Ejemplo n.º 1
0
 public RankedDataController(ILogger <RankedDataController> logger, RankedService rankedService, SeasonService seasonService)
 {
     _logger        = logger ?? throw new ArgumentNullException(nameof(logger));
     _rankedService = rankedService ?? throw new ArgumentNullException(nameof(rankedService));
     _seasonService = seasonService ?? throw new ArgumentNullException(nameof(seasonService));
 }
Ejemplo n.º 2
0
        private async Task RunAsync()
        {
            socketClient = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel            = LogSeverity.Verbose,
                AlwaysDownloadUsers = true,
                GatewayIntents      = GatewayIntents.GuildBans | GatewayIntents.DirectMessages | GatewayIntents.DirectMessageReactions |
                                      GatewayIntents.GuildBans | GatewayIntents.GuildEmojis | GatewayIntents.GuildMembers | GatewayIntents.GuildPresences | GatewayIntents.GuildMessageReactions |
                                      GatewayIntents.GuildMessages | GatewayIntents.Guilds
            });
            socketClient.Log += Log;

            restClient = new DiscordRestClient(new DiscordRestConfig
            {
                LogLevel = LogSeverity.Verbose
            });
            restClient.Log += Log;

            if (File.Exists("./update"))
            {
                var temp = File.ReadAllText("./update");
                ulong.TryParse(temp, out updateChannel);
                File.Delete("./update");
                Console.WriteLine($"Found an update file! It contained [{temp}] and we got [{updateChannel}] from it!");
            }

            config = Config.Load();
            //uptime = new UptimeService();
            events             = EventStorage.Load();
            rankedService      = new RankedService();
            strings            = new RandomStrings();
            discordBotsService = new DiscordBotsService();
            //gate = new AccountGateService();


            //var map = new DependencyMap();
            map = new ServiceCollection().AddSingleton(socketClient).AddSingleton(config).AddSingleton(strings).AddSingleton(events).AddSingleton(rankedService).AddSingleton(discordBotsService) /*.AddSingleton(gate)*/.BuildServiceProvider();

            //await ConfigureServicesAsync(map);

            await socketClient.LoginAsync(TokenType.Bot, config.Token);

            await socketClient.StartAsync();

            await restClient.LoginAsync(TokenType.Bot, config.Token);

            if (File.Exists("./deadlock"))
            {
                Console.WriteLine("We're recovering from a deadlock.");
                File.Delete("./deadlock");
                foreach (var u in config.OwnerIds)
                {
                    (await restClient.GetUserAsync(u))?
                    .SendMessageAsync($"I recovered from a deadlock.\n`{DateTime.Now.ToShortDateString()}` `{DateTime.Now.ToLongTimeString()}`");
                }
            }

            socketClient.GuildAvailable  += Client_GuildAvailable;
            socketClient.Disconnected    += SocketClient_Disconnected;
            socketClient.MessageReceived += SocketClient_MessageReceived;
            socketClient.ReactionAdded   += SocketClient_ReactionAdded;
            //client.GuildMemberUpdated += Client_UserUpdated;
            // memes

            //await uptime.Install(map);

            socketClient.UserJoined += Client_UserJoined;

            //await gate.Install(map);
            await discordBotsService.Install(map);

            handler = new CommandHandler();
            await handler.Install(map);

            //Task.Run(async () =>
            //{
            //    await Task.Delay(1000 * 60); // wait a minute before downloading to ensure we have access to the server
            //    await client.DownloadUsersAsync(new IGuild[] { client.GetGuild(110373943822540800) });
            //    var role = client.GetGuild(110373943822540800).GetRole(110374777914417152);

            //    while (true)
            //    {
            //        foreach (var u in client.GetGuild(110373943822540800).Users.Where(x => x?.IsBot == true))
            //        {
            //            if (!u.Roles.Contains(role))
            //            {
            //                await u.AddRoleAsync(role);
            //            }
            //        }

            //        await Task.Delay(1000 * 60 * 30); // Wait 30 minutes
            //    }
            //});

            //await client.CurrentUser.ModifyAsync(x => x.Avatar = new Image(File.OpenRead("Minitori.png")));

            await Task.Delay(-1);
        }