예제 #1
0
 private void Disconnect()
 {
     try {
         // TRANSLATORS: Log message. Disconnect Nursery.
         Logger.Log(T._("- disconnect from Voice channel ..."));
         if (this.voice != null)
         {
             this.voice.Disconnect().Wait();
             this.voice.Dispose();
             this.voice = null;
         }
         // TRANSLATORS: Log message. Disconnect Nursery.
         Logger.Log(T._("- disconnect from discord ..."));
         if (this.discord != null)
         {
             var t = Task.Run(async() => {
                 await instance.discord.SetGameAsync("");
                 await this.discord.StopAsync();
                 await this.discord.LogoutAsync();
             });
             var timeout = 0;
             while (true)
             {
                 if (this.discord.ConnectionState == ConnectionState.Disconnected && this.discord.LoginState == LoginState.LoggedOut)
                 {
                     // TRANSLATORS: Log message. Disconnect Nursery.
                     Logger.Log(T._("- Disconnected and Logged out!"));
                     break;
                 }
                 if (timeout > 300)
                 {
                     timeout = -1;
                     break;
                 }
                 timeout++;
                 Task.Delay(100).Wait();
             }
             if (timeout < 0)
             {
                 // TRANSLATORS: Log message. Disconnect Nursery.
                 Logger.Log(T._("Could not stop Discord. Stop challange was timeouted."));
             }
         }
     } catch (Exception e) {
         // TRANSLATORS: Log message. Disconnect Nursery.
         Logger.Log(T._("Could not disconnect."));
         Logger.DebugLog(e.ToString());
     }
 }
예제 #2
0
 private VoiceBot()
 {
     this.state = new BotState();
     // TRANSLATORS: Log message. Initializing Nursery.
     Logger.Log(T._("- initialize Bouyomi-chan ..."));
     this.bouyomichan = new BouyomiChanClient();
     try {
         this.bouyomichan.ClearTalkTasks();
     } catch (Exception e) {
         this.Dispose();
         // TRANSLATORS: Error message. Initializing Nursery.
         throw new Exception(T._("Could not load Bouyomi-chan. Please check Bouyomi-chan awaking."), e);
     }
     // TRANSLATORS: Log message. Initializing Nursery.
     Logger.Log(T._("- initialize sound devices ..."));
     try {
         BassWrapper.Initialize(Config.Instance.MainConfig);
     } catch (Exception e) {
         this.Dispose();
         // TRANSLATORS: Error message. Initializing Nursery.
         throw new Exception(T._("Could not initialize sound devices. Please check virtual devices installed and valid name set."), e);
     }
     try {
         this.voice = new VoiceChat(Config.Instance.MainConfig);
     } catch (Exception e) {
         this.Dispose();
         // TRANSLATORS: Error message. Initializing Nursery.
         throw new Exception(T._("Could not initialize recording devices. Please check virtual devices installed and valid name set."), e);
     }
     // TRANSLATORS: Log message. Initializing Nursery.
     Logger.Log(T._("- initialize Discord client ..."));
     this.discord = new DiscordSocketClient();
     // TRANSLATORS: Log message. Initializing Nursery.
     Logger.Log(T._("- load plugins ..."));
     PluginManager.Instance.Load(this);
 }