func handle_command(conn *irc.Conn, line *irc.Line, args []string) { command := args[0][len(RC.CmdPrefix):] args = args[1:] st := conn.StateTracker() authed := RC.Authed[line.Nick] if line.Nick == RC.Owner && authed { // Owner-only commands if command == "mock" { for _, n := range args { _, is_on := st.IsOn(RC.Channel, n) if is_on { RC.Mocking[n] = true conn.Privmsg(RC.Channel, "Now mocking "+n) } } } else if command == "unmock" { for _, n := range args { if RC.Mocking[n] { RC.Mocking[n] = false conn.Privmsg(RC.Channel, "No longer mocking "+n) } } } else if command == "shorten" { fmt.Println("unimplemented") } else if command == "snoop" { fmt.Println("unimplemented") } } else if (RC.Ops[line.Nick] || line.Nick == RC.Owner) && authed { // Ops-level commands if command == "poop" { conn.Privmsg(RC.Channel, "poop") } } else if command == "identify" && !line.Public() { fmt.Println("User " + line.Nick + " attempting to auth...") h := sha256.New() h.Write([]byte(args[0])) pwd_hash := hex.EncodeToString(h.Sum(nil)) if (line.Nick == RC.Owner || RC.Ops[line.Nick]) && RC.Password == pwd_hash { fmt.Println("Auth succeeded for " + line.Nick) RC.Authed[line.Nick] = true conn.Privmsg(line.Nick, "You're authenticated now.") } else { fmt.Println("WARNING: Auth failed for " + line.Nick + "!") conn.Privmsg(line.Nick, "You f****d up.") } } }
func (k *KarmaModule) collectorHandler(conn *irc.Conn, msg *Privmsg, match []string) { nickStr := strings.TrimSpace(match[1]) if msg.Nick == nickStr { msg.RespondToNick(conn, "You can't karama yourself, you'll go blind!") return } nick := conn.StateTracker().GetNick(nickStr) if nick == nil { log.WithFields(logrus.Fields{ "srcNick": msg.Nick, "dstNick": nickStr, "channel": msg.Channel, }).Debug("Karma: unknown nick") return } _, isOnChan := nick.IsOnStr(msg.Channel) if !isOnChan { log.WithFields(logrus.Fields{ "srcNick": msg.Nick, "dstNick": nickStr, "channel": msg.Channel, }).Debug("Karma: nick not in the current channel") return } log.WithFields(logrus.Fields{ "srcNick": msg.Nick, "dstNick": nickStr, "channel": msg.Channel, "direction": match[2], }).Info("Karma: Updating nick") var karma Karma db.Where(Karma{Nick: nick.Nick}).FirstOrInit(&karma) if match[2] == "++" { karma.Count++ } else { karma.Count-- } db.Save(&karma) }
func setTopic(conn *irc.Conn, channel string) { defer func() { if r := recover(); r != nil { log.Printf("most likely coding error: %v", r) } }() topic := conn.StateTracker().GetChannel(channel).Topic newtopic := insertNextEvent(topic) newtopic = advanceDates(newtopic) if topic == newtopic { return } log.Printf("%s OLD TOPIC: %s", channel, topic) log.Printf("%s NEW TOPIC: %s", channel, newtopic) conn.Topic(channel, newtopic) }