private void checkNewUserEntries() { List <SocketGuild> guilds = Client.Guilds.ToList(); foreach (SocketGuild guild in guilds) { List <SocketGuildUser> guildUsers = guild.Users.ToList(); foreach (SocketGuildUser guildUser in guildUsers) { if (guildUser.Id == BotConfiguration.meId) { Me = guildUser as SocketUser; } //check if user exist in global instance User myUser = DatabaseAccess.Instance.Users.Find(u => u.Id == guildUser.Id); if (myUser == null) { DatabaseAccess.Instance.InsertUser(new User(guildUser.Id, true)); } myUser = DatabaseAccess.Instance.Users.Find(u => u.Id == guildUser.Id); //check if guilduser exist in guild instance if (!myUser.GuildSpecificUser.ContainsKey(guild.Id)) { DatabaseAccess.Instance.InsertGuildUser(guild.Id, new GuildUser(guildUser.Id, guild.Id, 500)); } //check if user is already in a voice channel if (guildUser.VoiceChannel != null) { //start tracking if user detected VoiceRewardService.StartTrackingVoiceChannel(myUser.GuildSpecificUser[guild.Id]); } } } }
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 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"); }