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) { string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arg.Length == 0) { throw new Exception("No name or hostmask was specified"); } string name = arg[0]; string hostmask = null; if(name.Contains("!") && name.Contains("@")) { hostmask = name; } else { if (CommandHandler.GetPrivilegeLevel(name) >= PrivilegeLevel.Operator) { throw new Exception("Unable to ban moderator/operator"); } HostMask mask = BanSystem.CreateBanMask(name); if (mask == null) { throw new Exception("Name '" + name + "' not found"); } hostmask = mask.Mask; } string duration = "10m"; int next = 1; if (arg.Length >= 2) { string maybe_duration = arg[1]; if (maybe_duration.StartsWith("perm")) { duration = null; next = 2; } else { Regex duration_regex = new Regex("^(?:[0-9]+[mhdwMy])+$"); int minutes; if (duration_regex.Match(maybe_duration).Success) { duration = maybe_duration; next = 2; } else if (int.TryParse(maybe_duration, out minutes) && minutes > 0) { duration = minutes.ToString() + "m"; next = 2; } } } string reason = ""; for (int i = next; i < arg.Length; ++i) reason += arg[i] + " "; if (reason == "") reason = duration == null ? "Banned permanently" : "Banned for " + duration; else reason += (duration == null ? " (permanently)" : (" (for " + duration + ")")); reason = reason.Trim() + " by " + message.From; BanSystem.PerformBan(hostmask, duration, reason, message.From); }
//execute command public override void Execute(IrcMessage message, string args) { if (string.IsNullOrEmpty(args)) { SendAd(); } else { string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { ShowKey(message, "text"); } else if (words.Length == 1) { ShowKey(message, words[0]); } else if (words.Length == 2) { SetKey(message, words[0], words[1]); } else if (words[0].ToLower() == "text") { string text = null; for (int i = 1; i < words.Length; i++) text = (text == null) ? words[i] : text + " " + words[i]; if (text == null) { throw new Exception("Cannot advertise nothing"); } SetKey(message, words[0], text); } else throw new Exception("Syntax is error, expects: !ad [<key> [<value>]]"); } }
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) { string hostmask = args.Trim(); if(hostmask.Contains(" ")) { throw new Exception("No name or hostmask was specified"); } if(!hostmask.Contains("!") || !hostmask.Contains("@")) { string name = hostmask; HostMask mask = BanSystem.FindBanByNick(name); #if QNETBOT if(mask == null) { throw new Exception("Name '" + name + "' was not found, check spelling or specify hostmask"); } #elif JTVBOT if (mask == null) mask = new HostMask(name); #endif hostmask = mask.Mask; } #if JTVBOT BanSystem.PerformUnban(hostmask, false); #elif QNETBOT BanSystem.PerformUnban(hostmask); #endif }
public override void Execute(IrcMessage message, string args) { int space = args.IndexOf(' '); if (space == -1) space = args.Length; if (space == 0 && string.IsNullOrEmpty(DefaultSubCommand)) throw new Exception("Expected a subcommand, please see 'help " + GetKeyword() + "'"); string subname = args.Substring(0, space); args = args.Substring(space).Trim(); for (int i = 0; i < 2; i++) { foreach (Command sub in subcommands) { if (sub.GetKeyword() == subname && sub.Privilege <= CommandHandler.GetPrivilegeLevel(message.From)) { sub.Execute(message, args); return; } } if (i == 0 && !string.IsNullOrEmpty(DefaultSubCommand)) { subname = DefaultSubCommand; } else break; } throw new Exception("Cannot find any subcommand '" + subname + "' for command '" + GetKeyword() + "'"); }
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 (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) { string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arg.Length != 2) throw new Exception("Expected two arguments, got " + arg.Length.ToString()); IPAddress ip = null; if (!IPAddress.TryParse(arg[1], out ip)) throw new Exception("Failed to parse '" + arg[1] + "' as an IP address"); Account acct = State.AccountList.Lookup(ip); switch (arg[0].ToLower()) { case "add": if (acct != null) throw new Exception("An account already exists for IP " + ip.ToString()); acct = Account.Generate(ip); string result = acct.GetToken().ToXML(); State.AccountList.Add(acct); message.ReplyPrivate(result); break; case "get": if (acct == null) throw new Exception("No account exists for IP " + ip.ToString()); string reply = acct.GetToken().ToXML(); message.ReplyPrivate(reply); break; case "del": if (acct == null) throw new Exception("No account exists for IP " + ip.ToString()); State.AccountList.Remove(acct); message.ReplyPrivate("The account for IP " + ip.ToString() + " was removed"); break; } }
public override void Execute(IrcMessage message, string args) { User user = State.UserList.Lookup(message.From); if (user == null) throw new Exception("User not known"); bool enabled; if (args.ToLower() == "on") enabled = true; else if (args.ToLower() == "off") enabled = false; else throw new Exception("Argument expected: on or off"); user.Meta.Elevation = enabled; State.MetaUserList.MarkChanged(user.Meta); message.ReplyPrivate("Developer commands are now " + (user.Meta.Elevation ? "enabled" : "disabled") + " for " + message.From); }
/// <summary> /// Handle /// </summary> /// <param name="message"></param> public static void HandleMessage(IrcMessage message) { try { if (message.IsPrivateMessage && message.From.StartsWith("jtv") && message.Text.StartsWith("SPECIALUSER") && message.Text.EndsWith("subscriber")) { MarkSubscriber(message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1]); } } catch (Exception) { //ignore } }
public override void Execute(IrcMessage message, string args) { if (Limiter.AttemptOperation(message.Level)) { bool silent = false; if (args == "<silent>") { args = DefaultChannel; silent = true; } string stream = args.Length == 0 ? DefaultChannel : args; string uri = "https://api.twitch.tv/kraken/streams/" + stream; if (Uri.IsWellFormedUriString(uri, UriKind.Absolute)) { if (cache.ContainsKey(stream)) { Cache item = cache[stream]; if (item == null) { //already pending return; } else if ((DateTime.UtcNow - item.retrieved).TotalMinutes <= 1.0) { //in cache if (!silent) { item.Report(message); } return; } } //add new request if (cache.ContainsKey(stream)) cache.Remove(stream); cache.Add(stream, null); AsyncExec async = new AsyncExec(); async.request = WebRequest.Create(uri); async.message = message; async.stream = stream; async.silent = silent; async.Execute(); } else if (!silent) { message.ReplyPrivate("The stream you specified is invalid"); } } }
public override void Execute(IrcMessage message, string args) { int space = args.IndexOf(' '); if (space == -1) space = args.Length; string name = args.Substring(0, space); string val = args.Substring(space).Trim(); if (name.Length == 0) throw new Exception("No property name specified"); switch (name.ToLower()) { case "sd": if (val.Length != 0) { int ms = int.Parse(val); if(ms <= 0) throw new Exception("Invalid value for property"); State.SendDelay.Value = ms; } message.ReplyPrivate("State.SendDelay == " + State.SendDelay.Value.ToString()); break; case "pc": if(val.Length != 0) State.ParseChannel.Value = bool.Parse(val); message.ReplyPrivate("State.ParseChannel == " + State.ParseChannel.Value.ToString()); break; case "wt": if (val.Length != 0) { int wt = int.Parse(val); if(wt <= 1) throw new Exception("Invalid value for property"); State.WarningThreshold.Value = wt; } message.ReplyPrivate("State.WarningThreshold == " + State.WarningThreshold.Value.ToString()); break; #if QNETBOT case "cc": if (val.Length != 0) State.ControlCharacters.Value = bool.Parse(val); message.ReplyPrivate("State.ControlCharacters == " + State.ControlCharacters.Value.ToString()); break; case "qe": if (val.Length != 0) State.UseQEnforce.Value = bool.Parse(val); message.ReplyPrivate("State.UseQEnforce == " + State.UseQEnforce.Value.ToString()); break; case "qb": if (val.Length != 0) State.UseQuietBan.Value = bool.Parse(val); message.ReplyPrivate("State.UseQuietBan == " + State.UseQuietBan.Value.ToString()); break; #endif default: throw new Exception("Unknown property name: " + name); } }
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) { 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"); } } }
/// <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) { if (Limiter.AttemptOperation(message.Level)) { PrivilegeLevel privilege = CommandHandler.GetPrivilegeLevel(message.From); string priv; switch (privilege) { case PrivilegeLevel.Developer: case PrivilegeLevel.OnChannel: case PrivilegeLevel.Operator: case PrivilegeLevel.Subscriber: priv = " " + privilege.ToString(); break; default: priv = "n " + privilege.ToString(); break; } message.ReplyPrivate("'sup " + message.From + ", you are a" + priv); } }
//execute command public override void Execute(IrcMessage message, string args) { if (string.IsNullOrEmpty(args)) { if (lastmessage != null) ShowRecent(true, false); else ShowRecent(false, false); } else { string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 1) { ShowKey(message, words[0]); } else if (words.Length == 2) { SetKey(message, words[0], words[1]); } else throw new Exception("Syntax error, expects: !twitter [<key> [<value>]]"); } }
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) { 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); }
public override void Execute(IrcMessage message, string args) { Irc.SendChannelMessage("I'll be back!", true); Irc.Disconnect("Restart pending"); }
static void client_OnMessage(IrcMessage message) { lock (desBot.State.GlobalSync) { if (OnMessage != null) OnMessage.Invoke(message); } }
/// <summary> /// Injects a message from the console as if it was received through /msg /// </summary> /// <param name="text">The text in the message</param> public static void InjectConsoleMessage(string text) { IrcMessage message = new IrcMessage("<console>", text, null, false); client_OnMessage(message); }
//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"); } }
//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"); } }
internal static void Tick(IrcMessage msg) { try { if (msg != null) { if (msg.IsChannelMessage) { if (has_joked > 0) has_joked--; lastmessage = DateTime.UtcNow; } } else if (has_joked == 0 && (DateTime.UtcNow - lastmessage).TotalSeconds >= joke_limiter.Configuration.sub && joke_limiter.AttemptOperation(PrivilegeLevel.OnChannel)) { Program.Log("Triggering auto-joke"); has_joked = 5; string joke = Process("dummy", "tell me a joke", PrivilegeLevel.Operator); if (joke.Length != 0) { //Irc.SendChannelMessage(joke, false); } } } catch (Exception ex) { Program.Log("Alice.Tick() exception: " + ex.Message); } }
//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"); } }
//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"); } }