Example #1
0
        private void HandlePrivateMessage(OsuIrcMessageArgs args)
        {
            if (args.Sender == null || !args.Sender.Equals("BanchoBot", StringComparison.CurrentCultureIgnoreCase))
            {
                OnPrivateMessageRecieved?.Invoke(this, new OsuIrcPrivateMessageArg(args.Sender, args.Parameters, this));
                return;
            }

            if (args.Parameters.Equals("User not found", StringComparison.CurrentCultureIgnoreCase))
            {
                OnUserRequestedNotFound?.Invoke(this, new EventArgs());
                return;
            }

            bool triggerPrivMsgEvent = true;

            HandleBanchoMessage(args, ref triggerPrivMsgEvent);

            if (triggerPrivMsgEvent)
            {
                OnPrivateMessageRecieved?.Invoke(this, new OsuIrcPrivateMessageArg(args.Sender, args.Parameters, this));
            }
        }
Example #2
0
        private void HandleIrcMessage(object sender, string message)
        {
            try
            {
                OnRawDataRecieved?.Invoke(this, message);

                string msg            = message.TrimStart(':').Replace("!", "");
                string ircSender      = null;
                string ircFrom        = null;
                string ircDestination = null;
                string ircChannel     = null;
                string ircCommand     = null;
                string ircParameters  = null;

                string[] split;
                string   firstPart = null;
                if ((firstPart = GetSubString(ref msg, "!")) != null)
                {
                    int index = firstPart.IndexOf(' ');

                    if (index > 0)
                    {
                        if (firstPart[index + 1] == '3' &&
                            firstPart[index + 2] == '3' &&
                            firstPart[index + 3] == '3')
                        {
                            split = firstPart.Split(' ');

                            ircSender      = split[0];
                            ircCommand     = split[1];
                            ircDestination = split[2];
                            ircChannel     = split[3];
                            ircParameters  = split[4] + "!" + msg;

                            goto createArgs;
                        }
                    }

                    ircSender = firstPart;

                    /*
                     *  message: ":cho.ppy.sh PONG [email protected]"
                     *            :<sender> <command> <parameters>
                     */

                    string oldFirstPart = firstPart;
                    if ((firstPart = GetSubString(ref msg, ":")) != null)
                    {
                        ircParameters = msg;
                        split         = firstPart.Split(' ');

                        if (split.Length >= 2)
                        {
                            ircFrom    = split[0];
                            ircCommand = split[1];

                            if (split.Length >= 3)
                            {
                                ircChannel = split[2];
                            }
                        }
                        else
                        {
                            throw new NotSupportedException($"Unsupported split length {split.Length}");
                        }
                    }
                    else if (!msg.Contains(':') && !msg.Contains('+') && !oldFirstPart.Contains('+') && !oldFirstPart.Contains(':'))
                    {
                        split = oldFirstPart.Split(' ');

                        ircSender     = split[0];
                        ircCommand    = split[1];
                        ircParameters = split[2] + '!' + msg;
                    }
                    else
                    {
                        split = message.TrimStart(':').Split(' ');

                        ircFrom        = split[0];
                        ircCommand     = split[1];
                        ircChannel     = split[2];
                        ircDestination = split[3];
                        ircParameters  = split[4];
                    }
                }
                else
                {
                    if ((firstPart = GetSubString(ref msg, "=")) != null)
                    {
                        split = firstPart.Split(' ');

                        ircSender      = split[0];
                        ircCommand     = split[1];
                        ircDestination = split[2];

                        split = msg.Split(':');

                        ircChannel    = split[0];
                        ircParameters = split[1];
                    }
                    else if ((firstPart = GetSubString(ref msg, ":")) != null)
                    {
                        split         = firstPart.Split(' ');
                        ircParameters = msg;

                        ircSender  = split[0];
                        ircCommand = split[1];

                        if (split.Length >= 3)
                        {
                            ircDestination = split[2];

                            if (split.Length >= 4)
                            {
                                ircChannel = split[3];
                            }
                        }
                    }
                    else
                    {
                        split = msg.Split(' ');

                        if (split[0].Equals("ping", StringComparison.CurrentCultureIgnoreCase))
                        {
                            ircCommand = split[0];
                            ircSender  = split[1];
                        }
                        else
                        {
                            ircSender  = split[0];
                            ircCommand = split[1];
                        }

                        if (split.Length > 3)
                        {
                            ircDestination = split[2];
                            if (split.Length > 4)
                            {
                                ircChannel = split[3];
                                if (split.Length > 5)
                                {
                                    ircParameters = split[4] + " " + split[5];
                                }
                            }
                        }
                    }
                }

createArgs:
                {
                    OsuIrcMessageArgs args = new OsuIrcMessageArgs(ircSender, ircFrom, ircDestination,
                                                                   ircChannel, ircCommand, ircParameters);
                    TriggerEvents(args);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                Console.WriteLine("—————————————");
                Console.WriteLine(ex);
                Console.WriteLine(message);
                Console.WriteLine("—————————————");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
            }
        }
Example #3
0
 private void HandleBanchoMessage(OsuIrcMessageArgs args, ref bool triggerPrivMsgEvent)
 {
     //Handles: !stats <user>, !roll <maxValue>, !where <user>
     //[https://google.de test]
     if (_userStats.Equals(default))