コード例 #1
0
 private void PrintAlert(CountdownItem item, TimeSpan alerttime, CountdownState state = CountdownState.PreCountdown)
 {
     if (item == CountdownItem.Empty)
     {
         OnMessageEvent($"No badimes queued.  Currently Idle.");
     }
     if (state == CountdownState.PostCountdown)
     {
         OnMessageEvent($"{item.Title} elapsed time is {DateTime.Now - item.Epoch}");
     }
     else if (state == CountdownState.PreCountdown)
     {
         if (alerttime >= TimeSpan.FromSeconds(10))
         {
             OnMessageEvent($"{item.Title} in {alerttime}");
         }
         else if (alerttime == TimeSpan.FromSeconds(0))
         {
             OnMessageEvent($"{item.Title} starting!");
         }
         else
         {
             OnMessageEvent($"{alerttime.TotalSeconds}");
         }
     }
     else
     {
         OnMessageEvent($"{item.Title} starting!");
     }
     //OnMessageEvent($"{item.Title} in {alerttime}");
 }
コード例 #2
0
        public void Enqueue(string Anime, TimeSpan Countdown, TimeSpan Length)
        {
            CountdownItem item = new CountdownItem();

            item.Title        = Anime;
            item.Length       = Length;
            item.PreCountdown = Countdown;

            CountdownList.Enqueue(item);
        }
コード例 #3
0
        public static CountdownItem Parse(string message)
        {
            // add Anime Title for 25:00 in 15:00
            // add <title> for <length> in <countdown>
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"add\s(.*?)\sfor\s(.*?)\sin\s(.*)");
            if (r.IsMatch(message))
            {
                var m = r.Match(message);

                CountdownItem ci = new CountdownItem()
                {
                    Title        = m.Groups[1].Value,
                    Length       = ParseTime(m.Groups[2].Value),
                    PreCountdown = ParseTime(m.Groups[3].Value)
                };
                return(ci);
            }
            return(CountdownItem.Empty);
        }
コード例 #4
0
 public void Enqueue(CountdownItem item)
 {
     CountdownList.Enqueue(item);
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: hova0/badimebot
        static int Main(string[] args)
        {
            Console.WriteLine("Badime Bot v2.00");
            string server         = "127.0.0.1";
            string channel        = "#badimebottest";
            string AuthorizedNick = "hova";

            if (args.Length == 2)
            {
                server  = args[0];
                channel = args[1];
            }
            if (args.Length >= 3)
            {
                AuthorizedNick = args[2];
            }

            si = new BasicIrc();
            si.Connect(server, "badimebot");
            Console.WriteLine("Connected");
            si.Join(channel);
            Console.WriteLine($"Joined channel {channel}");
            CountdownTimer animetimer = new CountdownTimer();

            animetimer.MessageEvent += (x, y) =>
            {
                si.SendMessage(y.CountdownMessage);
            };

            si.ChannelMessageReceived += (x, y) =>
            {
                //Only respond to the !badime trigger
                if (IsValidBotCommand(y.Message, "badime"))
                {
                    si.SendMessage(string.Format("Time Elapsed {0}", animetimer.GetElapsedTime()));
                }
            };
            si.PrivateMessageReceived += (x, y) =>
            {
                if (IsValidBotCommand(y.Message, "badime"))
                {
                    si.PrivateMessage(y.From, string.Format("Time Elapsed {0}", animetimer.GetElapsedTime()));
                }
                if (y.From == "hova")
                {
                    if (y.Message == "shutdown")
                    {
                        PrintToConsoleWithColor("Shutdown request received, exiting program", ConsoleColor.Red);
                        si.Disconnect($"{y.From} told me to quit");
                        animetimer.Stop();
                        Environment.Exit(0);
                    }

                    if (y.Message.StartsWith("add"))
                    {
                        CountdownItem ci = CountdownTimer.Parse(y.Message);

                        if (ci != CountdownItem.Empty)
                        {
                            animetimer.Enqueue(ci);
                            si.PrivateMessage(y.From, $"Enqueued {ci.Title} for {ci.Length}");
                        }
                    }
                }
            };
            animetimer.Start();
            Console.WriteLine("Press Enter to quit...");
            Console.ReadLine();
            animetimer.Stop();
            si.Disconnect("Someone pressed enter on the console");
            return(0);
        }