Ejemplo n.º 1
0
        private void MainWindowClose(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ShutDown SD = new ShutDown();

            SD.Owner = this;
            if (SD.ShowDialog() == true)
            {
                //若沒有嚴謹確認NULL值,程式執行或結束時未使用的thread等會出現錯誤。

                /*  msg_reader
                 *  Do_Not_Disturb
                 *  IRCRoom
                 *  AutoPing
                 *  GC_T
                 */

                if (IRCRoom != null && IRCRoom.IsAlive)
                {
                    IRCRoom.Abort();
                    irc.close_irc();
                }
                if (Do_Not_Disturb != null && Do_Not_Disturb.IsAlive)
                {
                    Do_Not_Disturb.Abort();
                }
                if (AutoPing != null && AutoPing.IsAlive)
                {
                    AutoPing.Abort();
                }
                if (GC_T != null && GC_T.IsAlive)
                {
                    GC_T.Abort();
                }
                if (msg_reader != null && msg_reader.IsAlive)
                {
                    msg_reader.Abort();
                }
                if (TTS_T != null && TTS_T.IsAlive)
                {
                    TTS_T.Abort();
                }

                string path       = "Setting";
                string prisetting = "prisetting.txt";
                string nickname   = "nickname.txt";
                string education  = "education.txt";
                string react      = "ReAct.txt";
                string except     = "Except.txt";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                FileStream Fstream = null;

                Fstream = new FileStream(path + "/" + prisetting, FileMode.Truncate);  //清空txt文件
                if (Fstream != null)
                {
                    Fstream.Close();
                }

                Fstream = new FileStream(path + "/" + prisetting, FileMode.OpenOrCreate);

                StreamWriter FileWrite = new StreamWriter(Fstream);

                //========關閉確認後將使用者偏好之參數寫進檔案===========

                /*prisetting檔案內容
                 * PRISETTING
                 * Volume
                 * Rate
                 * Word_Limit
                 * DoNotTalkFunction
                 * AutoLogin
                 * SE Volume
                 * SE Cancel
                 */
                try
                {
                    //temp_writer = FileRead.ReadLine();

                    if (Fstream != null)   //如果個人設定檔案之內容已經存在
                    {
                        Fstream.Position = 0;

                        FileWrite.WriteLine("PRISETTING");
                        FileWrite.WriteLine(Speech_Volume);
                        FileWrite.WriteLine(Speech_Rate);
                        FileWrite.WriteLine(Speech_Word_Limit);

                        if (DoNotTalkFunction == true)  //DoNotTalkFunction
                        {
                            FileWrite.WriteLine("1");
                        }
                        else
                        {
                            FileWrite.WriteLine("0");
                        }

                        if (Auto_Login == true)         //Auto_Login
                        {
                            FileWrite.WriteLine("1");
                        }
                        else
                        {
                            FileWrite.WriteLine("0");
                        }

                        FileWrite.WriteLine(SE_Volume);

                        if (SE_Cancel_Func == true)
                        {
                            FileWrite.WriteLine("1");
                        }
                        else
                        {
                            FileWrite.WriteLine("0");
                        }

                        FileWrite.WriteLine(Speech_Pitch);

                        FileWrite.Flush();

                        //FileWrite.Close();
                        Fstream.Close();    //關閉檔案串流.
                    }
                }
                catch (Exception ex)
                {
                    Push_A_message_to_Room("Error:" + ex.Message + "\n");
                }
                //=======================================================


                //================= Nick Name ==========================
                Fstream = null;
                Fstream = new FileStream(path + "/" + nickname, FileMode.Truncate);  //清空txt文件
                if (Fstream != null)
                {
                    Fstream.Close();
                }
                Fstream   = new FileStream(path + "/" + nickname, FileMode.OpenOrCreate);
                FileWrite = new StreamWriter(Fstream);
                //FileWrite.AutoFlush = true;
                try
                {
                    if (Fstream != null)
                    {
                        Fstream.Position = 0;

                        FileWrite.WriteLine("NICKNAME");
                        if (NickNameList.Count > 0)
                        {
                            for (int i = 0; i < NickNameList.Count; i++)
                            {
                                FileWrite.WriteLine(NickNameList[i].GetTalker().Replace("\n", null));
                                FileWrite.WriteLine(NickNameList[i].Get_Talker_NK().Replace("\n", null));
                                FileWrite.Flush();
                            }
                        }
                    }
                    Fstream.Close();    //關閉檔案串流.
                }
                catch (Exception ex)
                {
                    Push_A_message_to_Room("Error:" + ex.Message + "\n");
                }
                //=========================================================


                //================= Education File ========================
                Fstream = null;
                Fstream = new FileStream(path + "/" + education, FileMode.Truncate);  //清空txt文件
                if (Fstream != null)
                {
                    Fstream.Close();
                }
                Fstream   = new FileStream(path + "/" + education, FileMode.OpenOrCreate);
                FileWrite = new StreamWriter(Fstream);
                //FileWrite.AutoFlush = true;
                try
                {
                    if (Fstream != null)
                    {
                        Fstream.Position = 0;

                        FileWrite.WriteLine("EDUCATION");
                        if (EducationList.Count > 0)
                        {
                            for (int i = 0; i < EducationList.Count; i++)
                            {
                                FileWrite.WriteLine(EducationList[i].GetWord().Replace("\n", null));
                                FileWrite.WriteLine(EducationList[i].Get_Word_ed().Replace("\n", null));
                                FileWrite.Flush();
                            }
                        }
                    }
                    Fstream.Close();    //關閉檔案串流.
                }
                catch (Exception ex)
                {
                    Push_A_message_to_Room("Error:" + ex.Message + "\n");
                }

                //=========================================================


                //===================ReAct File============================
                Fstream = null;
                Fstream = new FileStream(path + "/" + react, FileMode.Truncate);  //清空txt文件
                if (Fstream != null)
                {
                    Fstream.Close();
                }
                Fstream   = new FileStream(path + "/" + react, FileMode.OpenOrCreate);
                FileWrite = new StreamWriter(Fstream);
                //FileWrite.AutoFlush = true;
                try
                {
                    if (Fstream != null)
                    {
                        Fstream.Position = 0;

                        FileWrite.WriteLine("REACT");
                        if (ReActList.Count > 0)
                        {
                            for (int i = 0; i < ReActList.Count; i++)
                            {
                                FileWrite.WriteLine(ReActList[i].GetWord().Replace("\n", null));
                                FileWrite.WriteLine(ReActList[i].Get_word_ra().Replace("\n", null));
                                FileWrite.Flush();
                            }
                        }
                    }
                    Fstream.Close();    //關閉檔案串流.
                }
                catch (Exception ex)
                {
                    Push_A_message_to_Room("Error:" + ex.Message + "\n");
                }

                //=========================================================


                //================= Except File ========================
                Fstream = null;
                Fstream = new FileStream(path + "/" + except, FileMode.Truncate);  //清空txt文件
                if (Fstream != null)
                {
                    Fstream.Close();
                }
                Fstream   = new FileStream(path + "/" + except, FileMode.OpenOrCreate);
                FileWrite = new StreamWriter(Fstream);
                //FileWrite.AutoFlush = true;
                try
                {
                    if (Fstream != null)
                    {
                        Fstream.Position = 0;

                        FileWrite.WriteLine("EXCEPT");
                        if (ExceptList.Count > 0)
                        {
                            for (int i = 0; i < ExceptList.Count; i++)
                            {
                                FileWrite.WriteLine(ExceptList[i].GetName().Replace("\n", null));
                                FileWrite.Flush();
                            }
                        }
                    }
                    Fstream.Close();    //關閉檔案串流.
                }
                catch (Exception ex)
                {
                    Push_A_message_to_Room("Error:" + ex.Message + "\n");
                }

                //=========================================================

                Application.Current.Shutdown();
            }
            else
            {
                e.Cancel = true;
            }
        }
Ejemplo n.º 2
0
        private void Msg_Reader()
        {
            string msg;
            string talker = null;

            while (true)
            {
                try
                {
                    Thread.Sleep(3600000);
                }
                catch (ThreadInterruptedException)
                {
                    while (msg_queue.Count != 0)
                    {
                        msg    = msg_queue.Dequeue().ToString();
                        talker = Who_Talk(msg);
                        talker = talker.ToLower();

                        msg = Room_Content_Proccess(msg);   //回傳的msg已經處理成僅剩留言訊息,不包含talker

                        if (CommandSpeech)                  //如果以指令來說話之功能 啟用
                        {
                            msg = Speech_Msg_By_command(msg);
                        }
                        msg = Speech_Content_Proccess(msg); //處理多餘的符號

                        Msg_Command_Proc(talker, msg);

                        if (!msg.StartsWith("!") && !msg.StartsWith("/")) //如果不是指令
                        {
                            if (Except_Index(talker) == -1)               //如果不是Bot
                            {
                                int index = Nick_Name_Index(talker);      //判別該留言之人是否具有暱稱
                                if (index >= 0)                           //假如有暱稱
                                {
                                    string _NickName;
                                    _NickName = TransToNick(index);
                                    TTS_queue.Enqueue(_NickName);
                                    TTS_queue.Enqueue("說");
                                }

                                msg = Education_String_Replace(msg);
                                msg = Msg_WordsNumLimit(msg);
                                //====此時的msg已是替換過教育文字並被限制字數後的訊息====
                                msg = msg.Replace("\n", "");
                                if (!SE_pause)
                                {
                                    SE_pro(msg);    //使用recursive之方式
                                }
                                else
                                {
                                    TTS_queue.Enqueue(msg);
                                }
                                TTS_T.Interrupt();


                                //====自動回應====

                                Msg_ReAct(talker, msg);

                                if (msg.Contains("やっほー"))  //檢查棒讀醬反應
                                {
                                    if (talker != current_channel.ToLower())
                                    {
                                        Push_A_message_to_Room(current_channel + " : Ver 1.3.1 やっほー\n");
                                        irc.sendchatMessage("Ver 1.3.1 やっほー");
                                    }
                                }

                                //================
                            }
                        } //End_ else if(!msg.StartsWith("!"))
                    }     //End_ while(msg_queue.Count != 0)
                }         //End_ catch
            }
        }