Esempio n. 1
0
        void FireCallbacks(CommandEvent commandEvent)
        {
            bot.Logger.Info("Executing command '{0}'. Called by '{1}' from '{2}'.", commandEvent.Command.Alias, bot.Names.GetFriendName(commandEvent.Source.Caller), commandEvent.Source.Context);

            var alias = commandEvent.Command.Alias;

            if (commands.ContainsKey(alias))
            {
                // Process the command.
                var parser = new CommandParser(bot);
                parser.NoPermissionMessage = commandEvent.Command.NoPermissionMessage;
                parser.Silent = Muted;
                parser.ProcessCommand(commandEvent);
            }
        }
Esempio n. 2
0
        public async void ProcessCommand(CommandEvent commandEvent)
        {
            if (!commandEvent.Source.HadPermission)
            {
                if (string.IsNullOrEmpty(NoPermissionMessage))
                {
                    return;
                }

                if (commandEvent.Source.Context == MessageContext.Chat)
                {
                    Bot.Connection.SayToChat(Bot.CurrentChatRoomID, NoPermissionMessage);
                }
                else
                {
                    Bot.Connection.SayToFriend(commandEvent.Source.Caller, NoPermissionMessage);
                }
            }
            else
            {
                string result = null;
                if (commandEvent.Command.IsAsync)
                {
                    result = await commandEvent.Command.ExecuteAsync(commandEvent.Source);
                }
                else
                {
                    result = commandEvent.Command.Execute(commandEvent.Source);
                }

                if (!string.IsNullOrEmpty(result) && !Silent)
                {
                    if (commandEvent.Source.Context == MessageContext.Chat)
                    {
                        Bot.Connection.SayToChat(Bot.CurrentChatRoomID, result);
                    }
                    else
                    {
                        Bot.Connection.SayToFriend(commandEvent.Source.Caller, result);
                    }
                }
            }
        }
Esempio n. 3
0
        void HandleMessage(MessageContext context, SteamID caller, string message)
        {
            var parser = new MessageParser(message);

            if (parser.IsValid)
            {
                // Find a matching command using the parsed alias
                var command = GetCommand(parser.Command) as ChatCommand;

                if (command != null)
                {
                    // Cache the name of the caller.
                    bot.Names.Cache(caller);

                    var requiresPermission = command.UsersOnly || command.AdminOnly;
                    var hasPermission      = command.UsersOnly && (bot.Users.IsAdmin(caller) || bot.Users.IsUser(caller)) || command.AdminOnly && bot.Users.IsAdmin(caller);
                    var commandEvent       = new CommandEvent(context, caller, parser, command, requiresPermission ? hasPermission : true);

                    FireCallbacks(commandEvent);
                }
            }
        }