예제 #1
0
파일: Update.cs 프로젝트: thebecwar/Hatman
        public void ProcessMessage(Message msg, ref Room rm)
        {
            if (au == null) { return; }

            rm.PostReplyFast(msg, "Updating, one sec...");

            if (!au.Update())
            {
                rm.PostReplyFast(msg, "I'm already up to date.");
            }
            else
            {
                rm.PostReplyFast(msg, "Update successful, starting new version...");

                au.StartNewVersion();

                Process.GetCurrentProcess().CloseMainWindow();
            }
        }
예제 #2
0
파일: Blame.cs 프로젝트: thebecwar/Hatman
        public void ProcessMessage(Message msg, ref Room rm)
        {
            var users = rm.GetCurrentUsers();
            var userX = users.PickRandom().GetChatFriendlyUsername();
            var userY = users.PickRandom().GetChatFriendlyUsername();
            while (userX == userY)
            {
                userY = users.PickRandom().GetChatFriendlyUsername();
            }
            var message = string.Format(phrases.PickRandom(), userX, userY);

            rm.PostReplyFast(msg, message);
        }
예제 #3
0
파일: When.cs 프로젝트: thebecwar/Hatman
        public void ProcessMessage(Message msg, ref Room rm)
        {
            var n = new byte[4];
            rng.GetBytes(n);
            var message = "";

            if (BitConverter.ToUInt32(n, 0) % 100 > 50)
            {
                // Pick any date within 10 years from now.
                var date = DateTime.UtcNow.Add(TimeSpan.FromDays(r.Next(-3652, 3652)));
                message = date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
            }
            else
            {
                message = phrases.PickRandom();
            }

            rm.PostReplyFast(msg, message);
        }
예제 #4
0
        private static bool HandleOwnerCommand(Room room, Message command)
        {
            var cmd = command.Content.Trim().ToUpperInvariant();

            if (cmd == "STOP")
            {
                shutdownMre.Set();
                return true;
            }
            if (cmd.StartsWith("SET THRESHOLD"))
            {
                var th = 0F;

                if (!float.TryParse(cmd.Remove(0, 14), out th))
                {
                    room.PostReplyFast(command, "Try using your hands to type a valid number between 0 and 1.");
                    return true;
                }

                if (th < 0 || th > 1)
                {
                    room.PostReplyFast(command, "Threshold must be between 0 and 1 (and *don't* include the % sign).");
                    return true;
                }

                cvClassifier.Threshold = th;
                qdvClassifier.Threshold = th;
                advClassifier.Threshold = th;

                room.PostReplyFast(command, "Threshold updated.");

                return true;
            }

            //case "UPDATE":
            //{
            //    UpdateBot(room, command);
            //    return true;
            //}

            return false;
        }
예제 #5
0
        private static bool HandleNormalUserCommand(Room room, Message command)
        {
            var cmd = command.Content.Trim().ToUpperInvariant();

            switch (cmd)
            {
                case "ALIVE":
                {
                    var statusReport = $"Yes, I'm alive (`{DateTime.UtcNow - startTime}`).";
                    room.PostMessageFast(statusReport);
                    return true;
                }
                case "COMMANDS":
                {
                    var msg = $"See [here]({wikiCmdsLink} \"Chat Commands Wiki\").";
                    room.PostReplyFast(command, msg);
                    return true;
                }
                case "THRESHOLD":
                {
                    var msg = $"My current threshold is: `{cvClassifier.Threshold * 100}`%.";
                    room.PostMessageFast(msg);
                    return true;
                }
                //case "VERSION":
                //{
                //    var msg = $"My current version is: `{updater.CurrentVersion}`.";
                //    room.PostReplyFast(command, msg);
                //    return true;
                //}
                default:
                {
                    return false;
                }
            }
        }
예제 #6
0
        private static void HandleChatCommand(Room room, Message command)
        {
            try
            {
                if (UserAccess.Owners.Any(id => id == command.Author.ID) ||
                    command.Author.IsRoomOwner || command.Author.IsMod)
                {
                    var cmdMatches = HandleOwnerCommand(room, command);

                    if (!cmdMatches)
                    {
                        cmdMatches = HandlePrivilegedUserCommand(room, command);

                        if (!cmdMatches)
                        {
                            HandleNormalUserCommand(room, command);
                        }
                    }
                }
                else if (command.Author.Reputation >= 3000)
                {
                    var cmdMatches = HandlePrivilegedUserCommand(room, command);

                    if (!cmdMatches)
                    {
                        HandleNormalUserCommand(room, command);
                    }
                }
                else
                {
                    HandleNormalUserCommand(room, command);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                room.PostReplyFast(command, $"`Unable to execute command: {ex.Message}`");
            }
        }
예제 #7
0
파일: Face.cs 프로젝트: thebecwar/Hatman
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, faces.PickRandom());
 }
예제 #8
0
파일: Comics.cs 프로젝트: thebecwar/Hatman
        public void ProcessMessage(Message msg, ref Room rm)
        {
            string response = "";

            string[] commandParts = msg.Content.ToLowerInvariant().Replace("comic", "").Trim().Split(' ');
            if (commandParts.Length == 0)
            {
                string selectedComic = this.knownComics.Values.PickRandom();
                response = this.GetComic(selectedComic);
            }
            else if (commandParts[0].ToLowerInvariant().Trim() == "add")
            {
                if (commandParts.Length < 3)
                {
                    response = "Not enough args";
                }
                else
                {
                    this.knownComics.Add(commandParts[1].Trim(), commandParts[2].Trim());
                    response = "Ok.";
                }
            }
            else if (commandParts[0].ToLowerInvariant().Trim() == "remove")
            {
                if (commandParts.Length < 2)
                {
                    response = "Not enough args";
                }
                else if (!this.knownComics.ContainsKey(commandParts[1].Trim()))
                {
                    response = "Not found.";
                }
                else
                {
                    this.knownComics.Remove(commandParts[1].Trim());
                    response = "Done.";
                }
            }
            else if (commandParts[0].ToLowerInvariant().Trim() == "list")
            {
                response = String.Join(", ", this.knownComics.Keys);
            }
            else
            {
                if (!this.knownComics.ContainsKey(commandParts[0]))
                {
                    response = "Unknown comic";
                }
                else
                {
                    response = this.GetComic(this.knownComics[commandParts[0]]);
                    if (response == null)
                    {
                        response = "Comic was unsupported, and has been terminated as such.";
                        this.knownComics.Remove(commandParts[0]);
                    }
                }
            }

            rm.PostReplyFast(msg, response);
        }
예제 #9
0
파일: Comics.cs 프로젝트: thebecwar/Hatman
        public void ProcessMessage(Message msg, ref Room rm)
        {
            if ((DateTime.UtcNow - lastFetch).TotalHours > 1)
            {
                var html = new WebClient().DownloadString("http://xkcd.com/");
                var strId = latestComicIdParser.Match(html).Value;

                if (!int.TryParse(strId, out latestComicId))
                {
                    latestComicId = 1599;
                }

                lastFetch = DateTime.UtcNow;
            }

            int comicNumber = Extensions.PickRandom(Enumerable.Range(1, latestComicId));
            if (commandParser.IsMatch(msg.Content))
            {
                try
                {
                    comicNumber = int.Parse(commandParser.Match(msg.Content).Value);
                }
                catch { /* Laziest way to do this ever. Why validate parameters when you can just do it. */ }
            }
            rm.PostReplyFast(msg, String.Format("http://www.xkcd.com/{0}/", comicNumber));
        }
예제 #10
0
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, "Baby don't hurt me.");
 }
예제 #11
0
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, "No more.");
 }
예제 #12
0
        private void PrintCommandListReply(Message m, Room r)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < router.Commands.Count; i++)
            {
                sb.AppendFormat("{0}. ({1}) {2}\n", i + 1, router.CommandStates[router.Commands[i]] ? "Enabled" : "Disabled", router.Commands[i].Usage);
            }
            r.PostReplyFast(m, sb.ToString());
        }