Example #1
0
        public async Task HandleAsync(Command command)
        {
            var userPoints = await _userPointsRepository.GetUserBalanceAsync(command.Author.Id);

            if (userPoints is null)
            {
                await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                     "Can't find your wallet. Use ?register to create wallet");

                return;
            }

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 $"**{command.Author.Username}** currently has **{string.Format("{0:0.##}", userPoints)}** points");
        }
Example #2
0
        public async Task HandleAsync(Command command)
        {
            await _userPointsRepository.AddUserToSystem(command.Author.Username,
                                                        command.Author.Id);

            await _discordRestClient.PostMessage(command.CalledFromChannel, "Wallet created");
        }
Example #3
0
        public async Task HandleAsync(Command command)
        {
            var huhChamp = _guildRepository.GetGuild(command.CalledFromGuild)?
                           .Emojis.FirstOrDefault(x => x.Name == "HuhChamp");

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 "Invalid command <:{huhChamp.Name}:{huhChamp.Id}>");
        }
        public async Task HandleAsync(Command command)
        {
            var sadChamp = _guildRepository.GetGuild(command.CalledFromGuild)?
                           .Emojis.FirstOrDefault(x => x.Name == "SadChamp");

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 $"Internal application error <:{sadChamp.Name}:{sadChamp.Id}>");
        }
        private async Task PlayGame()
        {
            var rnd          = new Random();
            var attackerRoll = rnd.Next(0, 3);
            var defenderRoll = rnd.Next(0, 3);

            var attackerWon = false;

            if (attackerRoll == defenderRoll)
            {
                await _discordRestClient.PostMessage(_command.CalledFromChannel,
                                                     new Message { Content = "Draw! No points" });

                return;
            }
            else if (attackerRoll == 0 && defenderRoll == 2) // Rock vs Scissors
            {
                attackerWon = true;
            }
            else if (attackerRoll == 0 && defenderRoll == 1) // Rock vs Paper
            {
                attackerWon = false;
            }
            else if (attackerRoll == 2 && defenderRoll == 1) // Scissors vs Paper
            {
                attackerWon = true;
            }
            else if (attackerRoll == 2 && defenderRoll == 0) // Scissors vs Rock
            {
                attackerWon = false;
            }
            else if (attackerRoll == 1 && defenderRoll == 0) // Paper vs Rock
            {
                attackerWon = true;
            }
            else if (attackerRoll == 1 && defenderRoll == 2) // Paper vs Scissors
            {
                attackerWon = false;
            }

            await ManagePoints(attackerWon);
            await DisplayGameResult(attackerWon, attackerRoll, defenderRoll);
        }
Example #6
0
        public async Task HandleAsync(Command command)
        {
            var requestSendTime = DateTime.Now;
            var response        = await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                                       new Message { Content = "Calculating..." });

            var latency = response.Data.Timestamp - requestSendTime;

            await _discordRestClient.EditMessage(command.CalledFromChannel,
                                                 response.Data.Id, new Message { Content = $"{latency.Milliseconds}ms" });
        }
Example #7
0
        public async Task HandleAsync(Command command)
        {
            await _userPointsRepository.AddBalanceToUserAccount(command.Author.Id, 1000);

            await _userPointsRepository.UpdateDailyPoints(command.Author.Id);

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 new Rest.Models.Message {
                Content = $"Added 1000 points to user **{command.Author.Username}**"
            });
        }
Example #8
0
        public async Task HandleAsync(object @event)
        {
            if (_clientInfoRepository.GetClientInfo() != null)
            {
                _clientInfoRepository.DeleteClientInfo();
            }

            _clientInfoRepository.AddClientInfo(JsonConvert.DeserializeObject <ClientInfo>(@event.ToString()));

            await _discordRestClient.PostMessage("764840399696822322", "Ready to serve");
        }
Example #9
0
        public async Task HandleAsync(Command command)
        {
            try
            {
                var offerThreads = await GetWebsiteContentAsync();

                var embedMessage = new EbmedMessageBuilder()
                                   .AddAuthor()
                                   .AddMessageFields(FormatFields(offerThreads))
                                   .Build();

                await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                     new Message { Embed = embedMessage });
            }
            catch (Exception ex)
            {
                await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                     string.Format("Wystąpił bład - {0}", ex.Message));
            }
        }
        public async Task HandleAsync(object @event)
        {
            var eventData = JsonConvert.DeserializeObject <MessageReactionRemove>(@event.ToString());

            await _discordRestClient.PostMessage("764840399696822322",
                                                 new Rest.Models.Message
            {
                Content = $"User <@{eventData.UserId}> removed his <:{eventData.Emoji.Name}:{eventData.Emoji.Id}> " +
                          $"reaction on message id: {eventData.MessageId}"
            });
        }
Example #11
0
        private async Task HandleHelpCommand(Command command)
        {
            var isRegistered = _component.IsRegisteredWithKey <ICommandHandler>(command.Arguments[0]);

            if (isRegistered)
            {
                var commandUsage = _component.ResolveKeyed <ICommandHandler>(command.Arguments[0])
                                   .GetCommandUsage();

                if (commandUsage is null)
                {
                    await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                         "Help for this command is missing");
                }
                else
                {
                    await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                         "Command usage: " + commandUsage);
                }
            }
        }
Example #12
0
        public async Task HandleAsync(Command command)
        {
            var embedMessage = new EbmedMessageBuilder()
                               .AddAuthor()
                               .AddMessageBody("TEST_BODY")
                               .AddMessageFields(
                new EmbedField("Test", "test"),
                new EmbedField("Test", "test"))
                               .AddMessageFooter("TEST_FOOTER")
                               .Build();

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 new Message { Embed = embedMessage });
        }
Example #13
0
        public async Task HandleAsync(Command command)
        {
            joinEmoji  = GetEmoji(command.CalledFromGuild, "Join");
            startEmoji = GetEmoji(command.CalledFromGuild, "Stonks");

            var response = await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                                $"Created blackjack game! Use {MessageUtilities.UseEmoji(joinEmoji)} to join game, " +
                                                                $"{MessageUtilities.MentionUser(command.Author.Id)} use {MessageUtilities.UseEmoji(startEmoji)} to start game!");

            await _discordRestClient.AddReactionToMessage(command.CalledFromChannel,
                                                          response.Data.Id, new Emoji[] { joinEmoji, startEmoji });

            await _trackedMessageRepository.AddTrackedMessageAsync(new TrackedMessage(command.CalledFromGuild,
                                                                                      command.CalledFromChannel, response.Data.Id, this.GetAttributeCommandName(),
                                                                                      new Dictionary <string, string> {
                { joinEmoji.Name, joinEmoji.Id }
            }));

            _blackjackRepository.AddGame(new BlackjackGame(response.Data.Id,
                                                           command.Author.Id, float.Parse(command.Arguments[0])));
        }
Example #14
0
        public async Task HandleAsync(Command command)
        {
            var users = await _userPointsRepository.GetUsersAsync();

            var embedMessage = new EbmedMessageBuilder()
                               .AddAuthor();

            foreach (var user in users.OrderByDescending(x => x.Balance).Take(15))
            {
                embedMessage.AddMessageField(new EmbedField($"{user.Nickname}",
                                                            string.Format("{0:0.##}", user.Balance)));
            }

            embedMessage.AddMessageFooter(DateTime.Now.ToShortDateString());

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 new Message { Embed = embedMessage.Build() });
        }