func Register(bot *irc.IRC) { defer logger.Info(lib.TimeTrack(time.Now(), "Loading the MangaStream plugin")) timer.AddEvent("Checking Manga Sources", 900, func() { checkUpdates(bot, "mangafox", "") checkUpdates(bot, "mangastream", "") }) events.CmdListen(&events.CmdListener{ Commands: []string{"mangastream", "ms"}, Help: "Manages the MangaStream release watcher", Syntax: fmt.Sprintf("%sms <add/remove/list> <manga title> - Example: %sms add One Piece", bot.Config.Prefix, bot.Config.Prefix), Callback: func(input *events.Params) { if len(input.Args) == 0 { bot.Say(input.Context, events.Help("ms", "syntax")) return } var manga Manga loadWatched(&manga) switch strings.ToLower(input.Args[0]) { case "list": if len(manga.MangaStream) == 0 { bot.Say(input.Context, "I'm not watching for any MangaStream releases right now. :<") return } var titles string for _, entry := range manga.MangaStream { if entry.Manga == "" { titles += entry.Title + ", " } else { titles += entry.Manga + ", " } } bot.Say(input.Context, fmt.Sprintf("I'm currently watching for %s updates to %s.", "MangaStream", titles[:len(titles)-2])) case "add": if len(input.Args) < 2 { bot.Say(input.Context, events.Help("ms", "syntax")) return } bot.Say(input.Context, addManga(&manga, strings.Join(input.Args[1:], " "), input.Context, "MangaStream", bot)) case "remove": if len(input.Args) < 2 { bot.Say(input.Context, events.Help("ms", "syntax")) return } bot.Say(input.Context, removeManga(&manga, strings.Join(input.Args[1:], " "), "MangaStream")) case "check": checkUpdates(bot, "mangastream", input.Context) } }}) events.CmdListen(&events.CmdListener{ // not sure how to make this neat yet ^ v Commands: []string{"mangafox", "mf"}, Help: "Manages the MangaFox release watcher", Syntax: fmt.Sprintf("%smf <add/remove/list> <manga title> - Example: %smf add One Piece", bot.Config.Prefix, bot.Config.Prefix), Callback: func(input *events.Params) { if len(input.Args) == 0 { bot.Say(input.Context, events.Help("mf", "syntax")) return } var manga Manga loadWatched(&manga) switch strings.ToLower(input.Args[0]) { case "list": if len(manga.MangaFox) == 0 { bot.Say(input.Context, "I'm not watching for any MangaFox releases right now. :<") return } var titles string for _, entry := range manga.MangaFox { if entry.Manga == "" { titles += entry.Title + ", " } else { titles += entry.Manga + ", " } } bot.Say(input.Context, fmt.Sprintf("I'm currently watching for %s updates to %s.", "MangaFox", titles[:len(titles)-2])) case "add": if len(input.Args) < 2 { bot.Say(input.Context, events.Help("mf", "syntax")) return } bot.Say(input.Context, addManga(&manga, strings.Join(input.Args[1:], " "), input.Context, "MangaFox", bot)) case "remove": if len(input.Args) < 2 { bot.Say(input.Context, events.Help("mf", "syntax")) return } bot.Say(input.Context, removeManga(&manga, strings.Join(input.Args[1:], " "), "MangaFox")) case "check": checkUpdates(bot, "mangafox", input.Context) } }}) }
func Register(bot *irc.IRC) { defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Alias Frontend plugin")) events.CmdListen(&events.CmdListener{ Command: "var", Help: "Allows you to set variables.", Syntax: fmt.Sprintf("%svar <add/remove/list/info> <varname> [<data>] - Example: %svar add butts are nice", bot.Config.Prefix, bot.Config.Prefix), Callback: func(input *events.Params) { var argLen int = len(input.Args) if argLen == 0 { bot.Say(input.Context, events.Help("var", "syntax")) return } switch strings.ToLower(input.Args[0]) { case "add": if argLen < 3 { bot.Say(input.Context, events.Help("var", "syntax")) return } alias.Vars.SaveOne(input.Args[1], strings.Join(input.Args[2:], " ")) bot.Say(input.Context, "Added!") case "remove": if argLen < 2 { bot.Say(input.Context, events.Help("var", "syntax")) return } if ok := alias.Vars.RemoveOne(input.Args[1]); ok { bot.Say(input.Context, "Removed!") } else { bot.Say(input.Context, fmt.Sprintf("There is no %q variable.", input.Args[1])) } case "info": if argLen < 2 { bot.Say(input.Context, events.Help("var", "syntax")) return } varInfo := alias.Vars.GetOne(input.Args[1]) if varInfo == "" { bot.Say(input.Context, fmt.Sprintf("There is no %q variable.", input.Args[1])) } else { bot.Say(input.Context, fmt.Sprintf("Variable %q contains: %s", input.Args[1], varInfo)) } case "list": variables := alias.Vars.GetKeys() if len(variables) == 0 { bot.Say(input.Context, "There are no variables defined.") } else { bot.Say(input.Context, fmt.Sprintf("Variables: %s", strings.Join(variables, ", "))) } default: bot.Say(input.Context, events.Help("var", "syntax")) } }}) events.CmdListen(&events.CmdListener{ Command: "alias", Help: "Aliases things!", Syntax: fmt.Sprintf("%salias <add/remove/list/info> <command> <args> - Example: %salias add whip action whips {args*}'s buttocks!", bot.Config.Prefix, bot.Config.Prefix), Callback: func(input *events.Params) { var argLen int = len(input.Args) if argLen == 0 { bot.Say(input.Context, events.Help("alias", "syntax")) return } switch strings.ToLower(input.Args[0]) { case "list": aliases := alias.DB.GetKeys() if len(aliases) == 0 { bot.Say(input.Context, "There are no aliases defined.") } else { bot.Say(input.Context, fmt.Sprintf("Aliases: %s", strings.Join(aliases, ", "))) } case "info": if argLen < 2 { bot.Say(input.Context, events.Help("alias", "syntax")) return } aliasInfo := alias.DB.GetOne(input.Args[1]) if aliasInfo == "" { bot.Say(input.Context, fmt.Sprintf("There is no %q alias.", input.Args[1])) } else { bot.Say(input.Context, fmt.Sprintf("Alias %q contains: %s", input.Args[1], aliasInfo)) } case "add": if argLen < 3 { bot.Say(input.Context, events.Help("alias", "syntax")) return } alias.DB.SaveOne(input.Args[1], strings.Join(input.Args[2:], " ")) bot.Say(input.Context, "Added!") case "remove": if argLen < 2 { bot.Say(input.Context, events.Help("alias", "syntax")) return } if ok := alias.DB.RemoveOne(input.Args[1]); ok { bot.Say(input.Context, "Removed!") } else { bot.Say(input.Context, fmt.Sprintf("There is no %q alias.", input.Args[1])) } default: bot.Say(input.Context, events.Help("alias", "syntax")) } }}) }
func Register(bot *irc.IRC) { defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Core plugin")) // autojoin events.EvListen(&events.EvListener{ Handle: "autojoin", Event: "376", Callback: func(input *events.Params) { bot.Join(strings.Join(bot.Config.Autojoin, ",")) }}) // nick is taken events.EvListen(&events.EvListener{ Handle: "nickTaken", Event: "433", Callback: func(input *events.Params) { bot.Config.Nicknames = append(bot.Config.Nicknames[:0], bot.Config.Nicknames[1:]...) bot.Send("NICK " + bot.Config.Nicknames[0]) }}) events.CmdListen(&events.CmdListener{ Command: "help", Help: "Helps!", Syntax: bot.Config.Prefix + "help [<command>] - Example: " + bot.Config.Prefix + "help help", Callback: func(input *events.Params) { commands := events.CommandList() if len(input.Args) == 0 { bot.Say(input.Context, fmt.Sprintf("Commands: %s", strings.Join(commands, ", "))) return } input.Args[0] = strings.ToLower(input.Args[0]) for _, command := range commands { if input.Args[0] == command { bot.Say(input.Context, events.Help(command, "help")) bot.Say(input.Context, events.Help(command, "syntax")) return } } bot.Say(input.Context, fmt.Sprintf("\"%s\" isn't a command.", input.Args[0])) }}) // say events.CmdListen(&events.CmdListener{ Command: "say", Help: "Says stuff!", Syntax: bot.Config.Prefix + "say <thing you want to say>", Callback: func(input *events.Params) { bot.Say(input.Context, input.Data) }}) // action events.CmdListen(&events.CmdListener{ Command: "action", Help: "/me's stuff!", Syntax: bot.Config.Prefix + "action <thing you want the bot to emote>", Callback: func(input *events.Params) { bot.Action(input.Context, input.Data) }}) // join events.CmdListen(&events.CmdListener{ Command: "join", Help: "Joins channels!", Syntax: bot.Config.Prefix + "join #channel", Callback: func(input *events.Params) { if len(input.Args) < 1 || input.Args[0][0:1] != "#" { bot.Say(input.Context, "That ain't how you join a channel sucka") return } bot.Join(input.Args[0]) }}) // part events.CmdListen(&events.CmdListener{ Command: "part", Help: "Parts channels!", Syntax: bot.Config.Prefix + "part #channel", Callback: func(input *events.Params) { if len(input.Args) < 1 { if input.Context[0:1] == "#" { bot.Part(input.Context) } else { bot.Say(input.Context, "Either specify the channel to part or use the command in the channel.") } } else if input.Args[0][0:1] != "#" { bot.Say(input.Context, "That ain't how you part a channel sucka") return } else { bot.Part(input.Args[0]) } }}) // raw events.CmdListen(&events.CmdListener{ Command: "raw", Help: "Sends raw commands to the server", Syntax: bot.Config.Prefix + "raw <command>", Callback: func(input *events.Params) { bot.Send(input.Data) }}) // memstats events.CmdListen(&events.CmdListener{ Command: "memstats", Help: "Shows mem stats~", Syntax: bot.Config.Prefix + "memstats", Callback: func(input *events.Params) { m := &runtime.MemStats{} runtime.ReadMemStats(m) bot.Say(input.Context, fmt.Sprintf("Sys: %d KiB, Allocated and in use: %d KiB, Total Allocated (including freed): %d KiB, Lookups: %d, Mallocs: %d, Frees: %d", (m.Sys/1024.0), (m.Alloc/1024), (m.TotalAlloc/1024), m.Lookups, m.Mallocs, m.Frees)) }}) }