public IrcMessage(PrivateMessage raw) { Who = raw.User.Nick; Where = raw.Source; var toMatch = Regex.Match(raw.Message, @"^((?:[^:]+?)|(?::.+?:))[,:]\s"); if (toMatch.Success) { To = toMatch.Groups[1].Value; Text = raw.Message.Substring(toMatch.Length); } else Text = raw.Message; }
private static void Client_ChannelMessageRecieved(object sender, PrivateMessageEventArgs e) { try { // Is the sender an admin? client.WhoIs(e.PrivateMessage.User.Nick, who => { // Get the response admin = settings.admins.Contains(who.LoggedInAs); whoIs = who.LoggedInAs; // Set the private message message = e.PrivateMessage; // Find the current channel channel = client.Channels[e.PrivateMessage.Source]; // Log-Spam if (!admin) BaseUtils.Log(e.PrivateMessage.User.Nick + " in " + e.PrivateMessage.Source + ": " + e.PrivateMessage.Message); else BaseUtils.LogAdmin(e.PrivateMessage.User.Nick + " in " + e.PrivateMessage.Source + ": " + e.PrivateMessage.Message); // Get the message string msg = e.PrivateMessage.Message.Trim(); // If it should be a command if (msg.StartsWith(settings.startChar)) { // Mute if (settings.muted.Contains(channel.Name) && !BaseUtils.Is(msg, settings.startChar + "unmute")) return; // Get all the methods MethodInfo[] methods = Assembly.GetAssembly(typeof(IRCBot)).GetTypes().SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static)).ToArray() as MethodInfo[]; string start = settings.startChar; // Loop through them foreach (MethodInfo method in methods) { // Check the Commands foreach (Command c in method.GetCustomAttributes(typeof(Command), false)) { // Check if the command is correct if (BaseUtils.Is(msg, start + c.command)) { if (c.admin && !admin) break; method.Invoke(null, new[] { msg }); } } // Check the multipleCommands foreach (MultipleCommand mc in method.GetCustomAttributes(typeof(MultipleCommand), false)) { // Check if the command is correct if (BaseUtils.Is(msg, start + mc.commandT) || BaseUtils.Is(msg, start + mc.commandF)) { if (mc.admin && !admin) break; method.Invoke(null, new object[] { msg, BaseUtils.Is(msg, start + mc.commandT) }); } } } } Logic.Run(); }); } catch { } whoIs = ""; }