public async Task StartAsync(Func <string, string> tokenInput) { var token = tokenInput(GeneralGlobalSettings.Token) ?? GeneralGlobalSettings.Token; GlobalSettings.Edit <GeneralGlobalSetting>(s => { if (!string.IsNullOrWhiteSpace(token)) { s.Token = token; } }); if (DiscordClient.LoginState != LoginState.LoggedOut) { return; } try { await DiscordClient.LoginAsync(TokenType.Bot, GeneralGlobalSettings.Token); } catch (HttpException ex) { if (ex.HttpCode == HttpStatusCode.Unauthorized) { GlobalSettings.Edit <GeneralGlobalSetting>(s => s.Token = null); } throw; } await DiscordClient.StartAsync(); readyEvent.WaitOne(); readyEvent.Reset(); Scheduler.Enabled = true; }
Task LogoutAsync() { GlobalSettings.Edit <GeneralGlobalSetting>(s => s.Token = null); Bot.StopAsync().DontWait(); return(Task.CompletedTask); }