Exemplo n.º 1
0
        public async Task RunAsync()
        {
            _client = new DiscordSocketClient(new DiscordSocketConfig {
                LogLevel = LogSeverity.Verbose
            });

            var    Initialize   = new Configuration(null);
            string discordToken = Initialize.GetConfig("tokens:discord");   // reads bot token from _config.yml

            if (string.IsNullOrWhiteSpace(discordToken))
            {
                throw new Exception("Please enter your bot's token into the `config.yaml` file found in the applications root directory.");
            }

            await _client.LoginAsync(TokenType.Bot, discordToken);     // Login to discord

            await _client.StartAsync();

            CommandService commandService = new CommandService(new CommandServiceConfig {
                DefaultRunMode = RunMode.Async
            });

            Handlers.CommandHandler commandHandler = new Handlers.CommandHandler(_client, commandService, '&');
            commandHandler.AddModule <Modules.CommandModule>();
            await commandHandler.InstallCommandsAsync();

            ReactionAddedHandler reactionAddedHandler = new ReactionAddedHandler(_client);
            await reactionAddedHandler.InstallReactionAddedHandlerAsync();


            await Task.Delay(-1);
        }
Exemplo n.º 2
0
        private async Task Client_OnReactionAdded(Cacheable <IUserMessage, ulong> cacheAble, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (reaction.UserId != CurrentBot.Id && _waitedReactions.ContainsKey(reaction.MessageId))
            {
                _waitedReactions[reaction.MessageId].Add(reaction.Emote);
            }

            if (reaction.UserId != CurrentBot.Id && _waitedListQuestion.ContainsKey(reaction.UserId) && _waitedListQuestion[reaction.UserId].Key.Contains(reaction.MessageId))
            {
                // YES emote
                if (reaction.Emote.Name == "\u2705")
                {
                    _waitedListQuestion[reaction.UserId].Value = (await reaction.Channel.GetMessageAsync(reaction.MessageId)).Content;
                }
            }

            ReactionAddedHandler?.Invoke(reaction);
        }