Esempio n. 1
0
        public void OnChatMessage(SteamFriends.ChatMsgCallback callback)
        {
            if (callback.ChatMsgType != EChatEntryType.ChatMsg || callback.Message[0] != '!' || callback.Message.Contains('\n'))
            {
                return;
            }

            var i            = callback.Message.IndexOf(' ');
            var inputCommand = i == -1 ? callback.Message : callback.Message.Substring(0, i);

            Action <CommandHandler.CommandArguments> callbackFunction;

            if (CommandHandler.Commands.TryGetValue(inputCommand, out callbackFunction))
            {
                var input = i == -1 ? string.Empty : callback.Message.Substring(i).Trim();

                var command = new CommandHandler.CommandArguments
                {
                    SenderID   = callback.ChatterID,
                    ChatRoomID = callback.ChatRoomID,
                    Nickname   = Steam.Instance.Friends.GetFriendPersonaName(callback.ChatterID),
                    Message    = input
                };

                if (SteamDB.IsBusy())
                {
                    CommandHandler.ReplyToCommand(command, "{0}{1}{2}: The bot is currently busy.", Colors.OLIVE, command.Nickname, Colors.NORMAL);

                    return;
                }

                Log.WriteInfo("Steam", "Handling command {0} for user {1} in chatroom {2}", inputCommand, callback.ChatterID, callback.ChatRoomID);

                callbackFunction(command);
            }
        }
Esempio n. 2
0
        public static void OnChannelMessage(object sender, IrcEventArgs e)
        {
            if (e.Data.Message[0] != '!')
            {
                return;
            }

            if (e.Data.Message == "!relogin" && IRC.IsSenderOp(e.Data.Channel, e.Data.Nick))
            {
                if (Steam.Instance.Client.IsConnected)
                {
                    Steam.Instance.Client.Disconnect();
                }

                foreach (var idler in Program.GCIdlers)
                {
                    if (idler.Client.IsConnected)
                    {
                        idler.Client.Disconnect();
                    }
                }

                Log.WriteInfo("IRC", "Relogin forced by user {0} in channel {1}", e.Data.Nick, e.Data.Channel);

                ReplyToCommand(new CommandArguments {
                    Channel = e.Data.Channel
                }, "{0} is responsible for death of everything and everyone now.", e.Data.Nick);
            }

            Action <CommandArguments> callbackFunction;

            if (Commands.TryGetValue(e.Data.MessageArray[0], out callbackFunction))
            {
                var input = e.Data.Message.Substring(e.Data.MessageArray[0].Length).Trim();

                var command = new CommandArguments
                {
                    Channel  = e.Data.Channel,
                    Nickname = e.Data.Nick,
                    Message  = input
                };

                if (!Steam.Instance.Client.IsConnected)
                {
                    ReplyToCommand(command, "{0}{1}{2}: Not connected to Steam.", Colors.OLIVE, command.Nickname, Colors.NORMAL);

                    return;
                }

                if (SteamDB.IsBusy())
                {
                    ReplyToCommand(command, "{0}{1}{2}: The bot is currently busy.", Colors.OLIVE, command.Nickname, Colors.NORMAL);

                    return;
                }

                Log.WriteInfo("IRC", "Handling command {0} for user {1} in channel {2}", e.Data.MessageArray[0], e.Data.Nick, e.Data.Channel);

                callbackFunction(command);
            }
        }