Ejemplo n.º 1
0
        public void OnIRCMessage(object sender, ChatMessageEventArgs e)
        {
            var commandData = new CommandArguments
            {
                CommandType    = ECommandType.IRC,
                SenderIdentity = e.Sender,
                Recipient      = e.Recipient,
                Message        = e.Message
            };

            if (Steam.Instance.Client.IsConnected)
            {
                PubFileHandler.OnMessage(commandData);
            }

            LinkExpander.OnMessage(commandData);

            if (e.Message[0] != Settings.Current.IRC.CommandPrefix)
            {
                return;
            }

            var message      = (string)e.Message;
            var messageArray = message.Split(' ');
            var trigger      = messageArray[0];

            if (trigger.Length < 2)
            {
                return;
            }

            trigger = trigger.Substring(1);

            var command = RegisteredCommands.FirstOrDefault(cmd => cmd.Trigger.Equals(trigger));

            if (command == null)
            {
                return;
            }

            commandData.Message = message.Substring(messageArray[0].Length).Trim();

            if (command.IsSteamCommand && !Steam.Instance.Client.IsConnected)
            {
                commandData.Reply("Not connected to Steam.");

                return;
            }

            if (command.IsAdminCommand)
            {
                var ident = string.Format("{0}@{1}", e.Sender.Username, e.Sender.Hostname);

                if (!Settings.Current.IRC.Admins.Contains(ident))
                {
                    return;
                }
            }

            Log.WriteInfo("CommandHandler", "Handling IRC command \"{0}\" for {1}", message, commandData);

            TryCommand(command, commandData);
        }
        public void OnIRCMessage(object sender, ChatMessageEventArgs e)
        {
            var commandData = new CommandArguments
            {
                CommandType    = ECommandType.IRC,
                SenderIdentity = e.Sender,
                Nickname       = e.Sender.Nickname.ToString(),
                Recipient      = e.Recipient,
                Message        = e.Message
            };

            if (commandData.SenderIdentity.Hostname == "steamdb/discord-relay")
            {
                var match = DiscordRelayMessageRegex.Match(commandData.Message);

                if (!match.Success)
                {
                    return;
                }

                // Remove IRC colors, remove control characters, remove zero width space, add @ and a space
                commandData.Nickname = $"@{Utils.RemoveControlCharacters(Colors.StripColors(match.Groups["name"].Value.Replace("\u200B", "")))} ";
                commandData.Message  = match.Groups["message"].Value;
            }
            else
            {
                if (Steam.Instance.Client.IsConnected)
                {
                    PubFileHandler.OnMessage(commandData);
                }

                LinkExpander.OnMessage(commandData);
            }

            if (commandData.Message[0] != Settings.Current.IRC.CommandPrefix)
            {
                return;
            }

            var message      = commandData.Message;
            var messageArray = message.Split(' ');
            var trigger      = messageArray[0];

            if (trigger.Length < 2)
            {
                return;
            }

            trigger = trigger.Substring(1);

            var command = RegisteredCommands.Find(cmd => cmd.Trigger.Equals(trigger));

            if (command == null)
            {
                return;
            }

            commandData.Message = message.Substring(messageArray[0].Length).Trim();

            if (command.IsSteamCommand && !Steam.Instance.Client.IsConnected)
            {
                commandData.Reply("Not connected to Steam.");

                return;
            }

            var ident = string.Format("{0}@{1}", e.Sender.Username, e.Sender.Hostname);

            commandData.IsUserAdmin = Settings.Current.IRC.Admins.Contains(ident);

            if (command.IsAdminCommand && !commandData.IsUserAdmin)
            {
                return;
            }

            Log.WriteInfo("CommandHandler", "Handling IRC command \"{0}\" for {1}", message, commandData);

            TryCommand(command, commandData);
        }