Example #1
0
        private async void OnMessageReceived(object sender, MessageEventArgs e)
        {
            IMessage message = e.Message;

            if (message.User.Id == _discordClient.ClientId)
            {
                return;
            }

            ParsedCommand parsedCommand = _parser.ParseCommand(message);

            if (!parsedCommand.Success)
            {
                return;
            }

            bool commandExists = _commandHandlers.TryGetValue(parsedCommand.Command, out ICommandHandler commandHandler);

            if (!commandExists)
            {
                return;
            }

            if (commandHandler.ChannelFilter != null && !commandHandler.ChannelFilter(new DiscloseChannel(message.Channel)))
            {
                return;
            }

            DiscloseUser discloseUser;

            if (message.Channel.IsPrivateMessage)
            {
                //User objects in Direct Messages don't have roles because there is no server context. So find the user on the server and use that user to have the user's roles available
                IEnumerable <DiscloseUser> serverUsers = await _server.GetUsersAsync();

                discloseUser = serverUsers.FirstOrDefault(su => su.Id == message.User.Id);

                if (discloseUser == null)
                {
                    return;
                }
            }
            else
            {
                discloseUser = new DiscloseUser((IServerUser)message.User, _server);
            }

            DiscloseMessage discloseMessage = new DiscloseMessage(message, discloseUser);

            if (commandHandler.UserFilter != null && !commandHandler.UserFilter(discloseMessage.User))
            {
                return;
            }

            await commandHandler.Handle(discloseMessage, parsedCommand.Argument);
        }
 public Task Handle(DiscloseMessage message, string arguments)
 {
     return(_commandHandler.Handle(message, arguments));
 }
Example #3
0
 public abstract Task Handle(DiscloseMessage message, string arguments);