public override void Execute(IrcMessage message, string args) { //look for next highest ID int maxid = 0; foreach (Nuke needle in State.NukeList.GetItems()) { if (args == needle.Text) { message.ReplyAuto("A nuke already exists on that term."); return; } if (needle.ID > maxid) maxid = needle.ID; } maxid++; //create new Nuke Nuke Nuke = new Nuke(); Nuke.Created = DateTime.UtcNow; Nuke.SetBy = message.From; Nuke.Text = args; Nuke.ID = maxid; //add to collection State.NukeList.Add(Nuke); //reply string text = ControlCharacter.Enabled ? Nuke.Text : ControlCharacter.Strip(Nuke.Text); message.ReplyAuto(message.From + " added Nuke " + ControlCharacter.Bold() + "#" + Nuke.ID.ToString() + ControlCharacter.Bold() + ": " + text); }
public override void Execute(IrcMessage message, string args) { IEnumerable<string> results = Program.GrepLog(args); IEnumerator<string> it = results.GetEnumerator(); int limit = Limit; bool first = true; while (it.MoveNext()) { //ignore the logged message of this query if (first && it.Current.EndsWith(GetKeyword() + " " + args)) { first = false; continue; } first = false; //return result message.ReplyAuto(it.Current); if (--limit == 0) break; } if (limit == Limit) { message.ReplyAuto("No matches"); } }
public override void Execute(IrcMessage message, string args) { if (string.IsNullOrEmpty(args)) { ShowWelcomeMessage(message); } else { string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { ShowWelcomeMessage(message); } else if (words.Length == 1) { if (words[0].ToLower() == "disable") { message.ReplyAuto("New subscribers will no longer be welcomed"); DisableWelcomeMessages(); } else { ShowHelpText(message); } } else { SetNewSubText(args); ShowWelcomeMessage(message); } } }
public override void Execute(IrcMessage message, string args) { if (Limiter.AttemptOperation(message.Level)) { string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int min = 1; int max = 100; if (arg.Length == 1) { //get max int.TryParse(arg[0], out max); } else if (arg.Length >= 2) { //get min and max int.TryParse(arg[0], out min); int.TryParse(arg[1], out max); } if (min > max) { //swap if max > min int temp = min; min = max; max = temp; } //generate number int diff = max - min; int delta = diff != 0 ? new System.Random().Next(diff) : 0; int result = min + delta; //output result message.ReplyAuto("Random number between " + min.ToString() + " and " + max.ToString() + ": " + ControlCharacter.Underline() + result.ToString()); } }
public override void Execute(IrcMessage message, string args) { if (args.Length != 0) throw new Exception("Failed to parse command"); int jtvcount = 0; int othercount = 0; foreach (Ban ban in State.BanList.GetItems()) { if (ban.Enforcer == BanEnforcement.ByJtv) jtvcount++; else othercount++; } #if JTVBOT message.ReplyAuto("Currently " + jtvcount.ToString() + " bans are affecting the JTV chat"); #elif QNETBOT message.ReplyAuto("Currently " + State.BanList.GetCount() + " bans are affecting the channel, of which " + Irc.CountBans().ToString() + " bans are enforced on the channel"); #endif }
public override void Execute(IrcMessage message, string args) { string[] elem = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (elem.Length != 1 && elem.Length != 3) { throw new Exception("Expected syntaxis: " + GetKeyword() + " <command> [<subscriber> <other>]"); } RateLimiter limiter = null; if (!CommandHandler.GetCommands().ContainsKey(elem[0])) { string special = elem[0].ToLower(); if (special == "chat") { limiter = Alice.limiter; elem[0] = "flavor-chat"; } else if (special == "joke") { limiter = Alice.joke_limiter; elem[0] = "auto-joking"; } else if (special == "user") { limiter = UserLimiter; elem[0] = "command interval per user"; } else throw new Exception("Command not found"); } else { limiter = CommandHandler.GetCommands()[elem[0]].Limiter; } if (elem.Length == 3) { RateLimiterConfiguration config = new RateLimiterConfiguration(); config.sub = double.Parse(elem[1]); config.nor = double.Parse(elem[2]); limiter.Configuration = config; message.ReplyAuto("Limit for " + elem[0] + " has been set to once every " + config.sub.ToString() + "s for subscribers and " + config.nor.ToString() + "s for other users"); } else { RateLimiterConfiguration config = limiter.Configuration; message.ReplyAuto("Limit for " + elem[0] + " is set to once every " + config.sub.ToString() + "s for subscribers and " + config.nor.ToString() + "s for other users"); } }
public override void Execute(IrcMessage message, string args) { if(args.Contains(" ") || args.Length == 0) { message.ReplyAuto("Usage: '!purge <name>', where <name> is replaced by the target user"); } else { if (CommandHandler.GetPrivilegeLevel(args) >= PrivilegeLevel.Operator) { throw new Exception("Unable to purge moderator/operator"); } else { JTV.Purge(args); message.ReplyAuto("Chat from '" + args + "' was purged"); } } }
public override void Execute(IrcMessage message, string args) { if (args.ToLower() == "on") { JTV.Slowmode(true); } else if (args.ToLower() == "off") { JTV.Slowmode(false); } else { message.ReplyAuto("Did you mean: '!slowmode on' or '!slowmode off'"); } }
public override void Execute(IrcMessage message, string args) { string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string prefix = "The current spam level is: "; if (arg.Length == 2 && arg[0].ToLower() == "set") { //set spam level int newlevel; if (!int.TryParse(arg[1], out newlevel) || newlevel < 0 || newlevel > 2) { message.ReplyAuto("The spam level can only be set to 0, 1 or 2"); return; } else { prefix = "The new spam level is: "; State.AntiSpamLevel.Value = newlevel; } } //print spam level string level = "<invalid>"; switch (State.AntiSpamLevel.Value) { case 0: level = "level 0 - anti-spam is disabled"; break; case 1: level = "level 1 - links are purged"; break; case 2: level = "level 2 - links are purged, and offender is tempbanned"; break; } message.ReplyAuto(prefix + level); }
/// <summary> /// Announces a new subscription, called when string matches in service /// </summary> /// <param name="msg"></param> public static void AnnounceNewSubscription(IrcMessage msg) { if (State.NewSubText.Value.Length < 1) { return; } if (msg.From.ToLower() == State.NewSubNotifyUser.Value.ToLower()) { string username; string announcement = State.NewSubText.Value; string[] words = msg.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words[1] == "just" && words[2] == "subscribed!") { username = words[0]; announcement = announcement.Replace("%s", username); msg.ReplyAuto(announcement); } } }
public override void Execute(IrcMessage message, string args) { //look for next highest ID int maxid = 0; foreach (Quote needle in State.QuoteList.GetItems()) { if (needle.ID > maxid) maxid = needle.ID; } maxid++; //create new quote Quote quote = new Quote(); quote.Created = DateTime.UtcNow; quote.SetBy = message.From; quote.Text = args; quote.ID = maxid; //add to collection State.QuoteList.Add(quote); //reply string text = ControlCharacter.Enabled ? quote.Text : ControlCharacter.Strip(quote.Text); message.ReplyAuto(message.From + " added quote " + ControlCharacter.Bold() + "#" + quote.ID.ToString() + ControlCharacter.Bold() + ": " + text); }
public override void Execute(IrcMessage message, string args) { if(Limiter.AttemptOperation(message.Level)) { message.ReplyAuto(text); } }
//show value for key void ShowKey(IrcMessage msg, string key) { switch (key.ToLower()) { case KeyInterval: msg.ReplyAuto("Advertisements will repeat every " + State.AdInterval.Value + " minutes"); break; case KeyEnabled: msg.ReplyAuto("Advertising is " + (State.AdEnabled.Value ? "enabled" : "disabled")); break; case KeyText: if (State.AdText.Value == String.Empty) { msg.ReplyAuto("No ad text has been set"); } else msg.ReplyAuto("Current Ad: \"" + State.AdText.Value + "\""); break; default: throw new Exception("Unknown key specified"); } }
//set value for key void SetKey(IrcMessage msg, string key, string value) { switch (key.ToLower()) { case KeyInterval: { int minutes; if (int.TryParse(value, out minutes) && minutes >= MinInterval) { State.AdInterval.Value = minutes; msg.ReplyAuto("Advertising repeat set to " + minutes + " minutes"); } else throw new Exception("Interval must be integral value (minutes), >= " + MinInterval); } break; case KeyEnabled: { switch (value.ToLower()) { case "1": case "true": case "yes": State.AdEnabled.Value = true; msg.ReplyAuto("Ads have been enabled"); break; case "0": case "false": case "no": State.AdEnabled.Value = false; msg.ReplyAuto("Ads will no longer be displayed"); break; default: throw new Exception("Enabled flag must be 'true' or 'false'"); } } break; case KeyText: { State.AdText.Value = value; msg.ReplyAuto("Advertisement has been set."); } break; default: throw new Exception("Unknown key specified"); } }
public override void Execute(IrcMessage message, string args) { // We don't care about case in this command, so lower everything args = args.ToLower(); string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string response = "Usage: !" + AdvertCommand.Keyword + " " + HelpText; if (words.Length > 0) { // Determine which command was called and call the appropriate method switch (words[0]) { case "help": if (words.Length > 1) { switch (words[1]) { case "add": response = AddHelp(); break; case "remove": case "delete": case "del": case "rem": response = DeleteHelp(); break; case "clear": case "deleteall": case "purge": response = ClearHelp(); break; case "interval": case "timer": response = IntervalHelp(); break; case "list": response = ListHelp(); break; case "disable": case "enable": response = EnableHelp(); break; default: // The default help text is returned in this case break; } } break; case "add": // Add a trigger, as long as they specified one if (words.Length > 1) { string success = ""; for (int i = 1; i < words.Length; i++) { success += Add(words[i]); } if (success.Length > 0) { response = "Advertisements were successfully updated"; } else { response = "Failed to update the advertisements."; } } else { response = AddHelp(); } break; case "remove": case "delete": case "del": case "rem": // Remove or delete a trigger if (words.Length > 1) { response = Delete(words[1]); } else { response = DeleteHelp(); } break; case "clear": case "deleteall": case "purge": // Remove all triggers response = ClearList(); break; case "interval": case "timer": // Set or review the cooldown timer if (words.Length > 1) { response = SetInterval(words[1]); } else { response = IntervalHelp(); } break; case "enabled": case "on": case "start": case "enable": response = EnableAds(); break; case "disable": case "disabled": case "off": case "stop": response = DisableAds(); break; case "list": case "show": response = ListAds(); break; case "call": PlayAd(); response = ""; break; default: break; } } if (response != "") { message.ReplyAuto(response); } }
public void Report(IrcMessage message) { if (viewers == 0 && embeds == 0 && total == 0) { DateTime lastStream = State.LastStreamDateTime.Value; string peak = State.LastPeakViews.ToString(); if (peak == "0") { peak = "an unknown number of"; } message.ReplyAuto("Channel is not live. Last stream was " + lastStream.ToString("f") + " UTC with " + State.LastPeakViews.Value + " peak viewers."); } else { string chatmsg = ""; string peak = ""; if (stream.EndsWith(DefaultChannel)) { lock (State.GlobalSync) { //number of chatters int chat = 0; foreach (User user in State.UserList.GetItems()) { if (user.Left == DateTime.MaxValue) chat++; } chatmsg = " and " + chat.ToString() + " chatters"; //peak viewer count peak = Program.PeakViewers + " peak"; } } // Remove the stream_count and embed_count variables, as the JTV API doesn't appear to report them properly message.ReplyAuto( "Currently " + ControlCharacter.Underline() + viewers.ToString() + ControlCharacter.Underline() + " viewers (" + peak + ")" + chatmsg + " are tuned in to " + ControlCharacter.Underline() + stream + ControlCharacter.Underline() + ", which has a total of " + ControlCharacter.Underline() + total.ToString() + ControlCharacter.Underline() + " views" ); } }
public override void Execute(IrcMessage message, string args) { //parse arguments string[] arg = args.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arg.Length != 4 && arg.Length != 6) throw new Exception("Bad argument count"); if (arg[0] != "from" || arg[2] != "to" || (arg.Length == 6 ? arg[4] != "limit" : false)) throw new Exception("Bad argument value"); BanEnforcement from = ParseEnforcement(arg[1]); BanEnforcement to = ParseEnforcement(arg[3]); if (to == from) throw new Exception("Cannot offload when to and from are the same"); int limit = 100; if (arg.Length == 6 && !int.TryParse(arg[5], out limit)) throw new Exception("Failed to parse limit"); if (limit <= 0 || limit > 100) throw new Exception("Limit out of valid range (1-100)"); //max allowed int max = 100; if (to == BanEnforcement.ByQ) max = BanSystem.QMaxBans - BanSystem.OffloadMargin - State.BanList.CountIf(new Predicate<Ban>(new BanTypeMatches(BanEnforcement.ByQ).Test)); if (to == BanEnforcement.ByChannel) max = BanSystem.CMaxBans - BanSystem.OffloadMargin - State.BanList.CountIf(new Predicate<Ban>(new BanTypeMatches(BanEnforcement.ByChannel).Test)); //find candidates int count = 0; PendingOffload offload = new PendingOffload(message); foreach (Ban ban in State.BanList.GetItems()) { if (ban.Enforcer == from && (to == BanEnforcement.ByChannel ? ban.Expires == DateTime.MaxValue : true)) { switch(to) { case BanEnforcement.ByQ: QCommand cmd; if(ban.Expires == DateTime.MaxValue) { cmd = new PermBanCommand(ban.Mask.Mask, ban.Reason); } else { cmd = new TempBanCommand(ban.Mask.Mask, BanSystem.ParseDuration((DateTime.UtcNow - ban.Expires).Duration()), ban.Reason); } switch (from) { case BanEnforcement.ByChannel: new PendingSetEnforcer(cmd, ban.Mask.Mask, BanEnforcement.ByQ); new PendingUnban(cmd, ban.Mask.Mask); break; case BanEnforcement.ByMe: new PendingSetEnforcer(cmd, ban.Mask.Mask, BanEnforcement.ByQ); if (!BanSystem.IsBanEnforced(ban)) new PendingUnban(cmd, ban.Mask.Mask); break; } offload.Add(cmd); break; case BanEnforcement.ByChannel: switch (from) { case BanEnforcement.ByQ: QCommand qcmd = new BanDelCommand(ban.Mask.Mask); new PendingBan(qcmd, ban.Mask.Mask); new PendingSetEnforcer(qcmd, ban.Mask.Mask, BanEnforcement.ByChannel); offload.Add(qcmd); break; case BanEnforcement.ByMe: if(!BanSystem.IsBanEnforced(ban)) Irc.Ban(ban.Mask.Mask); ban.Enforcer = BanEnforcement.ByChannel; Program.Log("Offload bot->channel: " + ban.Mask.Mask); break; } break; case BanEnforcement.ByMe: switch (from) { case BanEnforcement.ByQ: QCommand qcmd = new BanDelCommand(ban.Mask.Mask); if(Irc.IsBanEnforced(ban.Mask.Mask)) new PendingBan(qcmd, ban.Mask.Mask); new PendingSetEnforcer(qcmd, ban.Mask.Mask, BanEnforcement.ByMe); offload.Add(qcmd); break; case BanEnforcement.ByChannel: ban.Enforcer = BanEnforcement.ByMe; Program.Log("Offload channel->bot: " + ban.Mask.Mask); break; } break; } count++; if (count == limit) break; } } if (count == 0) throw new Exception("No bans match the specified type"); BanSystem.RefreshFromIrc(); message.ReplyImmediately = true; message.ReplyAuto(count.ToString() + " ban offloads are pending..."); message.ReplyImmediately = false; if(!(to == BanEnforcement.ByQ || from == BanEnforcement.ByQ)) { message.ReplyAuto(count.ToString() + " ban offloads succeeded"); } }
//show value for key void ShowKey(IrcMessage msg, string key) { switch (key.ToLower()) { case KeyInterval: msg.ReplyAuto("The interval between repeats is set to " + State.TwitterInterval.Value + " minutes"); break; case KeyEnabled: msg.ReplyAuto("Twitter repeat is " + (State.TwitterEnabled.Value ? "enabled" : "disabled")); break; case KeyAccount: msg.ReplyAuto("Twitter source account is " + State.TwitterAccount.Value); break; default: throw new Exception("Unknown key specified"); } }
public override void Execute(IrcMessage message, string args) { if (args.Length == 0) { int mins = State.QuoteInterval.Value; if (mins > 0) message.ReplyAuto("The current interval between quotes is set to " + mins.ToString() + " minutes"); else message.ReplyAuto("The quote interval is currently disabled"); } else { int mins = 0; if (int.TryParse(args, out mins) && mins >= 0) { State.QuoteInterval.Value = mins; if (mins > 0) message.ReplyAuto("The current interval between quotes has been set to " + mins.ToString() + " minutes"); else message.ReplyAuto("The quote interval has been disabled"); } else message.ReplyAuto("Invalid argument specified: Expected a number >= 0"); } }
public override void Execute(IrcMessage message, string args) { if (Parent.Limiter.AttemptOperation(message.Level)) { //look up by ID int id = -1; Quote quote = null; if (int.TryParse(args, out id)) { foreach (Quote needle in State.QuoteList.GetItems()) { if (needle.ID == id) { quote = needle; break; } } } if (quote == null) { //not found message.ReplyAuto("no quote #" + args + " was found"); } else { //print quote and info string text = ControlCharacter.Enabled ? quote.Text : ControlCharacter.Strip(quote.Text); message.ReplyAuto(quote.SetBy + " added quote " + ControlCharacter.Bold() + "#" + quote.ID.ToString() + ControlCharacter.Bold() + " on " + quote.Created.ToString() + ": " + text); } } }
public override void Execute(IrcMessage message, string args) { if (args.Length != 0) throw new Exception("No arguments expected"); BanSystem.RefreshFromIrc(); message.ReplyAuto("Refreshing ban information"); }
public override void Execute(IrcMessage message, string args) { //look up by ID int id = -1; Quote quote = null; if (int.TryParse(args, out id)) { foreach (Quote needle in State.QuoteList.GetItems()) { if (needle.ID == id) { quote = needle; break; } } } if (quote == null) { //not found message.ReplyAuto("no quote #" + args + " was found"); } else { //remove quote State.QuoteList.Remove(quote); message.ReplyAuto("removed quote #" + id.ToString()); } }
public void Write(IrcMessage source, int showbracket) { if (Error != null) { source.ReplyAuto("Rank: " + Error); } else { if (Details.Count != 0) { List<string> results = new List<string>(); foreach (Cache.Details details in Details) { string result = "Rank: " + details.Name + " on " + Region.ToUpper() + " - "; int bracket = 1; bool hasbracket = false; foreach (Team team in details.Teams) { if (team.Bracket >= bracket && (showbracket == 0 || team.Bracket == showbracket)) { result += team.Bracket.ToString() + "v" + team.Bracket.ToString() + " " + team.League.ToUpper().Substring(0, 1) + team.League.Substring(1) + " #" + team.Rank; result += " (" + team.Points.ToString() + " points, " + team.Wins.ToString() + " wins" + (team.Losses <= 0 ? "" : ", " + team.Losses.ToString() + " losses, " + (team.Wins * 100 / (team.Wins + team.Losses)).ToString() + "%") + ") "; double hours = (team.Refreshed - DateTime.UtcNow).Duration().TotalHours; string age = hours * 60.0 < 100.0 ? ((int)(hours * 60.0)).ToString() + " mins" : ((int)(hours + 0.5)).ToString() + " hours"; result += "as of " + age + " ago - "; bracket = team.Bracket + 1; hasbracket = true; } } if (hasbracket) { result += "More info at " + ControlCharacter.Underline() + ControlCharacter.Color(IrcColor.Blue) + details.Link + ControlCharacter.Restore(); results.Add(result); } } if (results.Count > 4) { source.ReplyAuto("Rank: Too many hits (" + Items.Count.ToString() + ") to display, see " + ControlCharacter.Underline() + ControlCharacter.Color(IrcColor.Blue) + "http://sc2ranks.com/search/contains/" + Region + "/" + SearchName + ControlCharacter.Restore() + " for all hits"); } else { foreach (string result in results) { source.ReplyAuto(result); } } } else if (Items.Count == 0) { source.ReplyAuto("Rank: No matching names found :("); } else if (Items.Count >= 1) { string result = "Rank: Are you looking for one of these names? "; foreach (Item item in Items) { result += item.Name + ", "; } result = result.Substring(0, result.Length - 2); source.ReplyAuto(result); } else { source.ReplyAuto("Rank lookup failed: Internal logic error"); } } }
/// <summary> /// Handles an incoming message, and invokes any matching commands /// </summary> /// <param name="message">The message to check for commands</param> public static void HandleMessage(IrcMessage message) { //ignore messages from channel if (!State.ParseChannel.Value && message.IsChannelMessage) return; bool had_prefix = false; if (!HandleCommand(message, out had_prefix)) { try { // first check for sub notify if (message.From.ToLower() == State.NewSubNotifyUser.Value.ToLower()) { if (message.Text.ToString().EndsWith("just subscribed!")) { NewSubCommand.AnnounceNewSubscription(message); } } //ignore commands from reserved names if(message.From == "jtv" || message.From == "jtvnotifier" || message.From.StartsWith("jtv!")) return; //not a command, test for bad words bool isspam = ContainsBadWord(message.Text); bool purgetrigger = ContainsFilteredText(message.Text); if (isspam) { Program.Log("This input matches spamfilter"); } if (State.AntiSpamLevel.Value > 0 && GetPrivilegeLevel(message.From) < PrivilegeLevel.Voiced && ( isspam || purgetrigger )) { if (State.AntiSpamLevel.Value == 1) { JTV.Purge(message.From, 30); // Only report if spam link sent if (isspam) { message.ReplyChannel("Please don't use URLs in chat, " + message.From); } Program.Log("Message from " + message.From + " was filtered"); } } // Not a bad word, let's check for nuke text if (ContainsNukePhrase(message.Text) && GetPrivilegeLevel(message.From) < PrivilegeLevel.Voiced) { // Determine the nuke time, in minutes int time = State.NukeTime.Value; if (time == 0) { time = 1; } else { time = time * 60; } // nuke this person JTV.Purge(message.From, time); Program.Log("Message from " + message.From + " was nuked"); } //process for AI chatterbot string name = State.JtvSettings.Value.Nickname; //remove characters string input = message.Text.Replace(",", "").Replace(".", "").Replace("!", "").Replace("?", "").Trim(); int needle = input.IndexOf(name, StringComparison.OrdinalIgnoreCase); if (needle >= 0 && !had_prefix) { try { //rewrite around name string first = input.Substring(0, needle).Trim(); string second = input.Substring(needle + name.Length).Trim(); bool insert_you = false; if (first.ToLower().EndsWith(" is")) { first = first.Substring(0, first.Length - 2) + "are"; insert_you = true; } else if (second.ToLower().StartsWith("is ")) { second = "are" + second.Substring(2); insert_you = true; } string rewritten = insert_you ? first + " you " + second : first + " " + second; //trigger alice Program.Log("ALICE input: " + rewritten); string result = Alice.Process(message.From, rewritten, message.Level); if (result.Length > 0 && result.Length < 100 && !result.StartsWith("<br",true,System.Globalization.CultureInfo.CurrentCulture)) { message.ReplyAuto(result); } else { Program.Log("Suppressed ALICE output: " + result); } } catch (Exception ex) { //parse failed Program.Log("Failed to prepare input for chatterbox: " + ex.Message); } } } catch (Exception ex) { //ignore exception Program.Log("Exception while handling input: " + ex.Message); } } }
public override void Execute(IrcMessage message, string args) { if (args.Length == 0) { int mins = State.NukeTime.Value; if (mins > 0) message.ReplyAuto("Nuke penalty is set to " + mins.ToString() + " minutes"); else message.ReplyAuto("Nuke penalty is less than 1 minute (purge only)"); } else { int mins = 0; if (int.TryParse(args, out mins) && mins >= 0) { State.NukeTime.Value = mins; if (mins > 0) message.ReplyAuto("Users are nuked for " + mins.ToString() + " minutes"); else message.ReplyAuto("Nuke penalty is less than 1 minute (purge only)"); } else message.ReplyAuto("Invalid argument specified: Expected a number >= 0"); } }
public override void Execute(IrcMessage message, string args) { //search terms string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if(words.Length == 0) throw new Exception("No search terms specified"); //look for bans List<Ban> found = new List<Ban>(); foreach (Ban ban in State.BanList.GetItems()) { bool matches = true; foreach (string word in words) { if (!(ban.Affected.Contains(word) || ban.Mask.Mask.Contains(word) || ban.Reason.Contains(word))) { //skip bans of bad type if (Program.IsJTV ^ ban.Enforcer == BanEnforcement.ByJtv) break; matches = false; break; } } if (matches) found.Add(ban); } //output result if (found.Count == 0) message.ReplyAuto("No ban matching your request was found"); else if (found.Count > 3) message.ReplyAuto("Too many bans match your request, please be more specific"); else { foreach (Ban ban in found) { message.ReplyAuto("Mask: " + ban.Mask.Mask + " which affects '" + ban.Affected + "' expires " + (ban.Expires == DateTime.MaxValue ? "never" : "at " + ban.Expires.ToString()) + ", reason: " + ban.Reason); } } }
//set value for key void SetKey(IrcMessage msg, string key, string value) { switch (key.ToLower()) { case KeyInterval: { int minutes; if (int.TryParse(value, out minutes) && minutes >= MinInterval) { State.TwitterInterval.Value = minutes; msg.ReplyAuto("The interval between repeats is set to " + minutes + " minutes"); } else throw new Exception("Interval must be integral value (minutes), >= " + MinInterval); } break; case KeyEnabled: { switch (value.ToLower()) { case "1": case "true": case "yes": State.TwitterEnabled.Value = true; msg.ReplyAuto("Twitter repeat has been enabled"); break; case "0": case "false": case "no": State.TwitterEnabled.Value = false; msg.ReplyAuto("Twitter repeat has been disabled"); break; default: throw new Exception("Enabled flag must be 'true' or 'false'"); } } break; case KeyAccount: { //strip @ from twitter account if (value.StartsWith("@")) value = value.Substring(1); if (string.IsNullOrEmpty(value)) throw new Exception("Account must be an twitter account-name"); State.TwitterAccount.Value = value; } break; default: throw new Exception("Unknown key specified"); } }
public override void Execute(IrcMessage message, string args) { if (Limiter.AttemptOperation(message.Level)) { message.ReplyAuto(TimeZones.Lookup(args, CommandHandler.GetPrivilegeLevel(message.From) >= PrivilegeLevel.Operator)); } }
public override void Execute(IrcMessage message, string args) { if (Parent.Limiter.AttemptOperation(message.Level)) { //look up by word string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length != 0) { string reply = ""; int count = 0; Quote quote = null; foreach (Quote needle in State.QuoteList.GetItems()) { int found = 0; foreach (string word in words) { if (!needle.Text.Contains(word)) break; found++; } if (found == words.Length) { quote = needle; //print quote string text = ControlCharacter.Enabled ? quote.Text : ControlCharacter.Strip(quote.Text); reply += "Quote " + ControlCharacter.Bold() + "#" + quote.ID.ToString() + ControlCharacter.Bold() + ": " + text + "\n"; count++; } } if (quote == null) { //not found message.ReplyAuto("no quote found containing the word(s): " + args); } else if (count > 3) { //too many matches message.ReplyAuto("more than 3 quotes matched your criteria, please be more exclusive in your criteria"); } else { //print found quotes message.ReplyAuto(reply); } } else { //no words message.ReplyPrivate("When using 'quote find', specify one or more words to search"); } } }
public override void Execute(IrcMessage message, string args) { string[] arg = args.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int limit = 100; if (arg.Length == 0) /*acceptable*/; else if (arg.Length == 2) { if (arg[0] != "limit" || !int.TryParse(arg[1], out limit)) throw new Exception("Failed to parse limit"); } else throw new Exception("Unexpected number of arguments"); int result = BanSystem.FreeBanSlot(limit); message.ReplyAuto("Lifting " + result.ToString() + " bans from the channel ban list"); }