public Bot(IOptionsMonitor <BotConfiguration> options, IHubContext <MonitorHub> hubContext) { this.gameStateManager = new GameStateManager(); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.dbActionFactory = new SqliteDatabaseActionFactory(this.options.CurrentValue.DatabaseDataSource); this.readerRejoinedMap = new Dictionary <IGuildUser, bool>(); DiscordSocketConfig clientConfig = new DiscordSocketConfig() { // May not be needed MessageCacheSize = 1024 * 16 }; this.client = new DiscordSocketClient(clientConfig); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this.client); serviceCollection.AddSingleton(this.gameStateManager); serviceCollection.AddSingleton(this.options); serviceCollection.AddSingleton(this.dbActionFactory); serviceCollection.AddSingleton <IFileScoresheetGenerator>(new ExcelFileScoresheetGenerator()); IGoogleSheetsApi googleSheetsApi = new GoogleSheetsApi(this.options); serviceCollection.AddSingleton <IGoogleSheetsGeneratorFactory>( new GoogleSheetsGeneratorFactory(googleSheetsApi)); this.serviceProvider = serviceCollection.BuildServiceProvider(); this.commandService = new CommandService(new CommandServiceConfig() { CaseSensitiveCommands = false, LogLevel = LogSeverity.Info, DefaultRunMode = RunMode.Async, }); this.commandService.Log += this.OnLogAsync; this.logger = Log.ForContext(this.GetType()); this.discordNetEventLogger = new DiscordNetEventLogger(this.client, this.commandService); Task.WaitAll(this.commandService.AddModulesAsync(Assembly.GetExecutingAssembly(), this.serviceProvider)); this.messageHandler = new MessageHandler( this.options, this.dbActionFactory, hubContext, this.logger); this.client.MessageReceived += this.OnMessageCreated; this.client.GuildMemberUpdated += this.OnPresenceUpdated; this.client.JoinedGuild += this.OnGuildJoined; this.configurationChangeCallback = this.options.OnChange((configuration, value) => { this.logger.Information("Configuration has been reloaded"); }); }
private static async Task Main(string[] args) { const string serviceAcctEmail = "*****@*****.**"; const string configFile = "tempo-265222-88dada7b17c3.json"; const string appName = "TempoApi"; const string spreadsheetTitle = "Important exported info"; const string sheetTitle = "You precious data"; var credential = GoogleCredentialManager.CreateGoogleCredential(serviceAcctEmail, configFile); var sheetsApi = new GoogleSheetsApi(appName, credential); var createResponse = await sheetsApi.CreateAsync(spreadsheetTitle, sheetTitle); Console.WriteLine("Create sheet response"); Console.WriteLine(JsonConvert.SerializeObject(createResponse)); var headers = GetHeaders(); var data = GetData(); var batchUpdateValuesResponse = await sheetsApi.BatchUpdateAsync(createResponse.SpreadsheetId, sheetTitle, headers, data); Console.WriteLine("Batch update sheet response"); Console.WriteLine(JsonConvert.SerializeObject(batchUpdateValuesResponse)); var driveApi = new GoogleDriveApi(appName, credential); var fileList = await driveApi.ListFilesAsync(); Console.WriteLine("File list:"); Console.WriteLine(JsonConvert.SerializeObject(fileList)); var permission = await driveApi.ShareAsync(createResponse.SpreadsheetId, "*****@*****.**"); // permission = await driveApi.ShareAsync(createResponse.SpreadsheetId, "*****@*****.**"); // permission = await driveApi.ShareAsync(createResponse.SpreadsheetId, "*****@*****.**"); // await DeleteAllExceptAsync(fileList, createResponse.SpreadsheetId, driveApi); Console.ReadKey(); }