Esempio n. 1
0
        async Task <DiscloseMessage> IDiscloseFacade.SendMessageToUser(DiscloseUser user, string text)
        {
            IMessage message = await _discordClient.SendMessageToUser(user.DiscordUser, text);

            IEnumerable <DiscloseUser> users = await _server.GetUsersAsync();

            return(new DiscloseMessage(message, users.FirstOrDefault(u => u.Id == _discordClient.ClientId)));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public async Task SetUserDataAsync <TData>(DiscloseUser user, string key, TData data)
        {
            SemaphoreSlim semaphore = _locks.GetOrAdd(user.Id, new SemaphoreSlim(1));

            await semaphore.WaitAsync();

            try
            {
                await DataStore.SetUserDataAsync(user, key, data);
            }
            finally
            {
                semaphore.Release();
            }
        }
Esempio n. 4
0
 internal DiscloseMessage(IMessage message, DiscloseUser user)
 {
     Content = message.Content;
     Channel = new DiscloseChannel(message.Channel);
     User    = user;
 }
Esempio n. 5
0
 /// <inheritdoc />
 public abstract Task Handle(DiscloseUser user, DiscloseServer server);