/// <summary> /// Initializes a new a <see cref="TriggerEventArgs"/> object with the specified data. /// </summary> /// <param name="client">The <see cref="IrcClient"/> on which the trigger occurred.</param> /// <param name="target">The channel in which the trigger occurred, or the sender if it was a PM.</param> /// <param name="sender">The user triggering the procedure.</param> /// <param name="match">The <see cref="System.Text.RegularExpressions.Match"/> object containing details of the match.</param> public TriggerEventArgs(IrcClient client, IrcMessageTarget target, IrcUser sender, Match match) { this.Client = client; this.Target = target; this.Sender = sender; this.Match = match; }
private async Task ShowHelp(IrcMessageTarget target, IrcUser user, string topic) { bool anyText = false; foreach (var plugin in Bot.Plugins) { if (plugin.Obj.IsActiveTarget(target)) { var text = plugin.Obj.Help(topic, target); if (text != null) { anyText = true; foreach (var line in text.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None)) { Bot.Say(user.Client, user.Nickname, Bot.ReplaceCommands(line, target)); Thread.Sleep(600); } } } } if (!anyText) { // If they typed a command label, run `!cmdinfo`. if (!await showCommandInfo(target, user, topic)) { Bot.Say(user.Client, user.Nickname, $"I have no information on that topic. Use {Colours.Bold}{Bot.ReplaceCommands("!cmdlist", target)}{Colours.Bold} for a list of commands."); } } }
public override string Help(string Topic, IrcMessageTarget target) { if (Topic == null) { return($"Use {Colours.Bold}!cmdlist{Colours.Bold} for a list of my commands, or {Colours.Bold}!cmdinfo {Colours.Underline}label{Colours.Reset} for information on one."); } return(null); }
public override string Help(string topic, IrcMessageTarget target) { if (topic == null) { return("Quotes are being provided in this channel."); } return(null); }
/// <summary>Initializes a new <see cref="CommandEventArgs"/> object with the specified data.</summary> /// <param name="client">The <see cref="IrcClient"/> on which the command was heard.</param> /// <param name="target">The target of the event.</param> /// <param name="sender">The user invoking the command.</param> /// <param name="parameters">The list of parameters to the command.</param> public CommandEventArgs(IrcClient client, IrcMessageTarget target, IrcUser sender, string[] parameters) { this.Client = client; this.Target = target; this.Sender = sender; this.Parameters = parameters; this.Cancel = true; }
private async Task <bool> showCommandInfo(IrcMessageTarget target, IrcUser user, string message) { if (!Bot.IsCommand(target, message, false, out var pluginKey, out var label, out var prefix, out var parameters)) { return(false); } var result = Bot.GetCommand(user, target, pluginKey, label, parameters); if (result == null) { return(false); } var command = result.Value.command; // Check for permissions. var attribute = command.Attribute; string permission; if (attribute.Permission == null) { permission = null; } else if (attribute.Permission != "" && attribute.Permission.StartsWith(".")) { permission = result.Value.plugin.Key + attribute.Permission; } else { permission = attribute.Permission; } if (permission != null && !await Bot.CheckPermissionAsync(user, permission)) { if (attribute.NoPermissionsMessage != null) { Bot.Say(user.Client, user.Nickname, attribute.NoPermissionsMessage); } return(true); } Bot.Say(user.Client, user.Nickname, Colours.Bold + "Aliases:" + Colours.Bold + " " + string.Join(" ", command.Attribute.Names)); #if (DEBUG) Bot.Say(user.Client, user.Nickname, Colours.Bold + "Priority:" + Colours.Bold + " " + command.Attribute.PriorityHandler.Invoke(new CommandEventArgs(target.Client, target, user, new string[0]))); #endif Bot.Say(user.Client, user.Nickname, Colours.Bold + "Syntax:" + Colours.Bold + " " + command.Attribute.Syntax); Bot.Say(user.Client, user.Nickname, command.Attribute.Description); return(true); }
public bool RunArenaRegex(IrcClient client, IrcMessageTarget channel, IrcUser sender, string message) { foreach (System.Reflection.MethodInfo method in this.GetType().GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic)) { foreach (Attribute attribute in method.GetCustomAttributes(typeof(ArenaRegexAttribute), false)) { foreach (string expression in ((ArenaRegexAttribute)attribute).Expressions) { Match match = Regex.Match(message, expression); if (match.Success) { try { method.Invoke(this, new object[] { this, new TriggerEventArgs(client, channel, sender, match) }); } catch (Exception ex) { this.LogError(method.Name, ex); } return(true); } } } } return(false); }
public async void SendCheck(string message, IrcClient originConnection, IrcMessageTarget origin) { foreach (string channelName in this.Targets) { string[] fields = channelName.Split(new char[] { '/' }, 2); if (fields.Length == 1) { fields = new string[] { "*", fields[0] } } ; IEnumerable <ClientEntry> clients; if (fields[0] == "*") { clients = Bot.Clients; } else { ClientEntry client = Bot.Clients.FirstOrDefault(c => fields[0].Equals(c.Client.Extensions.NetworkName, StringComparison.OrdinalIgnoreCase) || fields[0].Equals(c.Client.Address, StringComparison.OrdinalIgnoreCase)); if (client == default(ClientEntry)) { return; } clients = new ClientEntry[] { client }; } foreach (ClientEntry clientEntry in clients) { IrcClient client = clientEntry.Client; if (fields[1] == "*") { if (client == originConnection) { foreach (IrcChannel channel in client.Channels.Where(_channel => _channel != origin)) { channel.Say(message); } } else { foreach (IrcChannel channel in client.Channels) { channel.Say(message); } } } else if (client.IsChannel(fields[1]) && (client != originConnection || !client.CaseMappingComparer.Equals(fields[1], origin))) { client.Send("PRIVMSG " + fields[1] + " :" + message); } else { IrcUser user; if ((client != originConnection || !client.CaseMappingComparer.Equals(fields[1], origin)) && client.Users.TryGetValue(fields[1], out user) && await Bot.CheckPermissionAsync(user, this.Key + ".receive")) { client.Send("PRIVMSG " + fields[1] + " :" + message); } } } } }