private async Task ConnectedAsync() { _didStart = true; StaticObjects.ClientId = StaticObjects.Client.CurrentUser.Id; await StaticObjects.Client.SetGameAsync("https://sanara.zirk.eu Sanara V3 is out!", null, ActivityType.CustomStatus); await StaticObjects.UpdateTopGgAsync(); StaticObjects.Website?.KeepSendStats(); }
public async Task StartAsync() { // Setting Logs callback StaticObjects.Client.Log += Utils.Log; _commands.Log += Log.ErrorAsync; await Utils.Log(new LogMessage(LogSeverity.Info, "Setup", "Initialising bot")); // Load credentials if (!File.Exists("Keys/Credentials.json")) { throw new FileNotFoundException("Missing Credentials file"); } var _credentials = JsonConvert.DeserializeObject <Credentials>(File.ReadAllText("Keys/Credentials.json")); // Create saves directories if (!Directory.Exists("Saves")) { Directory.CreateDirectory("Saves"); } if (!Directory.Exists("Saves/Radio")) { Directory.CreateDirectory("Saves/Radio"); } if (!Directory.Exists("Saves/Download")) { Directory.CreateDirectory("Saves/Download"); } if (!Directory.Exists("Saves/Game")) { Directory.CreateDirectory("Saves/Game"); } // Set culture to invarriant (so we don't use , instead of . for decimal separator) CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; // Initialize services await StaticObjects.InitializeAsync(_credentials); // If the bot takes way too much time to start, we stop the program // We do that after the StaticObjects initialization because the first time we load game cache, it can takes plenty of time _ = Task.Run(async() => { await Task.Delay(Constants.PROGRAM_TIMEOUT); if (!_didStart) { Environment.Exit(1); } }); // Discord callbacks StaticObjects.Client.MessageReceived += HandleCommandAsync; StaticObjects.Client.Connected += ConnectedAsync; StaticObjects.Client.ReactionAdded += ReactionManager.ReactionAddedAsync; StaticObjects.Client.ReactionAdded += Log.ReactionAddedAsync; StaticObjects.Client.GuildAvailable += GuildJoined; StaticObjects.Client.JoinedGuild += GuildJoined; StaticObjects.Client.JoinedGuild += ChangeGuildCountAsync; StaticObjects.Client.LeftGuild += ChangeGuildCountAsync; StaticObjects.Client.Disconnected += Disconnected; _commands.CommandExecuted += CommandExecuted; // Add readers _commands.AddTypeReader(typeof(IMessage), new TypeReader.IMessageReader()); _commands.AddTypeReader(typeof(ImageLink), new TypeReader.ImageLinkReader()); // Discord modules await _commands.AddModuleAsync <Module.Administration.InformationModule>(null); await _commands.AddModuleAsync <Module.Administration.SettingModule>(null); await _commands.AddModuleAsync <Module.Community.CommunityModule>(null); await _commands.AddModuleAsync <Module.Entertainment.FunModule>(null); await _commands.AddModuleAsync <Module.Entertainment.JapaneseModule>(null); await _commands.AddModuleAsync <Module.Entertainment.MediaModule>(null); await _commands.AddModuleAsync <Module.Game.GameModule>(null); await _commands.AddModuleAsync <Module.Nsfw.BooruModule>(null); await _commands.AddModuleAsync <Module.Nsfw.DoujinshiModule>(null); await _commands.AddModuleAsync <Module.Nsfw.CosplayModule>(null); await _commands.AddModuleAsync <Module.Radio.RadioModule>(null); await _commands.AddModuleAsync <Module.Tool.CommunicationModule>(null); await _commands.AddModuleAsync <Module.Tool.LanguageModule>(null); await _commands.AddModuleAsync <Module.Tool.ScienceModule>(null); await StaticObjects.Client.LoginAsync(TokenType.Bot, _credentials.BotToken); await StaticObjects.Client.StartAsync(); // We keep the bot online await Task.Delay(-1); }
private async Task ChangeGuildCountAsync(SocketGuild _) { await StaticObjects.UpdateTopGgAsync(); }