Ejemplo n.º 1
0
        private void Bot_Connected(object sender, OnConnectedArgs e)
        {
            string file = botPath + "Scheduled.txt";

            string[]   lines;
            string[][] scheduled = new string[101][];
            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                    lines = sr.ReadToEnd().Split(';');

                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].Length > 4)
                    {
                        scheduled[i]    = new string[4];
                        scheduled[i][0] = lines[i].Split(':')[0];
                        scheduled[i][1] = lines[i].Split(':')[1];
                        scheduled[i][2] = lines[i].Split(':')[2];
                        scheduled[i][3] = lines[i].Split(':')[3];
                    }
                }
                for (int j = 0; j < scheduled.GetLength(0); j++)
                {
                    if (scheduled[j] != null && scheduled[j].Length > 0)
                    {
                        int frequency;
                        int chance;
                        int.TryParse(scheduled[j][1], out frequency);
                        int.TryParse(scheduled[j][2], out chance);

                        TimedMessage.NewMessage(scheduled[j][0], scheduled[j][3], frequency, chance);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Message_Received(object sender, OnMessageReceivedArgs e)
        {
            string message  = e.ChatMessage.Message;
            string cmdsPath = botPath + "Commands.txt";
            string userPath = @"Users\" + user + @"\Data.txt";

            bool command = message.StartsWith("!");
            bool bc      = e.ChatMessage.IsBroadcaster;
            bool permit  = e.ChatMessage.IsBroadcaster || e.ChatMessage.IsModerator;

            if (command && (bc || UserPermit(userPath)))
            {
                string editCmd = "!edit";
                string delCmd  = "!delcmd";
                string taskMsg = "!task";
                string delTask = "!deltask";
                if (message.StartsWith(editCmd))
                {
                    int    startIndex = editCmd.Length + 1;
                    string substring  = message.Substring(startIndex);
                    int    length     = Math.Max(startIndex - substring.IndexOf(' '), substring.IndexOf(' ') - startIndex);
                    WriteToFile(cmdsPath, ';', message.Substring(startIndex, length), substring.Substring(length), false);
                }
                if (message.StartsWith(delCmd))
                {
                    int    startIndex = delCmd.Length + 1;
                    string substring  = message.Substring(startIndex);
                    int    length     = Math.Max(startIndex - substring.IndexOf(' '), substring.IndexOf(' ') - startIndex);
                    WriteToFile(cmdsPath, ';', message.Substring(startIndex, length), string.Empty, false);
                }
                if (message.StartsWith(taskMsg))
                {
                    string nameIndex = message.Substring(message.IndexOf('$') + 1);
                    string name      = nameIndex.Substring(0, nameIndex.IndexOf(' '));
                    string msg       = message.Substring(message.IndexOf('$') + name.Length + 2);
                    int    frequency;
                    int    chance;
                    int.TryParse(message.Substring(message.IndexOf('#') + 1, 2), out frequency);
                    int.TryParse(message.Substring(message.LastIndexOf('#') + 1, 1), out chance);

                    int taskID = TimedMessage.NewMessage(name, msg, frequency, chance);

                    string taskAlert = "@" + e.ChatMessage.Username + " Task ID: " + taskID + " created";
                    client.SendMessage(channel, taskAlert);
                }
                if (message.StartsWith(delTask))
                {
                    string ID = message.Substring(delTask.Length + 1);
                    int    id;
                    int.TryParse(ID, out id);
                    foreach (TimedMessage task in TimedMsgs)
                    {
                        if (task != null && (task.name == ID || task.ID == id))
                        {
                            task.Dispose();
                            break;
                        }
                    }
                }
            }
            if (command && FileCheck(cmdsPath, ';', message))
            {
                client.SendMessage(channel, MessageOutput(cmdsPath, ';', message));
            }
        }