func apReadConfig(nick *irc.Nick) (apnick string) { c, _ := config.ReadDefault(apConfigFile) hostmask := user(nick) apnick, _ = c.String(hostmask, "nick") return apnick }
func helpGetHelp(conn *irc.Conn, topic string, channel string) { c, _ := config.ReadDefault(helpFile) var text []string content, _ := c.String(topic, "content") content = strings.Replace(content, "{trigger}", trigger, -1) text = strings.Split(content, "\n") for _, out := range text { say(conn, channel, out) } }
func banList(conn *irc.Conn, nick *irc.Nick, args string, target string) { channel, args := parseAccess(conn, nick, target, args, "?") if channel == "" { say(conn, target, "Please specify a channel.") return } c, err := config.ReadDefault("bans.list") if err != nil { say(conn, channel, "No banlist file exists for %s. This is probably an error.", channel) return } banCount, _ := c.Int(channel, "count") if banCount == 0 { say(conn, channel, "There are no bans for %s.", channel) return } howMany, err := strconv.Atoi(args) if err != nil { howMany = 10 } if howMany == 0 { say(conn, channel, "Why would you ask me to show you nothing? Sheesh.") return } if howMany < 0 || howMany > banCount { howMany = banCount } say(conn, nick.Nick, "There are a total of %v bans in the log for %s.", banCount, channel) say(conn, nick.Nick, "Displaying the last %v bans.", howMany) if banCount == howMany { howMany = 0 } else { howMany = banCount - howMany } for counter := banCount; counter > howMany; counter -= 1 { id := strconv.Itoa(counter) logNick, _ := c.String(channel, id+".nick") logReason, _ := c.String(channel, id+".reason") logTime, _ := c.String(channel, id+".time") logStatus, _ := c.String(channel, id+".status") say(conn, nick.Nick, "%v: %s [%s] | %s | %s", counter, logTime, logStatus, logNick, logReason) } }
func handleTempBan(channel string, id string, expiry string) { channel = strings.Trim(channel, "#") c, _ := config.ReadDefault("bans.list") count := 0 if c.HasOption("timed", "count") { count, _ = c.Int("timed", "count") count++ } else { count = 1 } c.AddOption("#"+channel, id+".timer", strconv.Itoa(count)) c.AddOption("timed", "count", strconv.Itoa(count)) c.AddOption("timed", strconv.Itoa(count), channel+" "+id+" "+expiry) c.WriteFile("bans.list", 0644, "Ban List") }
func banLogDel(channel string, ban string) { c, err := config.ReadDefault("bans.list") if err != nil { return } c.AddOption(channel, ban+".status", "REMOVED") if c.HasOption(channel, ban+".timer") { timer, _ := c.String(channel, ban+".timer") tcount, _ := c.Int("timed", "count") tcount-- c.AddOption("timed", "count", strconv.Itoa(tcount)) c.RemoveOption("timed", timer) c.RemoveOption(channel, ban+".timer") } c.WriteFile("bans.list", 0644, "Ban List") }
func unban(conn *irc.Conn, nick *irc.Nick, args, target string) { channel, args := parseAccess(conn, nick, target, args, "o") if channel == "" || args == "" { return } ch := conn.GetChannel(channel) if ch == nil { say(conn, target, "%s: Unable to get channel information about %s", nick.Nick, channel) return } bans := strings.TrimSpace(args) split := strings.Fields(bans) for i, ban := range split { if strings.Index(ban, "@") != -1 { // it's already a host, do nothing continue } if b, ok := ch.Bans[ban]; ok { // we've seen this nick banned before split[i] = b } else if n := conn.GetNick(ban); n != nil { // the user is in one of our channels, here's our best guess split[i] = "*!*@" + n.Host } else if _, err := strconv.Atoi(ban); err == nil { // the ban is an integer, let's find it in the banlist c, err := config.ReadDefault("bans.list") if err != nil { return } host, err := c.String(channel, ban+".host") if err == nil { split[i] = host } banLogDel(channel, ban) } } bans = strings.Join(split, " ") modestring := "-" + strings.Repeat("b", len(bans)) + " " + bans conn.Mode(channel, modestring) }
func apSetNick(conn *irc.Conn, nick *irc.Nick, arg string, channel string) { arg = strings.TrimSpace(arg) if arg == "" { say(conn, channel, "Format is !apnick <nickname>") return } if apUserExists(arg) { c, _ := config.ReadDefault(apConfigFile) hostmask := user(nick) c.AddOption(hostmask, "nick", arg) c.WriteFile(apConfigFile, 0644, "") say(conn, channel, "Your anime-planet.com username has been recorded as '%s'", arg) return } say(conn, channel, "The user '%s' doesn't exist. Try again.", arg) }
func banLogAdd(host string, nick string, reason string, channel string, expiry int64) { c, _ := config.ReadDefault("bans.list") banCount, _ := c.Int(channel, "count") banCount += 1 id := strconv.Itoa(banCount) expires := strconv.Itoa64(expiry) localtime := time.LocalTime() banTime := localtime.Format("01/02/06 @ 15:04") c.AddOption(channel, "count", id) c.AddOption(channel, id+".nick", nick) c.AddOption(channel, id+".host", host) c.AddOption(channel, id+".reason", reason) c.AddOption(channel, id+".time", banTime) c.AddOption(channel, id+".status", "ACTIVE") if expiry > 0 { c.AddOption(channel, id+".expiry", expires) } c.WriteFile("bans.list", 0644, "Ban List") if expiry > 0 { handleTempBan(channel, id, expires) } }
func helpGetTopics() (helpTopics string) { c, _ := config.ReadDefault(helpFile) helpTopics, _ = c.String("DEFAULT", "topics") return helpTopics }