Example #1
0
    public static string DebugMessageEvent(ChatSharp.Events.PrivateMessageEventArgs e)
    {
        string parameters = "";

        for (int i = 0; i < e.IrcMessage.Parameters.Length; i++)
        {
            if (i != 0)
            {
                parameters += ", ";
            }
            parameters += e.IrcMessage.Parameters[i];
        }

        string result = string.Format(
            @"IrcMessage: 
            Command: {0}
            Parameters: [{1}]
            Prefix: {2}
            Raw message: {3}

            PrivateMessage:
            IsChannelMessage: {4}
            Message: {5}
            Source: {6}
            User: {7}",
            e.IrcMessage.Command, parameters, e.IrcMessage.Prefix, e.IrcMessage.RawMessage,
            e.PrivateMessage.IsChannelMessage, e.PrivateMessage.Message, e.PrivateMessage.Source, e.PrivateMessage.User
            );

        return(result);
    }
Example #2
0
    void Client_ChannelMessageRecieved(object sender, ChatSharp.Events.PrivateMessageEventArgs e)
    {
        Debug.Log("[IRC] Message!");
        if (e.PrivateMessage.Message.Contains("team"))
        {
            if (e.PrivateMessage.Message.Contains("blue"))
            {
                EventManager.QueueEvent(() =>
                {
                    Minions.SpawnAllLanes(true, 2);
                    Client.SendMessage("Sending reinforcements to team BLUE!", "#vimaster_game");
                });
            }

            if (e.PrivateMessage.Message.Contains("red"))
            {
                EventManager.QueueEvent(() =>
                {
                    Minions.SpawnAllLanes(false, 2);
                    Client.SendMessage("Sending reinforcements to team RED!", "#vimaster_game");
                });
            }
        }
    }
Example #3
0
 protected internal virtual void OnUserMessageRecieved(PrivateMessageEventArgs e)
 {
     if (UserMessageRecieved != null) UserMessageRecieved(this, e);
 }
Example #4
0
 protected internal virtual void OnChannelMessageRecieved(PrivateMessageEventArgs e)
 {
     if (ChannelMessageRecieved != null) ChannelMessageRecieved(this, e);
 }
Example #5
0
 public static void HandlePrivmsg(IrcClient client, IrcMessage message)
 {
     var eventArgs = new PrivateMessageEventArgs(message);
     client.OnPrivateMessageRecieved(eventArgs);
     if (eventArgs.PrivateMessage.IsChannelMessage)
         client.OnChannelMessageRecieved(eventArgs);
     else
         client.OnUserMessageRecieved(eventArgs);
 }
Example #6
0
 public static void HandlePrivmsg(IrcClient client, IrcMessage message)
 {
     var eventArgs = new PrivateMessageEventArgs(message, client.ServerInfo);
     client.OnPrivateMessageRecieved(eventArgs);
     if (eventArgs.PrivateMessage.IsChannelMessage)
     {
         try
         {
             // Populate this user's hostname and user from the message
             // TODO: Merge all users from all channels into one list and keep references to which channels they're in
             var channel = client.Channels[eventArgs.PrivateMessage.Source];
             var u = channel.Users[eventArgs.PrivateMessage.User.Nick];
             u.Hostname = eventArgs.PrivateMessage.User.Hostname;
             u.User = eventArgs.PrivateMessage.User.User;
         }
         catch { /* silently ignored */ }
         client.OnChannelMessageRecieved(eventArgs);
     }
     else
         client.OnUserMessageRecieved(eventArgs);
 }
Example #7
0
 private static void OnUserMessageReceived(object s, PrivateMessageEventArgs e)
 {
     if (!Utils.IsDev(e.PrivateMessage.User.Nick)) return;
     if (e.PrivateMessage.Message.StartsWith(_commandPrefix + "msg "))
         Utils.SendChannel(e.PrivateMessage.Message.Substring(5));
 }
Example #8
0
        private static void OnChannelMessageReceived(object sender, PrivateMessageEventArgs args)
        {
            var serverList = new List<string> {"RR1", "RR2", "MagicFarm", "Dire20", "Unleashed", "Pixelmon", "TPPI", "Horizons"};
            var isIngameCommand = false;
            var message = args.PrivateMessage.Message.Trim();
            var paramList = message.Split(' ');

            if (serverList.Contains(args.PrivateMessage.User.Nick))
            {
                var ingameMessage = args.PrivateMessage.Message.Split(':');
                if (ingameMessage.Any())
                {
                    try
                    {
                        if (ingameMessage[1].StartsWith(" " + _commandPrefix))
                        {
                            paramList = ingameMessage[1].Trim().Split(' ');
                            isIngameCommand = true;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (args.PrivateMessage.Message.StartsWith(_commandPrefix) || paramList[0].StartsWith(_commandPrefix))
            {
                // Only listen to people who are not blacklisted
                if (BlackList.All(item => item.Ip != args.PrivateMessage.User.Hostname) || Utils.IsAdmin(args.PrivateMessage.User.Nick) || Utils.IsOp(args.PrivateMessage.User.Nick))
                {
                    if (IsLocked & Utils.IsOp(args.PrivateMessage.User.Nick) != true & !paramList[0].Contains("player"))
                    {
                        Utils.SendNotice("Edgebot is currently set to Ops Only.", args.PrivateMessage.User.Nick);
                    }
                    else
                    {
                        foreach (var type in Commands.Where(cmd => cmd.Value.Listener == paramList[0].Substring(1)).Select(cmd => Type.GetType(cmd.Key)).Where(type => type != null))
                        {
                            ((CommandHandler)Activator.CreateInstance(type)).HandleCommand(paramList, args.PrivateMessage.User, isIngameCommand);
                        }
                    }
                }
                else
                {
                    Utils.SendNotice("You have been blacklisted from this bot. Refer to a staff member if you feel this is in error.", args.PrivateMessage.User.Nick);
                }
            }

            //listen for www or http(s)
            if (!string.IsNullOrEmpty(_nickServAuth))
            {
                if (args.PrivateMessage.Message.Contains("http://") || args.PrivateMessage.Message.Contains("https://") || args.PrivateMessage.Message.Contains("www."))
                {
                    for (var i = 0; i < paramList.Count(); i++)
                    {
                        var url = "";
                        if (paramList[i].Contains("http://") || paramList[i].Contains("https://"))
                        {
                            url = paramList[i];
                        }
                        else if (paramList[i].Contains("www."))
                        {
                            url = string.Concat("http://", paramList[i]);
                        }

                        if (!string.IsNullOrEmpty(url))
                        {
                            Connection.GetLinkTitle(url, title =>
                            {
                                if (!string.IsNullOrEmpty(title))
                                {
                                    Utils.SendChannel("URL TITLE: " + title);
                                }
                                else
                                {
                                    Utils.Log("Connection: Result is null");
                                }
                            }, Utils.HandleException);
                        }
                    }
                }
            }

            if (args.PrivateMessage.Message.StartsWith(_commandPrefix))
            {
                Utils.Log("<{0}> {1}", args.PrivateMessage.User.Nick, args.PrivateMessage.Message);
            }
        }
Example #9
0
        private static void UrlSubmitted(PrivateMessageEventArgs e)
        {
            bool secureUrl = false;
            string url;
            if (e.PrivateMessage.Message.Contains ("http://"))
                url = e.PrivateMessage.Message.Substring (e.PrivateMessage.Message.LastIndexOf ("http://")).Trim ();
            else
            {
                url = e.PrivateMessage.Message.Substring (e.PrivateMessage.Message.LastIndexOf ("https://")).Trim ();
                secureUrl = true;
            }

            //shoutout to Blank for this :D
            //thank god because i'm terrible with regular expressions
            WebClient wc = new WebClient();
            try
            {
                client.SendRawMessage("NOTICE {0} :One sec, {1}..", e.PrivateMessage.User.Nick, e.PrivateMessage.User.Nick);
                if(url.Contains("pornhub"))
                {
                        return;
                }
                string source = wc.DownloadString(url);
                string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
                title = title.Trim(new char[]{'\n', '\r'});
                if(secureUrl)
                    client.SendRawMessage("PRIVMSG {0} :{1} submitted a link: [{2}] - {3}", client.Channels[0].Name, e.PrivateMessage.User.Nick, title, url.Substring(url.LastIndexOf("https://")).Trim('/'));
                else
                    client.SendRawMessage("PRIVMSG {0} :{1} submitted a link: [{2}] - {3}", client.Channels[0].Name, e.PrivateMessage.User.Nick, title, url.Substring(url.LastIndexOf("http://")).Trim('/'));
            }
            catch(Exception ex)
            {
                client.SendRawMessage ("PRIVMSG {0} :Couldn't Load this webpage!");

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine ("Exception occurred!");
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine (ex.Message);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine ("Exception occurred!");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Example #10
0
 internal void OnPrivateMessageRecieved(PrivateMessageEventArgs e)
 {
     if (PrivateMessageRecieved != null) PrivateMessageRecieved(this, e);
 }
        /// <summary>
        /// Handle IRC messages that are commands
        /// </summary>
        /// <param name="messageReceivedEventArgs">Event args of message to handle</param>
        private void handleMessage(PrivateMessageEventArgs messageReceivedEventArgs)
        {
            string messageText = messageReceivedEventArgs.PrivateMessage.Message.ToString();
            string[] messageTextArr = Regex.Split(messageText, " ");

            // Output message text
            asyncOutputBoxAppendNoBreak(botOutputBox, "    <");
            asyncOutputBoxColorAppend(botOutputBox, messageReceivedEventArgs.PrivateMessage.User.Nick.ToString(), "Green");
            asyncOutputBoxColorAppend(botOutputBox, "> " + messageReceivedEventArgs.PrivateMessage.Message + "\r", "Black");

            if (messageTextArr[0] == "!hypeBot")
            {
                // Message is command for HypeBot
                if (messageTextArr[1] == "hello")
                {
                    // Message requests "hello" response
                    string returnMessage = "Hello, " + messageReceivedEventArgs.PrivateMessage.User.Nick + "!";
                    ircClient.Channels[messageReceivedEventArgs.PrivateMessage.Source].SendMessage(returnMessage);
                    asyncOutputBoxAppend(botOutputBox, "    <" + ircClient.User.Nick + "> " + returnMessage);
                }
            }
            else
            {
                // Message is not command for HypeBot, ignore
                return;
            }
        }
Example #12
0
        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 = "";
        }