Exemplo n.º 1
0
        public Task DoPremiumAsync([Remainder] string code = null)
        {
            var tokenModel = TokenModel.Load();
            var tokens     = tokenModel.TokenList;
            var match      = tokens.FirstOrDefault(x => x.Token == code);

            if (match == null)
            {
                throw new Exception($"Invalid Token\nYou may purchase tokens at:\n{ConfigModel.Load().PurchaseLink}");
            }

            Context.Server.Settings.Premium.IsPremium = true;
            Context.Server.Settings.Premium.Expiry    = Context.Server.Settings.Premium.Expiry < DateTime.UtcNow ? DateTime.UtcNow + TimeSpan.FromDays(match.Days) : Context.Server.Settings.Premium.Expiry + TimeSpan.FromDays(match.Days);
            Context.Server.Settings.Premium.PremiumKeys.Add(new GuildModel.GuildSettings._Premium.Key
            {
                Token    = code,
                ValidFor = TimeSpan.FromDays(match.Days)
            });
            Context.Server.Save();
            tokens.Remove(match);
            tokenModel.TokenList = tokens;
            tokenModel.Save();
            return(SimpleEmbedAsync(
                       $"Success, Token Redeemed ({match.Days} days)\n"
                       + $"Server expires on {Context.Server.Settings.Premium.Expiry.ToLongDateString()} {Context.Server.Settings.Premium.Expiry.ToLongTimeString()}"));
        }
Exemplo n.º 2
0
        public Task CreateKeysAsync(int keyCount, int days)
        {
            if (keyCount > 100)
            {
                throw new Exception("Cannot Create more than 100 keys at a time");
            }

            return(InlineReactionReplyAsync(
                       new ReactionCallbackData(
                           "",
                           new EmbedBuilder
            {
                Description =
                    $"Do you wish to create {keyCount} keys, each with {days} days?"
            }.Build(),
                           true,
                           true,
                           TimeSpan.FromSeconds(30)).WithCallback(
                           new Emoji("✅"),
                           async(c, r) =>
            {
                var tokenModel = TokenModel.Load();
                var sb = new StringBuilder();
                for (var i = 0; i < keyCount; i++)
                {
                    var token =
                        $"{GenerateRandomNo()}-{GenerateRandomNo()}-{GenerateRandomNo()}-{GenerateRandomNo()}";
                    if (tokenModel.TokenList.Any(x => x.Token == token))
                    {
                        continue;
                    }

                    tokenModel.TokenList.Add(
                        new TokenModel.TokenClass {
                        Token = token, Days = days
                    });
                    sb.AppendLine(token);
                }

                tokenModel.Save();
                await SimpleEmbedAsync("Complete");
                await SimpleEmbedAsync($"New Tokens\n```\n{sb.ToString()}\n```");
                sb.Clear();
            }).WithCallback(
                           new Emoji("❎"),
                           (c, r) => SimpleEmbedAsync("Exited Token Task"))));
        }