Пример #1
0
 private VoiceBot()
 {
     this.state = new BotState();
     // TRANSLATORS: Log message. Initializing Rein.
     Logger.Log(T._("- initialize Bouyomi-chan ..."));
     this.bouyomichan = new BouyomiChanClient();
     this.CheckBouyomichan();
     // TRANSLATORS: Log message. Initializing Rein.
     Logger.Log(T._("- initialize sound devices ..."));
     try {
         Rein.AudioConnector.NAudio.Initialize(Config.Instance.MainConfig);
     } catch (Exception e) {
         this.Dispose();
         // TRANSLATORS: Error message. Initializing Rein.
         throw new Exception(T._("Could not initialize sound devices. Please check virtual devices installed and valid name set."), e);
     }
     try {
         this.voice = new Rein.AudioConnector.NAudio(Config.Instance.MainConfig);
     } catch (Exception e) {
         this.Dispose();
         // TRANSLATORS: Error message. Initializing Rein.
         throw new Exception(T._("Could not initialize recording devices. Please check virtual devices installed and valid name set."), e);
     }
     // TRANSLATORS: Log message. Initializing Rein.
     Logger.Log(T._("- initialize Discord client ..."));
     this.discord = CreateDiscordClient();
     // TRANSLATORS: Log message. Initializing Rein.
     Logger.Log(T._("- initialize Timer ..."));
     this.timer = new Timer(this.TickHandler);
     // TRANSLATORS: Log message. Initializing Rein.
     Logger.Log(T._("- load plugins ..."));
     PluginManager.Instance.Load(this);
 }
Пример #2
0
 private void Disconnect()
 {
     try {
         // TRANSLATORS: Log message. Disconnect Rein.
         Logger.Log(T._("- stop Timer ..."));
         this.timer.Stop();
         // TRANSLATORS: Log message. Disconnect Rein.
         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 Rein.
         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 Rein.
                     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 Rein.
                 Logger.Log(T._("Could not stop Discord. Stop challange was timeouted."));
             }
         }
     } catch (Exception e) {
         // TRANSLATORS: Log message. Disconnect Rein.
         Logger.Log(T._("Could not disconnect."));
         Logger.DebugLog(e.ToString());
     }
 }