Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 Task LogoutAsync()
 {
     GlobalSettings.Edit <GeneralGlobalSetting>(s => s.Token = null);
     Bot.StopAsync().DontWait();
     return(Task.CompletedTask);
 }