Update repository

This commit is contained in:
Eva Dengler 2022-12-21 13:04:36 +01:00
commit df2a986286
7 changed files with 35 additions and 24 deletions

29
bot.go
View file

@ -18,23 +18,22 @@ func sendmsg (conn net.Conn, channel string, msg string) {
conn.Write([]byte(mesg))
}
func scanline_privmsg (msg string) irc_msg {
var irc irc_msg
func scanline_privmsg (msg string, irc *irc_msg) {
LOG_ERR.Printf(msg)
msg = msg[1:]
t := strings.Split(msg, "!")
irc.author, irc.channel = t[0], t[1]
t = strings.Split(irc.channel, "PRIVMSG ")
irc.channel = t[1]
t = strings.Split(irc.channel, " :")
irc.channel, irc.msg = t[0], t[1]
t = strings.Split(irc.msg, "\r\n")
irc.msg = strings.TrimSpace(t[0])
if ! strings.HasPrefix(irc.channel, "#") {
irc.channel = irc.author
(*irc).author, (*irc).channel = t[0], t[1]
t = strings.Split((*irc).channel, "PRIVMSG ")
(*irc).channel = t[1]
t = strings.Split((*irc).channel, " :")
(*irc).channel, (*irc).msg = t[0], t[1]
t = strings.Split((*irc).msg, "\r\n")
(*irc).msg = strings.TrimSpace(t[0])
if ! strings.HasPrefix((*irc).channel, "#") {
(*irc).channel = (*irc).author
}
irc.retmsg = ""
return irc
(*irc).retmsg = ""
}
func bot_connect(bot *bot) {
@ -113,7 +112,9 @@ func bot_listen(bot *bot) <-chan string {
time.Sleep(10 * time.Second)
bot_register(bot)
} else if strings.Contains(line, "PRIVMSG") {
msg := scanline_privmsg(line)
var msg irc_msg
scanline_privmsg(line, &msg)
LOG_ERR.Printf(msg.author)
parsemsg(&msg, (*bot))
if msg.retmsg != "" {
sendmsg((*bot).conn, msg.channel, msg.retmsg)