コード例 #1
0
        public async Task VoteAsync()
        {
            if (string.IsNullOrWhiteSpace(_config["token_discord_boats"]))
            {
                throw new Exception("Expected valid API token for Discord Boats");
            }

            using var boatClient = new BoatClient(_client.CurrentUser.Id, _config["token_discord_boats"]);
            VoteResultFlag result = VoteService.Next(boatClient, Context.Account);
            await Context.Channel.SendMessageAsync(VoteService.ApplyAndDisplay(Context.Account, result));
        }
コード例 #2
0
ファイル: VoteService.cs プロジェクト: AbnerSquared/Orikivo
        public static Message ApplyAndDisplay(ArcadeUser user, VoteResultFlag flag)
        {
            long           reward  = Reward;
            string         header  = $"{Reward:##,0}";
            ImmutableColor color   = GammaPalette.Lemon[Gamma.Max];
            string         icon    = $"+ {Icons.Tokens}";
            string         content = "Thank you for voting!";

            switch (flag)
            {
            case VoteResultFlag.Cooldown:
                TimeSpan sinceLast = StatHelper.SinceLast(user, CooldownVars.Vote);
                TimeSpan rem       = Cooldown - sinceLast;
                DateTime time      = DateTime.UtcNow.Add(rem);

                content = "You are on cooldown.";
                color   = GammaPalette.Amber[Gamma.Max];
                header  = Format.Countdown(rem);
                icon    = Icons.GetClock(time.Hour);
                break;

            case VoteResultFlag.Reset:
                content = "Your streak has been reset.";
                color   = GammaPalette.NeonRed[Gamma.Max];
                user.SetVar(Stats.VoteStreak, 0);
                break;

            case VoteResultFlag.Bonus:
                content = "You have received a bonus.";
                color   = GammaPalette.Glass[Gamma.Max];
                header += $" + {Bonus:##,0}";
                reward += Bonus;
                break;

            case VoteResultFlag.Success:
                content = "Thank you for voting!";
                color   = GammaPalette.Wumpite[Gamma.Max];
                break;

            case VoteResultFlag.Unavailable:
                content = $"Voting allows you to receive a **Token** on each vote you submit.\nYou are given an additional 2 **Tokens** on each 7 day streak.\n**Tokens** can be cashed out, or saved to purchase upcoming special items that can only be bought with this currency!\nYou can vote every **12** hours on any voting platform, and your streak is cut short after **48**  hours.\n\n> **Voting Portal**\n• [**Discord Boats**](https://discord.boats/bot/686093964029329413/vote)";
                color   = GammaPalette.Oceanic[Gamma.Max];
                icon    = Icons.Tokens;
                header  = $"Voting";
                reward  = 0;
                break;
            }

            if (flag != VoteResultFlag.Cooldown && flag != VoteResultFlag.Unavailable)
            {
                user.SetVar(CooldownVars.Vote, DateTime.UtcNow.Ticks);
                user.AddToVar(Stats.VoteStreak);
                user.AddToVar(Stats.TimesVoted);
                Var.SetIfGreater(user, Stats.LongestVoteStreak, Stats.VoteStreak);
                user.Give(reward, CurrencyType.Tokens);
            }

            var message  = new MessageBuilder();
            var embedder = Embedder.Default;

            embedder.Color   = color;
            embedder.Header  = $"{icon} {header}";
            message.Content  = content;
            message.Embedder = embedder;

            return(message.Build());
        }