public void CommandSave(object sender, CommandEventArgs e) { PluginEntry plugin; if (Bot.Plugins.TryGetValue(e.Parameters[0], out plugin)) { plugin.Obj.OnSave(); e.Reply(string.Format("Called \u0002{0}\u0002 to save successfully.", e.Parameters[0])); } else { e.Reply(string.Format("I haven't loaded a plugin with key \u0002{0}\u001F.", e.Parameters[0])); } }
public void CommandUnload(object sender, CommandEventArgs e) { PluginEntry plugin; if (Bot.Plugins.TryGetValue(e.Parameters[0], out plugin)) { Bot.DropPlugin(e.Parameters[0]); e.Reply(string.Format("Dropped \u0002{0}\u0002.", e.Parameters[0])); } else { e.Reply(string.Format("I haven't loaded a plugin with key \u0002{0}\u001F.", e.Parameters[0])); } }
public void CommandSaveAll(object sender, CommandEventArgs e) { foreach (PluginEntry pluginData in Bot.Plugins) { pluginData.Obj.OnSave(); } e.Reply("Called plugins to save successfully."); }
public void CommandThreadState(object sender, CommandEventArgs e) { IrcClient client = null; foreach (ClientEntry clientEntry in Bot.Clients) { IrcClient _client = clientEntry.Client; if (_client.Address.Equals(e.Parameters[0], StringComparison.OrdinalIgnoreCase) || (_client.Extensions.NetworkName ?? "").Equals(e.Parameters[0], StringComparison.OrdinalIgnoreCase)) { client = _client; break; } } if (client == null) { e.Reply(string.Format("I'm not connected to \u0002{0}\u0002.", e.Parameters[0])); return; } var method = Bot.GetClientEntry(client).CurrentProcedure; if (method == null) { e.Reply(string.Format("\u0002{0}\u0002's read thread is \u0002standing by\u0002.", e.Parameters[0])); } else { var attribute = method.GetCustomAttributes <CommandAttribute>().FirstOrDefault(); if (attribute != null) { e.Reply(string.Format("\u0002{0}\u0002's read thread is in \u0002{1}\u0002 – !\u0002{2}\u0002.", e.Parameters[0], Bot.GetClientEntry(client).CurrentPlugin.Key, attribute.Names[0])); } else { e.Reply(string.Format("\u0002{0}\u0002's read thread is in \u0002{1}\u0002 – !\u0002{2}\u0002.", e.Parameters[0], Bot.GetClientEntry(client).CurrentPlugin.Key, method.Name)); } } }
public void CommandLoad(object sender, CommandEventArgs e) { string key; string filename; string realFilename; if (e.Parameters.Length == 2) { key = e.Parameters[0]; filename = e.Parameters[1]; } else { filename = e.Parameters[1]; key = Path.GetFileNameWithoutExtension(filename); } if (Bot.Plugins.Contains(key)) { e.Reply(string.Format("A plugin with the key \u0002{0}\u000F is already loaded.", key)); return; } if (!File.Exists(realFilename = filename)) { if (Path.IsPathRooted(realFilename)) { e.Reply(string.Format("The file \u0002{0}\u000F doesn't exist.", filename)); return; } else { realFilename = Path.Combine("Plugins", filename); if (!File.Exists(realFilename)) { e.Reply(string.Format("The file \u0002{0}\u000F couldn't be found.", filename)); return; } } } try { Bot.LoadPlugin(key, realFilename); e.Reply(string.Format("Loaded \u0002{0}\u0002.", Bot.Plugins[key].Obj.Name)); } catch (InvalidPluginException ex) { e.Reply("That file could not be loaded: {0}", ex.Message); } catch (Exception ex) { e.Reply(string.Format("Failed to load the plugin: {0}", ex.Message)); } }
public async void CommandAddTrigger(object sender, CommandEventArgs e) { var match = Regex.Match(e.Parameters[0], @"(?:/(\\.|[^\/])*/)?(\S+)(?>\s+)(.+)"); if (!match.Success) { return; } string regex, switches; if (match.Groups[1].Success) { regex = match.Groups[1].Value; switches = match.Groups[2].Value; } else { regex = match.Groups[2].Value; switches = ""; } var fields = match.Groups[3].Value.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); string alias = fields[0]; Command command; foreach (var pluginEntry in Bot.Plugins) { if (!pluginEntry.Obj.Commands.TryGetValue(alias, out command)) { continue; } // Check the scope. if ((command.Attribute.Scope & CommandScope.PM) == 0 && !(e.Target is IrcChannel)) { continue; } if ((command.Attribute.Scope & CommandScope.Channel) == 0 && e.Target is IrcChannel) { continue; } // Check for permissions. string permission; if (command.Attribute.Permission == null) { permission = null; } else if (command.Attribute.Permission != "" && command.Attribute.Permission.StartsWith(".")) { permission = this.Key + command.Attribute.Permission; } else { permission = command.Attribute.Permission; } if (permission != null) { if (!await Bot.CheckPermissionAsync(e.Sender, permission)) { if (command.Attribute.NoPermissionsMessage != null) { e.Whisper(command.Attribute.NoPermissionsMessage); } return; } } pluginEntry.Obj.Triggers.Add(new Trigger(new TriggerAttribute(regex), (_sender, _e) => command.Handler.Invoke(_sender, new CommandEventArgs(_e.Client, _e.Target, _e.Sender, _e.Match.Groups.Cast <Group>().Select(g => g.Value).ToArray())))); e.Reply("Added a trigger successfully."); return; } }
public void CommandChannels(object sender, CommandEventArgs e) { PluginEntry plugin; short direction = 0; if (Bot.Plugins.TryGetValue(e.Parameters[0], out plugin)) { if (e.Parameters.Length == 2) { List <string> channels = new List <string>(plugin.Obj.Channels); foreach (string channel in e.Parameters[1].Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)) { string realChannel; if (channel.StartsWith("+")) { direction = 1; realChannel = channel.Substring(1); } else if (channel.StartsWith("-")) { direction = -1; realChannel = channel.Substring(1); } else { if (direction == 0) { channels.Clear(); direction = 1; } realChannel = channel; } if (direction == 1) { if (!channels.Contains(realChannel, StringComparer.OrdinalIgnoreCase)) { channels.Add(realChannel); } } else { for (int i = 0; i < channels.Count; ++i) { if (channels[i].Equals(realChannel, StringComparison.OrdinalIgnoreCase)) { channels.RemoveAt(i); break; } } } } plugin.Obj.Channels = channels.ToArray(); e.Reply(string.Format("\u0002{0}\u0002 is now assigned to the following channels: \u0002{1}\u0002.", e.Parameters[0], string.Join("\u0002, \u0002", plugin.Obj.Channels))); } else { e.Reply(string.Format("\u0002{0}\u0002 is assigned to the following channels: \u0002{1}\u0002.", e.Parameters[0], string.Join("\u0002, \u0002", plugin.Obj.Channels))); } } else { e.Reply(string.Format("I haven't loaded a plugin with key \u0002{0}\u001F.", e.Parameters[0])); } }
public void CommandSet(object sender, CommandEventArgs e) { if (e.Parameters.Length == 1) { switch (e.Parameters[0].ToUpperInvariant()) { case "WHO": case "WHOINTERVAL": if (this.WhoTimer.Enabled) { e.Reply("WHO requests \u00039are\u000F being sent every \u0002{0}\u0002 seconds.", this.WhoTimer.Interval / 1000); } else { e.Reply("WHO requests \u00034are not\u000F being sent.", 0); } break; default: e.Whisper(string.Format("I don't manage a setting named \u0002{0}\u0002.", e.Parameters[1])); break; } } else { switch (e.Parameters[0].ToUpperInvariant()) { case "WHO": case "WHOINTERVAL": int value; if (int.TryParse(e.Parameters[1], out value)) { if (value == 0) { this.WhoTimer.Stop(); e.Reply("WHO requests will \u00034no longer\u000F be sent.", 0); } else if (value >= 5) { this.WhoTimer.Interval = value * 1000; this.WhoTimer.Start(); e.Reply("WHO requests will \u00039now\u000F be sent every \u0002{0}\u0002 seconds.", value); } else if (value > 0) { e.Whisper("That number is too small.", value); } else { e.Whisper("The number cannot be negative.", value); } } else { e.Whisper(string.Format("That's not a valid integer.", e.Parameters[1])); } break; default: e.Whisper(string.Format("I don't manage a setting named \u0002{0}\u0002.", e.Parameters[1])); break; } } }
public void CommandGetGender(object sender, CommandEventArgs e) { Gender gender; string header = null; if (this.GenderTable.TryGetValue(e.Parameters[0], out gender)) { header = e.Parameters[0]; } else { string[] fields = e.Parameters[0].Split(new char[] { '/' }, 2); if (fields.Length == 1) { fields = new string[] { "*", fields[0] } } ; var thisEntry = Bot.GetClientEntry(e.Client); if (fields[1].Contains("!")) { foreach (ClientEntry clientEntry in new[] { thisEntry }.Concat(Bot.Clients).Distinct()) { IrcClient client = clientEntry.Client; if (fields[0] == "*" || fields[0].Equals(client.Extensions.NetworkName, StringComparison.OrdinalIgnoreCase) || fields[0].Equals(client.Address, StringComparison.OrdinalIgnoreCase)) { foreach (var user in client.Users) { if (Bot.MaskCheck(user.ToString(), fields[1])) { gender = user.Gender; header = user.Nickname + "\u0002 on \u0002" + client.Extensions.NetworkName; break; } } break; } } } else { foreach (ClientEntry clientEntry in new[] { thisEntry }.Concat(Bot.Clients).Distinct()) { IrcClient client = clientEntry.Client; if (fields[0] == "*" || fields[0].Equals(client.Extensions.NetworkName, StringComparison.OrdinalIgnoreCase) || fields[0].Equals(client.Address, StringComparison.OrdinalIgnoreCase)) { if (client.Users.TryGetValue(fields[1], out IrcUser user)) { gender = user.Gender; header = user.Nickname + "\u0002 on \u0002" + client.Extensions.NetworkName; } break; } } } if (header == null) { e.Whisper("I didn't find any matching users."); return; } } if (gender == Gender.Male) { e.Reply("\u0002{0}\u0002 is \u0002male\u0002.", header); } else if (gender == Gender.Female) { e.Reply("\u0002{0}\u0002 is \u0002female\u0002.", header); } else if (gender == Gender.Bot) { e.Reply("\u0002{0}\u0002 is \u0002none\u0002.", header); } else { e.Reply("\u0002{0}\u0002 is \u0002unknown\u0002.", header); } }
public async void CommandSetGender(object sender, CommandEventArgs e) { Gender gender = Gender.Unspecified; bool valid = false; string mask = null; if (e.Parameters.Length == 1) { valid = true; mask = "*!*" + (e.Sender.Ident.StartsWith("~") ? e.Sender.Ident.Substring(1) : e.Sender.Ident) + "@" + e.Sender.Host; if (e.Parameters[0].Equals("male", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[00].Equals("m", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Male; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002male\u0002.", mask); } else if (e.Parameters[0].Equals("female", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[0].Equals("f", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Female; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002female\u0002.", mask); } else if (e.Parameters[0].Equals("none", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[0].Equals("n", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[0].Equals("bot", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[0].Equals("b", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Bot; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002none\u0002.", mask); } else if (e.Parameters[0].Equals("clear", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[0].Equals("c", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Unspecified; } else { valid = false; } } if (valid) { if (gender == Gender.Unspecified) { if (this.GenderTable.Remove(mask)) { e.Reply("Gender for \u0002{0}\u0002 has been cleared.", mask); } else { e.Whisper("No gender for \u0002{0}\u0002 was set.", mask); return; } } else { this.GenderTable[mask] = gender; } e.Sender.Gender = gender; return; } else if (await Bot.CheckPermissionAsync(e.Sender, this.Key + ".setgender.others")) { if (e.Parameters.Length == 1 || e.Parameters[1].Equals("clear", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("c", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Unspecified; if (this.GenderTable.Remove(e.Parameters[0])) { e.Reply("Gender for \u0002{0}\u0002 has been cleared.", e.Parameters[0]); } else { e.Whisper("No gender for \u0002{0}\u0002 was set.", e.Parameters[0]); return; } } else if (e.Parameters[1].Equals("male", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("m", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Male; this.GenderTable[e.Parameters[0]] = Gender.Male; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002male\u0002.", e.Parameters[0]); } else if (e.Parameters[1].Equals("female", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("f", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Female; this.GenderTable[e.Parameters[0]] = Gender.Female; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002female\u0002.", e.Parameters[0]); } else if (e.Parameters[1].Equals("none", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("n", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("bot", StringComparison.InvariantCultureIgnoreCase) || e.Parameters[1].Equals("b", StringComparison.InvariantCultureIgnoreCase)) { gender = Gender.Bot; this.GenderTable[e.Parameters[0]] = Gender.Bot; e.Reply("Gender for \u0002{0}\u0002 has been set to \u0002none\u0002.", e.Parameters[0]); } else { e.Whisper("'{0}' isn't a valid option. Use 'male', 'female', 'none' or 'clear'.", e.Parameters[1]); return; } } else { e.Whisper("You don't have permission to set a gender for others."); return; } string[] fields = e.Parameters[0].Split(new char[] { '/' }, 2); if (fields.Length == 1) { fields = new string[] { "*", fields[0] } } ; int index = fields[1].IndexOf('!'); int index2 = index == -1 ? 0 : fields[1].IndexOfAny(new char[] { '*', '?' }, 0, index); if (index2 == -1) { foreach (ClientEntry clientEntry in Bot.Clients) { IrcClient client = clientEntry.Client; if (fields[0] == "*" || fields[0].Equals(client.Extensions.NetworkName, StringComparison.OrdinalIgnoreCase) || fields[0].Equals(client.Address, StringComparison.OrdinalIgnoreCase)) { IrcUser user; if (client.Users.TryGetValue(fields[1].Substring(0, index), out user)) { if (Bot.MaskCheck(user.ToString(), fields[1])) { user.Gender = gender; } } } } } else { foreach (ClientEntry clientEntry in Bot.Clients) { IrcClient client = clientEntry.Client; if (fields[0] == "*" || fields[0].Equals(client.NetworkName, StringComparison.OrdinalIgnoreCase) || fields[0].Equals(client.Address, StringComparison.OrdinalIgnoreCase)) { foreach (IrcUser user in client.Users) { if (Bot.MaskCheck(user.ToString(), fields[1])) { user.Gender = gender; } } } } } }