private async Task Client_Ready() { AddonLoader.Load(Client); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); List <Type> commandClasses = new List <Type>(); foreach (Assembly assembly in assemblies) { commandClasses.AddRange(assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ModuleBase)) && !t.IsAbstract).ToList()); } checkNewUserEntries(); StatusNotifierService.InitializeService(Me); MusicCommands.Initialize(Client); RoleManagerService.InitializeHandler(Client, BotConfiguration); ApiRequestService.Initialize(BotConfiguration); UserManagerService.InitializeHandler(Client); await CommandHandlerService.InitializeHandler(Client, BotConfiguration, commandClasses, prefixDictionary, !CredentialManager.OptionalSettings.Contains("CleverApi")); CacheService.InitializeHandler(); VoiceRewardService.InitializeHandler(Client, BotConfiguration, !CredentialManager.OptionalSettings.Contains("CleverApi")); switch (startValue) { case 0: //shutdown break; case 1: //restarting await Me.SendMessageAsync("I have restored and restarted successfully."); break; case 2: //updating //check if an update is nessasarry await Me.SendMessageAsync("I at all the new features and restarted successfully."); break; default: break; } if (!CredentialManager.OptionalSettings.Contains("WeatherApiKey")) { if (!CredentialManager.OptionalSettings.Contains("WeatherPlace")) { MoodDictionary.InitializeMoodDictionary(Client, BotConfiguration); await MoodHandlerService.InitializeHandler(Client, BotConfiguration); } WeatherSubscriptionService.InitializeWeatherSub(Client, BotConfiguration); } }
private static async Task voiceChannelLeft(SocketUser disUser, SocketVoiceState voiceStateOld, SocketVoiceState voiceStateNew) { if (voiceStateNew.VoiceChannel != null || voiceStateOld.VoiceChannel?.Id == voiceStateNew.VoiceChannel?.Id || disUser.IsBot) { return; } User currentUser = DatabaseAccess.Instance.Users.Find(u => u.Id == disUser.Id); GuildUser guildUser = currentUser.GuildSpecificUser[voiceStateOld.VoiceChannel.Guild.Id]; if ((!currentUser.HasMuted && (DateTime.Now - currentUser.LastFarewell).TotalHours > 12) && hasCleverbotApiKey) { //send private message await disUser.SendMessageAsync(MoodDictionary.getMoodMessage("Bye"));//Bye currentUser.LastFarewell = DateTime.Now; } stopTrackingVoiceChannel(guildUser); }
private static async Task voiceChannelJoined(SocketUser disUser, SocketVoiceState voiceStateOld, SocketVoiceState voiceStateNew) { //if guild joined if (voiceStateOld.VoiceChannel?.Id == voiceStateNew.VoiceChannel?.Id || voiceStateNew.VoiceChannel == null || disUser.IsBot) { return; } User currentUser = DatabaseAccess.Instance.Users.Find(u => u.Id == disUser.Id); GuildUser guildUser = currentUser.GuildSpecificUser[voiceStateNew.VoiceChannel.Guild.Id]; if ((!currentUser.HasMuted && (DateTime.Now - currentUser.LastGreeting).TotalHours > 12) && hasCleverbotApiKey) { //send private message await disUser.SendMessageAsync(String.Format(MoodDictionary.getMoodMessage("Hello"), disUser.Username));//Hello currentUser.LastGreeting = DateTime.Now; } StartTrackingVoiceChannel(guildUser); }
private async Task Client_Ready() { IServiceProvider services = new ServiceCollection() .AddSingleton(Client) .AddSingleton <CleverbotApiHandler>() .AddSingleton <ColornamesApiHandler>() .AddSingleton <KonachanApiHandler>() .AddSingleton <WeatherApiHandler>() .AddSingleton <WikipediaApiHandler>() .AddSingleton(CredentialManager) .BuildServiceProvider(); AddonLoader.Load(Client); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); List <Type> commandClasses = new List <Type>(); foreach (Assembly assembly in assemblies) { commandClasses.AddRange(assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ModuleBase)) && !t.IsAbstract).ToList()); } VoiceRewardService.InitializeHandler(Client, BotConfiguration, !CredentialManager.OptionalSettings.Contains("CleverApi")); checkNewUserEntries(); StatusNotifierService.InitializeService(Me); MusicCommands.Initialize(Client); RoleManagerService.InitializeHandler(Client, BotConfiguration); UserManagerService.InitializeHandler(Client, fileLogger); await CommandHandlerService.InitializeHandler(Client, BotConfiguration, commandClasses, prefixDictionary, !CredentialManager.OptionalSettings.Contains("CleverApi"), fileLogger, services); CacheService.InitializeHandler(); switch (startValue) { case 0: //shutdown break; case 1: //restarting await Me.SendMessageAsync("I have restored and restarted successfully."); break; case 2: //updating //check if an update is nessasarry await Me.SendMessageAsync("I at all the new features and restarted successfully."); break; default: break; } if (!CredentialManager.OptionalSettings.Contains("WeatherApiKey")) { if (!CredentialManager.OptionalSettings.Contains("WeatherPlace")) { MoodDictionary.InitializeMoodDictionary(Client, BotConfiguration); await MoodHandlerService.InitializeHandler(Client, BotConfiguration, services.GetRequiredService <WeatherApiHandler>(), fileLogger); } WeatherSubscriptionService.InitializeWeatherSub(Client, BotConfiguration, services.GetRequiredService <WeatherApiHandler>()); } consoleLogger.Info($"Addons loaded: {AddonLoader.LoadedAddonsCount}"); consoleLogger.Info($"User loaded: {DatabaseAccess.Instance.Users.Count}"); consoleLogger.Info($"Registered guilds: {Client.Guilds.Count}"); consoleLogger.Info($"Bot start up time: {(DateTime.Now - startTime).TotalSeconds} s"); }