public async Task RunAsync() { isDev = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WAZEBOT_ISDEV")); var token = Environment.GetEnvironmentVariable("DISCORD_API_TOKEN"); if (token == null) { throw new ArgumentNullException(nameof(token), "No Discord API token env var found"); } VerifyEnvironmentVariables(); var clientConfig = new DiscordSocketConfig { LogLevel = isDev ? LogSeverity.Info : LogSeverity.Warning, AlwaysDownloadUsers = true }; client = new DiscordSocketClient(clientConfig); client.Log += Log; var commandsConfig = new CommandServiceConfig { CaseSensitiveCommands = false }; commands = new CommandService(commandsConfig); httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("WazeBotDiscord/1.0"); var autoreplyService = new AutoreplyService(); await autoreplyService.InitAutoreplyServiceAsync(); var keywordService = new KeywordService(); await keywordService.InitKeywordServiceAsync(); var glossaryService = new GlossaryService(httpClient); await glossaryService.InitAsync(); var lookupService = new LookupService(httpClient); await lookupService.InitAsync(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(commands); serviceCollection.AddSingleton(autoreplyService); serviceCollection.AddSingleton(keywordService); serviceCollection.AddSingleton(lookupService); serviceCollection.AddSingleton(glossaryService); serviceCollection.AddSingleton(httpClient); client.Ready += async() => await client.SetGameAsync("with junction boxes"); var twitterService = new TwitterService(client); serviceCollection.AddSingleton(twitterService); client.Connected += async() => await twitterService.InitTwitterServiceAsync(); client.Disconnected += (ex) => { twitterService.StopAllStreams(); return(Task.CompletedTask); }; services = serviceCollection.BuildServiceProvider(); client.MessageReceived += async(SocketMessage msg) => await AutoreplyHandler.HandleAutoreplyAsync(msg, autoreplyService); client.MessageReceived += async(SocketMessage msg) => await KeywordHandler.HandleKeywordAsync(msg, keywordService, client); client.UserJoined += async(SocketGuildUser user) => await UserJoinedRoleSyncEvent.SyncRoles(user, client); await InstallCommands(); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); await Task.Delay(-1); }
public RemoveAutoreplyModule(AutoreplyService arService) { _arService = arService; }
public AddAutoreplyModule(AutoreplyService arService, CommandService cmdSvc) { _arService = arService; _cmdSvc = cmdSvc; }
public BaseAutoreplyModule(AutoreplyService arService) { _arService = arService; }