示例#1
0
        private async Task UpdateBotListStatsAsync()
        {
            try
            {
                if (_dblApi != null && _dblBot == null)
                {
                    try
                    {
                        _dblBot = await _dblApi.GetMeAsync();
                    }
                    catch (NullReferenceException)
                    {
                        _dblApi = null;
                        await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Stats", "Could not get the bot info from DBL API, make sure the bot is listed in DBL and the token is valid"));

                        await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", "Bot server count will not be sent to DBL API."));
                    }
                }

                if (_dblBot != null)
                {
                    await _dblBot.UpdateStatsAsync(_client.Guilds.Count);
                }
                if (_discordBots != null)
                {
                    await _discordBots.UpdateStatsAsync(_client.CurrentUser.Id, _client.Guilds.Count);
                }
            }
            catch (Exception e) when(e is HttpRequestException || e is TaskCanceledException)
            {
                await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Stats", "Could not update the DBL/DiscordBots bot stats", e));
            }
        }
示例#2
0
        private async Task <(bool, int)> UpdateBotWebsitesAsync()
        {
            int  serverCount = this.DiscordClient.Guilds.Count;
            bool success     = true;

            if (this.IsDevEnv)
            {
                return(true, serverCount);
            }

            try
            {
                var obj = new { guildCount = serverCount };
                if (JsonHelper.TrySerialize(obj, this.Logger, out string json))
                {
                    string endpoint = $"https://discord.bots.gg/api/v1/bots/{Config.Instance.Discord.BotID}/stats";
                    await HttpHelper.PostAsync(endpoint, json, this.Logger, null, req => {
                        req.Headers[System.Net.HttpRequestHeader.Authorization] = Config.Instance.Discord.BotsToken;
                        req.ContentType = "application/json";
                    });
                }

                IDblSelfBot me = await this.DiscordBotList.GetMeAsync();

                await me.UpdateStatsAsync(serverCount);
            }
            catch
            {
                success = false;
            }

            return(success, serverCount);
        }
示例#3
0
        public async Task MainAsync()
        {
            using (var services = ConfigureServices())
            {
                _client = services.GetRequiredService <DiscordSocketClient>();

                _client.Log += LogAsync;

                // Login
                await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("rtBotToken"));

                await _client.SetGameAsync("/rt", type : ActivityType.Watching);

                await _client.StartAsync();

                // Crate Discord Bot List client (Top.gg)
                var discordBotList = new AuthDiscordBotListApi(477287091798278145, Environment.GetEnvironmentVariable("rtBotListToken"));
                _dblApi = await discordBotList.GetMeAsync();

                // Initialize HttpClient
                WebUtils.http = new HttpClient();

                // These events will update the current amount of guilds the bot is in on Top.gg (_dblApi)
                _client.Ready       += OnReady;
                _client.JoinedGuild += OnGuildJoined;
                _client.LeftGuild   += OnGuildLeft;

                // Register commands
                await services.GetRequiredService <CommandHandlingService>().InitializeAsync();

                // Run forever
                await Task.Delay(Timeout.Infinite);
            }
        }
示例#4
0
        private static async Task UpdateTopGGStats()
        {
            if (bot.CurrentUser.Id == 729696788097007717) // make sure we are only setting this on the main bot, not test bot!
            {
                AuthDiscordBotListApi DblApi = GetTopGGClient();
                IDblSelfBot           me     = await DblApi.GetMeAsync();

                await me.UpdateStatsAsync(bot.Guilds.Count);
            }
        }
示例#5
0
        // Update the bot shard and guild count for DiscordBotList
        public async Task DBLGet()
        {
            AuthDiscordBotListApi DblApi = new AuthDiscordBotListApi(Config.bot.selfID, Config.bot.dblToken);
            IDblSelfBot           me     = await DblApi.GetMeAsync();

            // Update stats sharded   indexShard shardCount shards
            //await me.UpdateStatsAsync(24,        50,        new[] { 12, 421, 62, 241, 524, 534 });

            // Update stats           guildCount
            await me.UpdateStatsAsync(_client.Guilds.Count);
        }
示例#6
0
        public async Task UpdateDBLStatsAsync(int serverCount)
        {
            try
            {
                IDblSelfBot self = await dblApi.GetMeAsync();

                await self.UpdateStatsAsync(serverCount);
            } catch (Exception e)
            {
                await lib.EdgyLog(LogSeverity.Error, e.Message);
            }
        }
示例#7
0
        public async Task UpdateGuildCount(int count)
        {
            if (_enabled)
            {
                if (me == null)
                {
                    this.me = await dblapi.GetMeAsync();
                }

                await me.UpdateStatsAsync(count);
            }
        }
示例#8
0
        private async Task MainAsync()
        {
#if DEV
            const string dt = "atoken";
#else
            const string dt = "token";
#endif
            Discord = new DiscordClient(new DiscordConfiguration
            {
                Token           = ConfigurationManager.AppSettings[dt],
                TokenType       = TokenType.Bot,
                MinimumLogLevel = LogLevel.Debug
            });
            Commands = Discord.UseCommandsNext(new CommandsNextConfiguration {
                StringPrefixes = new[] { "w+" }
            });
            Commands.RegisterCommands <WordHooksCommands>();
            Commands.RegisterCommands <ServerCommands>();
            Commands.RegisterCommands <MiscCommands>();

            Database = new Database("storage.st");

            OptedOut = Database.GetTable <bool>("optedout");
            Guilds   = Database.GetTable <Guild>("guilds");

            Discord.MessageCreated += HandleMessage;
            Discord.GuildAvailable += e =>
            {
                Discord.Logger.Log(LogLevel.Debug, $"Guild '{e.Guild.Name}' is available",
                                   DateTime.Now);
                return(Task.CompletedTask);
            };


            await Discord.ConnectAsync(new DiscordActivity($" for messages | prefix w+", ActivityType.Watching));

#if !DEV
            DblApi     = new AuthDiscordBotListApi(Discord.CurrentUser.Id, ConfigurationManager.AppSettings["dbltoken"]);
            DblSelfBot = await DblApi.GetMeAsync();
#endif

            await Update();

            await Task.Delay(-1);
        }
示例#9
0
        public async Task OnReady()
        {
            var botID        = ulong.TryParse(Config.bot.BotUserID, out ulong ID);
            var mutualGuilds = _client.GetUser(ID).MutualGuilds;

            AuthDiscordBotListApi dblAPI = new AuthDiscordBotListApi(ID, Config.bot.DblApiKey);

            Console.WriteLine("\nRetrieving bot from DBL API...");
            IDblSelfBot me = await dblAPI.GetMeAsync();

            Console.WriteLine("Pushing stats to DBL API...");
            await me.UpdateStatsAsync(mutualGuilds.Count());

            Console.WriteLine("Success.");

            var serverCountValue = new Dictionary <string, string>
            {
                { "server_count", $"{mutualGuilds.Count()}" }
            };

            int i = 0;

            foreach (var guild in mutualGuilds)
            {
                for (int j = 0; j <= guild.MemberCount; j++)
                {
                    i++;
                }
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"\nAce Pilot Kaguya cleared for takeoff. Servicing {mutualGuilds.Count()} guilds" +
                              $" and {i.ToString("N0")} members." +
                              "\nBegin Logging\n");
            Console.WriteLine("--------------------------------------------");
        }