예제 #1
0
        /// <summary>
        /// Handles a chat event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        void ChatEvent(BotEngine sender, EventChatArgs e)
        {
            var query  = from AvatarStatus p in _statusList where p.Avatar.Citizen == e.Avatar.Citizen select p;
            var status = query.Single();

            status.LastSeen = DateTime.Now;
            var cmd = new CommandLine(e.Message); /* use a simple command line interpreter */

            switch (cmd.Command.ToLower())
            {
            case "!seen":
                if (cmd.Arguments.Count == 0)
                {
                    sender.Whisper(e.Avatar, "Invalid, usage is in the form of !seen <citizen name>.");
                }
                else
                {
                    var avatar = from AvatarStatus p in _statusList
                                 where p.Avatar.Name.ToLower() == cmd.Arguments[0].Value.Value.ToLower() select p;
                    if (avatar.Count() == 1)
                    {
                        sender.Whisper(e.Avatar, string.Format("Citizen {0} is here.", cmd.Arguments[0].Value.Value));
                        return;
                    }
                    var offline = from AvatarStatus p in _db where p.Avatar.Name.ToLower() == cmd.Arguments[0].Value.Value.ToLower() select p;
                    if (offline.Count() == 0)
                    {
                        sender.Whisper(e.Avatar, string.Format("Citizen {0} was never seen by me.", cmd.Arguments[0].Value.Value));
                        return;
                    }
                    var seen = offline.Single();
                    sender.Whisper(e.Avatar, string.Format("Citizen {0} was last seen on {1} at {2}", cmd.Arguments[0].Value.Value, seen.LastSeen.ToLongDateString(), seen.LastSeen.ToLongTimeString()));
                    return;
                }
                break;

            case "!idle":
                var message = string.Empty;
                foreach (var avatar in _statusList)
                {
                    if (avatar.IsIdle)
                    {
                        message += " " + avatar.Avatar.Name;
                    }
                }
                if (message == string.Empty)
                {
                    sender.Whisper(e.Avatar, "No one is idle.");
                }
                else
                {
                    sender.Whisper(e.Avatar, "Idle citizens:" + message);
                }
                break;
            }
        }
예제 #2
0
        void ChatMode_ChatEvent(BotEngine sender, EventChatArgs e)
        {
            switch (e.ChatType)
            {
            case ChatType.Whisper:
                ConsoleHelpers.WriteLine(ConsoleColor.DarkYellow, string.Format("[{0} whispers>: {1}", e.Avatar.Name, e.Message));
                break;

            case ChatType.Normal:
                ConsoleHelpers.WriteLine(ConsoleColor.Gray, string.Format("[{0}>: {1}", e.Avatar.Name, e.Message));
                break;
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the incoming chat event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void ChatEvent(BotEngine sender, EventChatArgs e)
        {
            switch (e.ChatType)
            {
            case ChatType.Normal:
            case ChatType.Broadcast:
                var setting =
                    (from AvatarColorChatSetting p in _settings where (p.Citizen == e.Avatar.Citizen) select p).
                    Single();
                var name = e.Avatar.Name + ":".PadRight(31 - e.Avatar.Name.Length);
                Bot.ConsoleMessage(e.Avatar.Name, setting.Color, setting.IsBold, setting.IsItalic, e.Message);
                break;

            case ChatType.Whisper:
                var cmd = new CommandLine(e.Message.ToLower());     /* use a simple command line interpreter */
                switch (cmd.Command)
                {
                case "!ccbot":
                    if (cmd.Arguments.Count != 1)
                    {
                        sender.Whisper(e.Avatar,
                                       "Use in the form of: !ccbot <#color> where #color is in the form of a HTML color. I.e: #000000 (black) #FF0000 red etc. You can also use known color names, such as Red, Blue, DarkViolet etc.");
                    }
                    else
                    {
                        var currentColor = (from AvatarColorChatSetting p in _settings
                                            where (p.Citizen == e.Avatar.Citizen)
                                            select p).Single();
                        try
                        {
                            currentColor.Color = ColorTranslator.FromHtml(cmd.Arguments[0].Value.Value.ToLower());
                            var dbColor = (from AvatarColorChatSetting p in sender.Storage.Db where (p.Citizen == e.Avatar.Citizen)
                                           select p).Single();
                            dbColor.Color = currentColor.Color;         /* todo: this object reference pattern should be genericly embedded within BotEngine */
                            sender.Storage.Db.Store(dbColor);
                            sender.Storage.Db.Commit();
                            Bot.Whisper(e.Avatar, string.Format("Your chat color has been changed to '{0}' brightness {1}", cmd.Arguments[0].Value.Value, dbColor.Color.GetBrightness()));
                        }
                        catch
                        {
                            Bot.Whisper(e.Avatar, string.Format("The chat color '{0}'is not recognized. Please try another color.", cmd.Arguments[0].Value.Value));
                        }
                    }

                    break;
                }

                break;
            }
        }
예제 #4
0
        void ChatEvent(BotEngine sender, EventChatArgs e)
        {
            var cmd = new CommandLine(e.Message); /* use a simple command line interpreter */

            if (string.IsNullOrEmpty(cmd.Command) || cmd.Command != "!awm" || cmd.Arguments.Count == 0)
            {
                return;
            }

            switch (cmd.Arguments[0].Value.Value)
            {
            case "version":
                sender.ConsoleMessage(Color.Black, true, false, string.Format("Managed Bot Engine Server {0}", sender.Version()));
                break;
            }
        }
예제 #5
0
        void ChatEvent(BotEngine sender, EventChatArgs e)
        {
            var cmd = new CommandLine(e.Message); /* use a simple command line interpreter */

            if (string.IsNullOrEmpty(cmd.Command) || cmd.Command != "!wbot")
            {
                return;
            }

            switch (cmd.Arguments[0].Value.Value)
            {
            case "cities":
                var    svc    = new GlobalWeatherService.GlobalWeather();
                string cities = svc.GetCitiesByCountry(cmd.Arguments[1].Value.Value);
                sender.Whisper(e.Avatar, cities);
                break;
            }
        }