Exemple #1
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);
        }
Exemple #2
0
        private async Task RunAsync()
        {
            socketClient = new DiscordSocketClient(new DiscordSocketConfig
            {
                //WebSocketProvider = WS4NetProvider.Instance,
                LogLevel = LogSeverity.Verbose
            });
            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();
            events = EventStorage.Load();

            var map = new ServiceCollection().AddSingleton(socketClient).AddSingleton(config).AddSingleton(events).BuildServiceProvider();

            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()}`");
                }
            }

            eqService = new EmergencyQuestService();
            await eqService.Install(map);

            map = new ServiceCollection().AddSingleton(socketClient).AddSingleton(config).AddSingleton(events).AddSingleton(eqService).BuildServiceProvider();

            socketClient.Disconnected   += SocketClient_Disconnected;
            socketClient.GuildAvailable += Client_GuildAvailable;

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

            //await Task.Delay(3000);

            //var avatar = new Image(File.OpenRead(".\\TaranzaSOUL.png"));
            //await client.CurrentUser.ModifyAsync(x => x.Avatar = avatar);

            await Task.Delay(-1);
        }