public static void evt_login(Bot bot, dAmnPacket packet) { if (packet.Arguments["e"] != "ok") { ConIO.Warning("dAmn", String.Format("Failed to login as {0} [{1}]", packet.Parameter, packet.Arguments["e"])); if (packet.Arguments["e"] == "authentication failed") { ConIO.Write("Attempting to renew authtoken..."); if (Program.RenewToken()) { Program.ForceReconnect = true; Program.wait_event.Set(); return; } } Program.Running = false; Program.wait_event.Set(); } else { ConIO.Write(String.Format("Logged in as {0} [{1}]", packet.Parameter, packet.Arguments["e"])); bot.Join("chat:DSGateWay"); foreach (String channel in bot.Config.Channels) { bot.Join(channel); } } }
public static void cmd_disconnects(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (Program.Disconnects == 0) bot.Say(ns, "<b>» I have not disconnected since startup.</b>"); else bot.Say(ns, String.Format("<b>» I have disconnected {0} time{1} since startup.</b>", Program.Disconnects, Program.Disconnects == 1 ? "" : "s")); }
public static void evt_recv_action(Bot bot, dAmnPacket packet) { // Don't display DataShare messages. if (!Program.NoDisplay.Contains(Tools.FormatNamespace(packet.Parameter.ToLower(), Types.NamespaceFormat.Channel))) { ConIO.Write(String.Format("* {0} {1}", packet.Arguments["from"], packet.Body), Tools.FormatChat(packet.Parameter)); lock (BDS._seen_database) { if (BDS._seen_database.ContainsKey(packet.Arguments["from"].ToLower())) { BDS._seen_database[packet.Arguments["from"].ToLower()].Channel = packet.Parameter; BDS._seen_database[packet.Arguments["from"].ToLower()].Type = (byte)Types.SeenType.Talking; BDS._seen_database[packet.Arguments["from"].ToLower()].Timestamp = Bot.EpochTimestamp; } else { BDS._seen_database.Add(packet.Arguments["from"].ToLower(), new SeenInfo() { Name = packet.Arguments["from"], Channel = packet.Parameter, Type = (byte)Types.SeenType.Talking, Timestamp = Bot.EpochTimestamp }); } } } }
public static void cmd_netinfo(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length >= 2 && args[1] == "reset") { if (Users.GetPrivs(from.ToLower()) >= (int)Privs.Operators) { Program.bytes_sent = 0; Program.bytes_received = 0; Program.packets_in = 0; Program.packets_out = 0; bot.Say(ns, "<b>» Network usage stats reset.</b>"); return; } else { bot.Say(ns, "<b>» You don't have permission to do that.</b>"); return; } } String output = "<bcode>"; bool verbose = (args.Length >= 2 && args[1] == "verbose"); output += String.Format("» Data sent : {0}\n", Tools.FormatBytes(Program.bytes_sent, verbose)); output += String.Format("» Data recv : {0}\n", Tools.FormatBytes(Program.bytes_received, verbose)); output += String.Format("» Packets : OUT: {0}\t\tIN: {1}\n", Program.packets_out, Program.packets_in); output += String.Format("» Queues : OUT: {0}\t\tIN: {1}\n", bot.QueuedOut, bot.QueuedIn); output += String.Format("» Disconnects: {0}\n", Program.Disconnects); output += "</bcode>"; bot.Say(ns, output); }
public static void cmd_act(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length < 2) { bot.Say(ns, String.Format("<b>» Usage:</b> {0}act <i>[#channel]</i> msg", bot.Config.Trigger)); } else { String chan, mesg; if (!args[1].StartsWith("#")) { chan = ns; mesg = msg.Substring(4); } else { chan = args[1]; mesg = msg.Substring(5 + args[1].Length); } lock (CommandChannels["send"]) { CommandChannels["send"].Add(ns); } bot.Act(chan, mesg); } }
public static void cmd_channels(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String output = String.Empty; List<String> chans = new List<String>(); try { foreach (var cd in Core.ChannelData.Values) if (cd.Name != "chat:DataShare" && !cd.Name.StartsWith("pchat") && !cd.Name.StartsWith("login")) chans.Add(Tools.FormatNamespace(cd.Name, Types.NamespaceFormat.Channel)); chans.Sort(); output += String.Format("<b>» I am currently residing in {0} channel{1}:</b><br/>", chans.Count, chans.Count == 1 ? "" : "s"); output += String.Format("<b> · [</b>{0}<b>]</b>", String.Join("<b>]</b>, <b>[</b>", chans)); bot.Act(ns, output); } catch (Exception Ex) { if (Program.Debug) bot.Say(ns, "Error: " + Ex.Message); } }
public static void cmd_part(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { var c = ns; if (args.Length != 2) { // Ignore this for now. //bot.Say(ns, String.Format("<b>» Usage:</b> {0}part #channel", bot.Config.Trigger)); } else { if (!args[1].StartsWith("#")) { bot.Say(ns, "<b>» Invalid channel!</b> Channels should start with a #"); return; } c = args[1]; } lock (CommandChannels["part"]) { CommandChannels["part"].Add(ns); } bot.Part(c); }
public static void cmd_cycle(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { var chan = ""; if (args.Length > 1 && args[1].StartsWith("#")) { chan = args[1]; } else { chan = ns; } String cpns = Tools.FormatNamespace(chan, Types.NamespaceFormat.Packet).ToLower(); if (!Core.ChannelData.ContainsKey(cpns)) { bot.Say(ns, "<b>» It doesn't look like I'm in that channel.</b>"); return; } lock (CommandChannels["part"]) { CommandChannels["part"].Add(ns); } lock (CommandChannels["join"]) { CommandChannels["join"].Add(ns); } bot.Part(cpns); bot.Join(cpns); }
public static void cmd_system(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String output = String.Empty; output += String.Format("<b>» System:</b> {0}. <b>Architecture:</b> {1}bit. <b>CLR Version:</b> {2}<br/>", Program.OS, Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Version.ToString()); bot.Say(ns, output); }
public static void cmd_about(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String output = String.Empty; output += String.Format("<b>» I am a <a href=\"http://fav.me/d5uviwb\">{0}</a> v{1} <b><sup>{2}</sup></b>, written by :devDivinityArcane:<br/>»</b> I am owned by :dev{3}:<br/>", Program.BotName, Program.Version, Program.ReleaseName, bot.Config.Owner); output += String.Format("<b>»</b> I've disconnected {0} time{1}, while I've been running for {2}<br/>", Program.Disconnects, Program.Disconnects == 1 ? "" : "s", Tools.FormatTime(bot.uptime)); bot.Act(ns, output); }
public static void cmd_reload(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { bot.Say(ns, "<b>» Reloading extensions...</b>"); ulong start = Bot.EpochTimestampMS; Events.ClearExternalEvents(); Bot.Extensions.Load(); bot.Say(ns, "<b>» Done!</b> Took " + Tools.FormatTime((ulong)(Bot.EpochTimestampMS - start) / 1000)); }
public static void evt_join(Bot bot, dAmnPacket packet) { if (BDS.syncing && packet.Parameter.StartsWith("pchat:") && packet.Parameter.ToLower().Contains(BDS.syncwith)) { BDS.syncwatch = Stopwatch.StartNew(); bot.NPSay(packet.Parameter, "BDS:SYNC:BEGIN"); return; } // Don't display DataShare messages. if (Program.NoDisplay.Contains(Tools.FormatNamespace(packet.Parameter.ToLower(), Types.NamespaceFormat.Channel))) return; if (packet.Arguments["e"] == "ok") { ConIO.Write(String.Format("** Joined [{0}]", packet.Arguments["e"]), Tools.FormatChat(packet.Parameter)); // Initialize channel data lock (ChannelData) { if (!ChannelData.ContainsKey(packet.Parameter.ToLower())) { ChannelData.Add(packet.Parameter.ToLower(), new Types.ChatData()); ChannelData[packet.Parameter.ToLower()].Name = packet.Parameter; } } lock (CommandChannels["join"]) { if (CommandChannels["join"].Count != 0) { String chan = CommandChannels["join"][0]; bot.Say(chan, String.Format("<b>» Joined {0} [ok]</b>", Tools.FormatChat(packet.Parameter))); CommandChannels["join"].RemoveAt(0); } } } else { ConIO.Write(String.Format("** Failed to join [{0}]", packet.Arguments["e"]), Tools.FormatChat(packet.Parameter)); lock (CommandChannels["join"]) { if (CommandChannels["join"].Count != 0) { String chan = CommandChannels["join"][0]; bot.Say(chan, String.Format("<b>» Failed to join {0} [{1}]</b>", Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); CommandChannels["join"].RemoveAt(0); } } } }
public static void cmd_ai(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String helpmsg = String.Format("<b>» Usage:</b><br/>{0}ai on/off<br/>{0}ai enable/disable #channel", " · " + bot.Config.Trigger); if (args.Length == 1) bot.Say(ns, helpmsg); else { String arg = args[1]; if (arg == "on" || arg == "off") { Config.Enabled = arg == "on"; Save(); bot.Say(ns, String.Format("<b>» AI has been {0}.</b>", Config.Enabled ? "enabled" : "disabled")); } else if ((arg == "enable" || arg == "disable") && args.Length == 3) { if (!args[2].StartsWith("#")) { bot.Say(ns, "<b>» Invalid channel name! Channel names start with #</b>"); return; } else if (blacklist.Contains(args[2].ToLower())) { bot.Say(ns, "<b>» AI is forbidden in channel:</b> " + args[2]); return; } String chan = Tools.FormatChat(args[2]).ToLower(); if (arg == "enable") { if (!Config.WhiteList.Contains(chan)) { Config.WhiteList.Add(chan); Save(); bot.Say(ns, String.Format("<b>» Channel {0} has been added to the whitelist.</b>", args[2])); } else bot.Say(ns, "<b>» That channel is already in the whitelist!</b>"); } else { if (Config.WhiteList.Contains(chan)) { Config.WhiteList.Remove(chan); Save(); bot.Say(ns, String.Format("<b>» Channel {0} has been removed from the whitelist.</b>", args[2])); } else bot.Say(ns, "<b>» That channel is not in the whitelist!</b>"); } } else bot.Say(ns, helpmsg); } }
public static void cmd_command(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String helpmsg = String.Format("<b>» Usage:</b>{0}command list{0}command disable/enable command", "<br/> · " + bot.Config.Trigger); if (args.Length < 2) { bot.Say(ns, helpmsg); } else { String arg = args[1], cmd; if (arg == "list") { if (_disabled_commands.Count == 0) bot.Say(ns, "<b>» There are currently no disabled commands.</b>"); else bot.Say(ns, String.Format("<b>» There's {0} disabled command{1}:</b><br/> · <b>[</b>{2}<b>]</b>", _disabled_commands.Count, _disabled_commands.Count == 1 ? "" : "s", String.Join("<b>]</b>, <b>[</b>", _disabled_commands))); } else if ((arg == "enable" || arg == "disable") && args.Length == 3) { cmd = args[2].ToLower(); if (!Events.ValidateCommandName(cmd)) { bot.Say(ns, "<b>» The specified command does not exist:</b> " + cmd); return; } bool en = arg == "enable"; if (!en && _disabled_commands.Contains(cmd)) { bot.Say(ns, "<b>» The specified command is already disabled:</b> " + cmd); return; } else if (en && !_disabled_commands.Contains(cmd)) { bot.Say(ns, "<b>» The specified command is not disabled:</b> " + cmd); return; } if (en) _disabled_commands.Remove(cmd); else { _disabled_commands.Add(cmd); _disabled_commands.Sort(); } bot.Say(ns, String.Format("<b>» The specified command has been {0}d:</b> {1}", args[1], cmd)); SaveDisabled(); } } }
public static void cmd_update(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String utd = Tools.UpToDate(Program.Version); if (utd == "OK") bot.Say(ns, "<b>» The bot is already up to date!</b>"); else if (utd == "ERR") bot.Say(ns, "<b>» Unable to check at this time. You can also <a href=\"http://j.mp/15ikMg1\">check manually.</a></b>"); else bot.Say(ns, "<b>» There's a new version available! <a href=\"http://j.mp/15ikMg1\">" + utd + "</a></b>"); }
public static void cmd_chat(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String pcns = Tools.FormatPCNS(from, bot.Config.Username); lock (CommandChannels["join"]) { CommandChannels["join"].Add(ns); } bot.Join(pcns); }
public static void evt_kill_error(Bot bot, dAmnPacket packet) { ConIO.Write(String.Format("*** Failed to kill {0} [{1}]", Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); if (CommandChannels["kill"].Count > 0) { String chan = CommandChannels["kill"][0]; CommandChannels["kill"].RemoveAt(0); bot.Say(chan, String.Format("<b>» Failed to kill {0}:</b> {1}", Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); } }
public static void cmd_debug(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length < 2) { bot.Say(ns, String.Format("<b>» Usage:</b> {0}debug on/off", bot.Config.Trigger)); } else { String cmd = args[1]; Program.Debug = cmd == "on"; bot.Say(ns, String.Format("<b>» Debug mode has been {0}.</b>", Program.Debug ? "enabled" : "disabled")); } }
public static void evt_disconnect(Bot bot, dAmnPacket packet) { ConIO.Write(String.Format("*** Disconnected [{0}]", packet.Arguments["e"])); // Add an override for a restart command later? if (bot.Quitting) { bot.Close(); Program.Running = false; Program.wait_event.Set(); } else bot.Reconnect(); }
public static void evt_set_error(Bot bot, dAmnPacket packet) { // Don't display DataShare messages. if (Program.NoDisplay.Contains(Tools.FormatNamespace(packet.Parameter.ToLower(), Types.NamespaceFormat.Channel))) return; if (CommandChannels["set"].Count > 0) { String chan = CommandChannels["set"][0]; CommandChannels["set"].RemoveAt(0); bot.Say(chan, String.Format("<b>» Failed to set {0} of {1}:</b> {2}", packet.Arguments["p"], Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); } ConIO.Write(String.Format("*** Failed to set {0} in {1} [{2}]", packet.Arguments["p"], Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); }
public static void cmd_sudo(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length < 3) { bot.Say(ns, String.Format("<b>» Usage:</b> {0}sudo [username] [command]", bot.Config.Trigger)); } else { String who = args[1], cmd = msg.Substring(6 + who.Length); dAmnPacket pkt = packet; pkt.Arguments["from"] = who; pkt.Body = bot.Config.Trigger + cmd; Events.CallCommand(args[2], pkt); } }
public static void cmd_whois(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length < 2) { bot.Say(ns, String.Format("<b>» Usage:</b> {0}whois username", bot.Config.Trigger)); } else { lock (CommandChannels["whois"]) { CommandChannels["whois"].Add(ns); bot.Send(dAmnPackets.Whois(args[1])); } } }
public static void cmd_kill(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { if (args.Length < 2) { bot.Say(ns, String.Format("<b>» Usage:</b> {0}kill username <i>reason</i>", bot.Config.Trigger)); } else { lock (CommandChannels["kill"]) { CommandChannels["kill"].Add(ns); } bot.Kill(args[1], "<b>" + from + "</b>" + (args.Length >= 3 ? ": " + msg.Substring(6 + args[1].Length) : "")); } }
public static void cmd_credits(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String output = String.Empty; output += "» lulzBot is a bot written by :devDivinityArcane: <sup><i>Formerly Kyogo</i></sup> and it couldn't have been done without the following people:"; output += "<br/><br/><b>Absolutely f*****g no one!</b> <sub><sub>No, not really.</sub></sub><br/><br/>"; output += ":devOrrinFox:, who thought of the name and inspired me to write the bot.<br/>"; output += ":devDeathShadow--666:, for letting me look at n00ds of his sister when I did well.<br/>"; output += ":devSubjectX52873M:, for teaching me quite a few fun things that bots could do, as well as proving that PHP sucks for bots. :cough: <sub><sub>Dante</sub></sub><br/>"; output += ":devdoofsmack: and :devtwexler:, who wrote dAmnBot, which inspired me to write bots for dAmn.<br/>"; output += ":devNoodleMan:, for writing NoodleBot and Gyn, which inspired me to do better, way back when.<br/>"; output += ":develectricnet:, for writing Futurism, which gave me quite a few ideas on what to do for user<->bot interaction.<br/>"; output += ":devphotofroggy:, for writing dAmnPHP and Contra, which gave me ideas on how to do certain things I was conflicted about.<br/>"; output += "And the whole #Botdom team, who put up with my bullshit for many, many years!<br/>"; output += "<br/>But, most of all, <b>you</b>, for continuing to use lulzBot and letting me know how I can improve it."; bot.Act(ns, output); }
public static void cmd_set(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String helpmsg = String.Format("<b>» Usage:</b> {0}set <i>[#channel]</i> [title|topic] [content]", bot.Config.Trigger); if (args.Length < 2) { bot.Say(ns, helpmsg); } else { String chan, prop, body; if (!args[1].StartsWith("#")) { chan = ns.ToLower(); ; prop = args[1]; body = msg.Substring(prop.Length + 4); } else if (args.Length >= 3) { chan = Tools.FormatChat(args[1]).ToLower(); prop = args[2]; body = msg.Substring(prop.Length + args[1].Length + 5); } else { bot.Say(ns, helpmsg); return; } if (prop != "title" && prop != "topic") { bot.Say(ns, "<b>» Invalid property!</b> Valid properties are title and topic."); return; } lock (CommandChannels["set"]) { CommandChannels["set"].Add(ns); bot.Send(dAmnPackets.Set(chan, prop, body)); } } }
public static void cmd_colors(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String helpmsg = String.Format("<b>» Usage:</b><br/>{0}colors on/off<br/>{0}colors username/message #colorcode", " · " + bot.Config.Trigger); if (args.Length == 1) bot.Say(ns, helpmsg); else { String arg = args[1]; if (arg == "on" || arg == "off") { Config.Enabled = arg == "on"; Save(); bot.Say(ns, String.Format("<b>» Colors have been {0}.</b>", Config.Enabled ? "enabled" : "disabled")); } else if (arg == "username" && args.Length == 3) { if (!args[2].StartsWith("#") || args[2].Length != 7) { bot.Say(ns, "<b>» Invalid color code! Use HTML color codes.</b>"); return; } Config.UsernameColor = args[2].Substring(1); Save(); bot.Say(ns, String.Format("<b>» Username color has been set to {0}.</b>", args[2])); } else if (arg == "message" && args.Length == 3) { if (!args[2].StartsWith("#") || args[2].Length != 7) { bot.Say(ns, "<b>» Invalid color code! Use HTML color codes.</b>"); return; } Config.MessageColor = args[2].Substring(1); Save(); bot.Say(ns, String.Format("<b>» Message color has been set to {0}.</b>", args[2])); } else bot.Say(ns, helpmsg); } }
public static void evt_connect(Bot bot, dAmnPacket packet) { try { if (bot == null) { Program.ForceReconnect = true; Program.wait_event.Set(); return; } if (Program.Debug) ConIO.Write("Connected to the server: " + bot.Endpoint()); bot.Send(dAmnPackets.dAmnClient(0.3, Program.BotName, bot.Config.Owner)); } catch { bot.Close(); } }
public static void evt_get_error(Bot bot, dAmnPacket packet) { if (packet.Parameter.StartsWith("login:"******"whois"]) { if (CommandChannels["whois"].Count > 0) { String chan = CommandChannels["whois"][0]; CommandChannels["whois"].RemoveAt(0); bot.Say(chan, String.Format("<b>» Failed to whois {0}:</b> {1}", packet.Parameter.Substring(6), packet.Arguments["e"])); } } } else { if (Program.NoDisplay.Contains(Tools.FormatNamespace(packet.Parameter.ToLower(), Types.NamespaceFormat.Channel))) return; ConIO.Write(String.Format("*** Failed to get {0} in {1} [{2}]", packet.Arguments["p"], Tools.FormatChat(packet.Parameter), packet.Arguments["e"])); } }
public static void evt_kicked(Bot bot, dAmnPacket packet) { // Don't display DataShare messages. if (!Program.NoDisplay.Contains(Tools.FormatNamespace(packet.Parameter.ToLower(), Types.NamespaceFormat.Channel))) { if (packet.Body.Length > 0) ConIO.Write(String.Format("*** Kicked by {0}: {1}", packet.Arguments["by"], packet.Body), Tools.FormatChat(packet.Parameter)); else ConIO.Write(String.Format("*** Kicked by {0}", packet.Arguments["by"]), Tools.FormatChat(packet.Parameter)); } // In the event that we cannot (or will not) rejoin, remove channel data. lock (ChannelData) { if (ChannelData.ContainsKey(packet.Parameter.ToLower())) ChannelData.Remove(packet.Parameter.ToLower()); } // Rejoin! if (bot.AutoReJoin) bot.Join(packet.Parameter); }
public static void cmd_demote(Bot bot, String ns, String[] args, String msg, String from, dAmnPacket packet) { String helpmsg = String.Format("<b>» Usage:</b> {0}demote <i>[#channel]</i> username <i>privclass</i>", bot.Config.Trigger); if (args.Length < 2) { bot.Say(ns, helpmsg); } else { String chan, who, pc; if (!args[1].StartsWith("#")) { chan = ns; who = args[1]; pc = (args.Length >= 3 ? args[2] : null); } else if (args.Length >= 3) { chan = args[1]; who = args[2]; pc = (args.Length >= 4 ? args[3] : null); } else { bot.Say(ns, helpmsg); return; } lock (CommandChannels["send"]) { CommandChannels["send"].Add(ns); } bot.Demote(chan, who, pc); } }