Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 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}`");
            }
        }
Ejemplo n.º 7
0
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, faces.PickRandom());
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, "Baby don't hurt me.");
 }
Ejemplo n.º 11
0
 public void ProcessMessage(Message msg, ref Room rm)
 {
     rm.PostReplyFast(msg, "No more.");
 }
Ejemplo n.º 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());
        }