Exemplo n.º 1
0
        private async Task PayoutRewards()
        {
            if (string.IsNullOrWhiteSpace(_creds.MiningProxyUrl))
            {
                return;
            }

            try
            {
                _log.Info("Paying out mining rewards.");
                var res = await _http.GetStringAsync(_creds.MiningProxyUrl).ConfigureAwait(false);

                var data = JsonConvert.DeserializeObject <Payout[]>(res);
                if (data.Length == 0)
                {
                    _log.Info("No payouts sent out.");
                    return;
                }

                var filtered = data.Where(x => x.Amount > 0 && ulong.TryParse(x.User, out _)).ToArray();
                await _cs.AddBulkAsync(filtered.Select(x => ulong.Parse(x.User)),
                                       filtered.Select(x => "Mining payout"),
                                       filtered.Select(x => (long)x.Amount), true);
            }
            catch (Exception ex)
            {
                _log.Warn(ex);
            }
        }
Exemplo n.º 2
0
        private async Task TriggerVoteCheck()
        {
            try
            {
                using (var req = new HttpRequestMessage(HttpMethod.Get, _creds.VotesUrl))
                {
                    if (!string.IsNullOrWhiteSpace(_creds.VotesToken))
                    {
                        req.Headers.Add("Authorization", _creds.VotesToken);
                    }
                    using (var res = await _http.SendAsync(req).ConfigureAwait(false))
                    {
                        if (!res.IsSuccessStatusCode)
                        {
                            _log.Warn("Botlist API not reached.");
                            return;
                        }
                        var resStr = await res.Content.ReadAsStringAsync().ConfigureAwait(false);

                        var ids = JsonConvert.DeserializeObject <VoteModel[]>(resStr)
                                  .Select(x => x.User)
                                  .Distinct();
                        await _cs.AddBulkAsync(ids, ids.Select(x => "Voted - <https://discordbots.org/bot/nadeko/vote>"), ids.Select(x => 10L), true).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Warn(ex);
            }
        }
Exemplo n.º 3
0
        public ReactionEvent(BotConfig bc, DiscordSocketClient client, ICurrencyService cs, long amount)
        {
            _bc         = bc;
            _log        = LogManager.GetCurrentClassLogger();
            _client     = client;
            _cs         = cs;
            _botUser    = client.CurrentUser;
            _amount     = amount;
            Source      = new CancellationTokenSource();
            CancelToken = Source.Token;

            var _ = Task.Run(async() =>
            {
                var users = new List <ulong>();
                while (!CancelToken.IsCancellationRequested)
                {
                    await Task.Delay(1000).ConfigureAwait(false);
                    while (_toGiveTo.TryDequeue(out var usrId))
                    {
                        users.Add(usrId);
                    }

                    if (users.Count > 0)
                    {
                        var usrs = users.ToArray();
                        await _cs.AddBulkAsync(usrs, usrs.Select(x => "Reaction Event"), usrs.Select(x => _amount)).ConfigureAwait(false);
                    }

                    users.Clear();
                }
            }, CancelToken);
        }
Exemplo n.º 4
0
        private async void OnTimerTick(object state)
        {
            var          potEmpty = PotEmptied;
            List <ulong> toAward  = new List <ulong>();

            while (_toAward.TryDequeue(out var x))
            {
                toAward.Add(x);
            }

            if (!toAward.Any())
            {
                return;
            }

            try
            {
                await _cs.AddBulkAsync(toAward,
                                       toAward.Select(x => "Reaction Event"),
                                       toAward.Select(x => _amount),
                                       gamble : true).ConfigureAwait(false);

                if (_isPotLimited)
                {
                    await _msg.ModifyAsync(m =>
                    {
                        m.Embed = GetEmbed(PotSize).Build();
                    }, new RequestOptions()
                    {
                        RetryMode = RetryMode.AlwaysRetry
                    }).ConfigureAwait(false);
                }

                _log.Info("Gave {0} users {1} monies out of thin air.{2}",
                          toAward.Count,
                          _amount,
                          _isPotLimited ? $" {PotSize} left." : "");

                if (potEmpty)
                {
                    var _ = StopEvent();
                }
            }
            catch (Exception ex)
            {
                _log.Warn(ex);
            }
        }
Exemplo n.º 5
0
        private async void OnTimerTick(object state)
        {
            var          potEmpty = PotEmptied;
            List <ulong> toAward  = new List <ulong>();

            while (_toAward.TryDequeue(out var x))
            {
                toAward.Add(x);
            }

            if (!toAward.Any())
            {
                return;
            }

            try
            {
                await _cs.AddBulkAsync(toAward,
                                       toAward.Select(x => "GameStatus Event"),
                                       toAward.Select(x => _amount),
                                       gamble : true).ConfigureAwait(false);

                if (_isPotLimited)
                {
                    await _msg.ModifyAsync(m =>
                    {
                        m.Embed = GetEmbed(PotSize).Build();
                    }, new RequestOptions()
                    {
                        RetryMode = RetryMode.AlwaysRetry
                    }).ConfigureAwait(false);
                }

                Log.Information("Awarded {0} users {1} currency.{2}",
                                toAward.Count,
                                _amount,
                                _isPotLimited ? $" {PotSize} left." : "");

                if (potEmpty)
                {
                    var _ = StopEvent();
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Error in OnTimerTick in gamestatusevent");
            }
        }
Exemplo n.º 6
0
        public async Task Award(long amount, [Remainder] IRole role)
        {
            var users = (await Context.Guild.GetUsersAsync())
                        .Where(u => u.GetRoles().Contains(role))
                        .ToList();

            await _cs.AddBulkAsync(users.Select(x => x.Id),
                                   users.Select(x => $"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})"),
                                   users.Select(x => amount))
            .ConfigureAwait(false);

            await ReplyConfirmLocalized("mass_award",
                                        amount + CurrencySign,
                                        Format.Bold(users.Count.ToString()),
                                        Format.Bold(role.Name)).ConfigureAwait(false);
        }
Exemplo n.º 7
0
        public async Task Award(ShmartNumber amount, [Leftover] IRole role)
        {
            var users = (await ctx.Guild.GetUsersAsync().ConfigureAwait(false))
                        .Where(u => u.GetRoles().Contains(role))
                        .ToList();

            await _cs.AddBulkAsync(users.Select(x => x.Id),
                                   users.Select(x => $"Awarded by bot owner to **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
                                   users.Select(x => amount.Value),
                                   gamble : true)
            .ConfigureAwait(false);

            await ReplyConfirmLocalizedAsync("mass_award",
                                             n(amount) + CurrencySign,
                                             Format.Bold(users.Count.ToString()),
                                             Format.Bold(role.Name)).ConfigureAwait(false);
        }
Exemplo n.º 8
0
        public async Task Award(ShmartNumber amount, [Remainder] IRole role)
        {
            var users = (await Context.Guild.GetUsersAsync().ConfigureAwait(false))
                        .Where(u => u.GetRoles().Contains(role))
                        .ToList();

            await _cs.AddBulkAsync(users.Select(x => x.Id),
                                   users.Select(x => $"Awarded to all of **{role.Name}**. ({Context.User.Username}/{Context.User.Id})"),
                                   users.Select(x => amount.Value),
                                   gamble : true)
            .ConfigureAwait(false);

            await ReplyConfirmLocalizedAsync("mass_award",
                                             amount + CurrencySign,
                                             Format.Bold(users.Count.ToString()),
                                             Format.Bold(role.Name)).ConfigureAwait(false);
        }
            private async Task BotListUpvoters(long amount)
            {
                if (amount <= 0 || string.IsNullOrWhiteSpace(_creds.BotListToken))
                {
                    return;
                }
                string res;

                using (var http = new HttpClient())
                {
                    http.DefaultRequestHeaders.Add("Authorization", _creds.BotListToken);
                    res = await http.GetStringAsync($"https://discordbots.org/api/bots/116275390695079945/votes?onlyids=true");
                }
                var ids = JsonConvert.DeserializeObject <ulong[]>(res);
                await _cs.AddBulkAsync(ids, ids.Select(x => "Botlist Upvoter Event"), ids.Select(x => amount), true);

                await ReplyConfirmLocalized("bot_list_awarded",
                                            Format.Bold(amount.ToString()),
                                            Format.Bold(ids.Length.ToString())).ConfigureAwait(false);
            }
Exemplo n.º 10
0
        private async Task BotlistUpvoteLoop()
        {
            if (string.IsNullOrWhiteSpace(_creds.VotesUrl))
            {
                return;
            }
            while (true)
            {
                await Task.Delay(TimeSpan.FromHours(1));

                try
                {
                    var req = new HttpRequestMessage(HttpMethod.Get, _creds.VotesUrl);
                    if (!string.IsNullOrWhiteSpace(_creds.VotesToken))
                    {
                        req.Headers.Add("Authorization", _creds.VotesToken);
                    }
                    var res = await _http.SendAsync(req).ConfigureAwait(false);

                    if (!res.IsSuccessStatusCode)
                    {
                        _log.Warn("Botlist API not reached.");
                        continue;
                    }
                    var resStr = await res.Content.ReadAsStringAsync();

                    var ids = JsonConvert.DeserializeObject <VoteModel[]>(resStr)
                              .Select(x => x.User)
                              .Distinct();
                    await _cs.AddBulkAsync(ids, ids.Select(x => "Voted - <https://discordbots.org/bot/nadeko/vote>"), ids.Select(x => 10L), true);
                }
                catch (Exception ex)
                {
                    _log.Warn(ex);
                }
            }
            //await ReplyConfirmLocalized("bot_list_awarded",
            //    Format.Bold(amount.ToString()),
            //    Format.Bold(ids.Length.ToString())).ConfigureAwait(false);
        }