Exemplo n.º 1
0
        private void LogChatHistory(Bot bot, MessageEventsArgs e)
        {
            string        key       = String.Concat(bot.Account.Settings.Username, bot.Account.Settings.Server);
            List <string> chatLines = e.Message.Split('\n').Select(x => x.Trim()).ToList();

            if (!ChatLogs.Keys.Any(x => x == key))
            {
                ChatLogs.Add(key, new HashSet <string>());
            }

            if (ChatLogs[key] == null)
            {
                ChatLogs[key] = new HashSet <string>();
            }

            List <string> newChatLines = chatLines.Where(x => !x.Contains(ChatLogs[key].ToList())).ToList();

            for (int i = chatLines.Count() - 1; i >= 0; i--)
            {
                ChatLogs[key].Add(chatLines[i]);
            }

            if (newChatLines.Count() > 0)
            {
                if (!System.IO.Directory.Exists("Logs"))
                {
                    System.IO.Directory.CreateDirectory("Logs");
                }

                CultureInfo culture = new CultureInfo("de-DE");

                System.IO.StreamWriter writer = new System.IO.StreamWriter(String.Concat("Logs/", bot.Account.Settings.Server, "-", bot.Account.Settings.Username, "-chatlog-", DateTime.Now.ToString(culture).Remove(DateTime.Now.ToString(culture).Length - 9), ".log"), true);
                for (int i = newChatLines.Count() - 1; i >= 0; i--)
                {
                    writer.WriteLine(newChatLines[i]);
                }

                writer.Close();
                writer.Dispose();
            }

            while (ChatLogs[key].Count > 20)
            {
                ChatLogs[key].Remove(ChatLogs[key].First());
            }

            WriteChatLogToConsole(SelectedBotKey);
        }
Exemplo n.º 2
0
        static void bot_ExtendedLog(object sender, MessageEventsArgs e)
        {
            Bot tmp = (Bot)sender;

            if (!System.IO.Directory.Exists("Logs"))
            {
                System.IO.Directory.CreateDirectory("Logs");
            }

            CultureInfo culture = new CultureInfo("de-DE");

            System.IO.StreamWriter writer = new System.IO.StreamWriter(String.Concat("Logs/", tmp.Account.Settings.Server, "-", tmp.Account.Settings.Username, "-extlog-", DateTime.Now.ToString(culture).Remove(DateTime.Now.ToString(culture).Length - 9), ".log"), true);
            writer.WriteLine(DateTime.Now.ToString() + ": " + e.Message);

            writer.Close();
            writer.Dispose();
        }