示例#1
0
文件: AI.cs 项目: JonHaywood/Oberon
        private void AICommand(CommandPacket packet, PluginContext context)
        {
            if (string.IsNullOrEmpty(packet.Message))
            {
                context.ThisRoom.Respond("Usage: ai [on|off|status]");
                return;
            }

            string cmd = packet.Message.ToLower().Trim();
            switch (cmd)
            {
                case "on":
                case "off":
                    enabled = cmd == "on" ? true : false;
                    context.ThisRoom.Say("** AI respond set to '{0}' by {1} *", cmd, packet.From);
                    if (enabled)
                        sessionTimer.Start();
                    else
                        sessionTimer.Stop();
                    break;
                case "status":
                    string status = enabled ? "on" : "off";
                    context.ThisRoom.Say("** AI respond set to '{0}' *", status);
                    break;
            }
        }
示例#2
0
        private void Command(CommandPacket packet, PluginContext context)
        {
            var sender = context.ChatRooms[packet.ChatRoom].GetMember(packet.From);
            var commands = context.Authorizer.AllCommands.Where(c => c.Value.Order <= sender.Role.Order).OrderBy(c => c.Key);
            if (commands.Count() > 0)
            {
                var commandsOutput = new StringBuilder(string.Format("<abbr title='{0}'> </abbr><b>Bot Commands:</b><br><sub>", packet.From));
                foreach (var command in commands)
                {
                    var commandData = context.Plugins.GetCommandHandler(command.Key);
                    // command data may be null if we have a command with a setting
                    // but that command isn't loaded. we'll keep the setting around in case
                    // it's loaded again and just skip it here
                    if (commandData == null)
                        continue;

                    string commandName = command.Key, roleName = command.Value.Name;
                    commandsOutput.AppendFormat("[{0}", commandData.Target.Enabled ? string.Empty : ":bulletred:");
                    commandsOutput.AppendFormat("<b>{0}</b> - {1}] ", commandName, roleName);
                }
                commandsOutput.Append("<br>:bulletblue: Disabled commands are displayed with a :bulletred:");
                context.ThisRoom.Say(commandsOutput.ToString());
            }
            else
            {
                context.ThisRoom.Respond("Sorry there are not any commands that you have access to.");
            }
        }
示例#3
0
文件: Sudo.cs 项目: JonHaywood/Oberon
        private void Sudo(CommandPacket packet, PluginContext context)
        {
            Action showHelp = () => context.ThisRoom.Respond("Usage: sudo [user] [command...]");
            string[] args = MessageHelper.MessageToArgs(packet.Message);

            if (args.Length < 2) { showHelp(); return; }

            string userName = args[0];
            string command = args[1];

            if (!context.Authorizer.DoesUserExist(userName))
            {
                context.ThisRoom.Respond("You must provide a user to impersonate.");
                return;
            }
            else if (string.IsNullOrEmpty(command))
            {
                context.ThisRoom.Respond("You must provide a command to execute.");
                return;
            }

            // modify the packet
            packet.OverrideFrom(userName);
            packet.OverrideCommand(command);
            packet.OverrideMessage(packet.Message.Right(userName.Length).Trim());

            // invoke the command handler
            System.ValidateAndInvokeCommand(packet, context);
        }
示例#4
0
 private void Command(CommandPacket packet, PluginContext context)
 {
     string motion = rockPaperScissors[randomizer.Next(3)];
     string say = string.Empty;
     switch (packet.Message.ToLower())
     {
         case "rock":
             if (motion == "rock") say = "Rock ties rock.";
             if (motion == "paper") say = "Paper covers rock. You lose.";
             if (motion == "scissors") say = "Rock smashes scissors. You win.";
             break;
         case "paper":
             if (motion == "rock") say = "Paper covers rock. You win.";
             if (motion == "paper") say = "Paper ties paper.";
             if (motion == "scissors") say = "Scissors cut paper. You lose.";
             break;
         case "scissors":
             if (motion == "rock") say = "Rock smashes scissors. You lose.";
             if (motion == "paper") say = "Scissors cut paper. You win.";
             if (motion == "scissors") say = "Scissors tie scissors.";
             break;
         default:
             context.ThisRoom.Respond("Usage: shoot [rock | paper | scissors]");
             return;
     }
     context.ThisRoom.Respond(say);
 }
示例#5
0
文件: Help.cs 项目: JonHaywood/Oberon
        private void Help(CommandPacket packet, PluginContext context)
        {
            if (string.IsNullOrWhiteSpace(packet.Message))
            {
                context.ThisRoom.Respond("You must provide a command to get help information for.");
                return;
            }

            string command = ToLower(packet.Message);
            var commandData = context.Plugins.GetCommandHandler(command);
            if (commandData == null)
            {
                context.ThisRoom.Respond("The command '{0}' does not exist.", command);
                return;
            }

            var help = commandData.Help;
            if (string.IsNullOrWhiteSpace(help.Usage))
            {
                context.ThisRoom.Respond("Help is not available for this command.");
                return;
            }

            StringBuilder output = new StringBuilder(string.Format("<sub>:pointr: <b>Command Name:</b> {0}<br>", command));
            output.AppendFormat(":pointr: <b>Usage:</b> {0}<br>", help.Usage);
            if (!string.IsNullOrWhiteSpace(help.Description))
                output.AppendFormat(":pointr: <b>Description:</b> {0}", help.Description);
            context.ThisRoom.Say(output.ToString());
        }
示例#6
0
        private void Plugins(CommandPacket packet, PluginContext context)
        {
            string cmd = packet.Message.Trim().ToLower();

            switch (cmd)
            {
                case "":
                case "list":
                    var listOutput = new StringBuilder("<b>All loaded plugins:</b><br><sub>");
                    foreach (var plugin in context.Plugins.GetPlugins())
                    {
                        string name = plugin.MetaData.Name;
                        string shortcut = plugin.MetaData.ShortCutName;
                        string pluginName = name == shortcut ? name : name + " (" + shortcut + ")";
                        listOutput.AppendFormat(plugin.Enabled ? "[{0}] " : "<b>[{0}]</b> ", pluginName);
                    }
                    listOutput.Append("<br>:bulletblue: Plugins that are deactivated are in bold.");
                    context.ThisRoom.Say(listOutput.ToString());
                    break;
                case "reload":
                    context.Plugins.Load();
                    context.ThisRoom.Say("** all plugins reloaded *");
                    break;
                default:
                    context.ThisRoom.Respond("Usage: plugins [list|reload]");
                    break;
            }
        }
示例#7
0
        private void Ignore(CommandPacket packet, PluginContext context)
        {
            var args = MessageHelper.MessageToArgs(packet.Message).Iterator();
            string cmd = args.Next(ToLower), userName = args.Next(ToLower);
            if (args.Length == 0) cmd = "list";

            switch (cmd)
            {
                case "list":
                    if (context.BotSettings.IgnoredUsers.Count == 0)
                    {
                        context.ThisRoom.Respond("The ignored user list is empty.");
                        return;
                    }
                    else
                    {
                        StringBuilder output = new StringBuilder("<b>Ignored Users</b>:<br /><sub>");
                        foreach (string u in context.BotSettings.IgnoredUsers)
                            output.AppendFormat("[{0}] ", u);
                        context.ThisRoom.Say(output.ToString());
                    }
                    break;
                case "add":
                    if (string.IsNullOrEmpty(userName))
                    {
                        context.ThisRoom.Respond("Please provide a username to add.");
                        return;
                    }
                    if (context.BotSettings.IgnoredUsers.Contains(userName))
                    {
                        context.ThisRoom.Respond("This username is already in the ignored list.");
                        return;
                    }
                    context.BotSettings.IgnoredUsers.Add(userName);
                    context.BotSettings.Save();
                    context.ThisRoom.Respond("** The username '{0}' has been added to the ignore list *", userName);
                    break;
                case "remove":
                case "delete":
                case "del":
                    if (string.IsNullOrEmpty(userName))
                    {
                        context.ThisRoom.Respond("Please provide a username to remove.");
                        return;
                    }
                    if (!context.BotSettings.IgnoredUsers.Contains(userName))
                    {
                        context.ThisRoom.Respond("This username is not in the ignored list.");
                        return;
                    }
                    context.BotSettings.IgnoredUsers.Remove(userName);
                    context.BotSettings.Save();
                    context.ThisRoom.Respond("** The username '{0}' has been removed from the ignore list *", userName);
                    break;
            }
        }
示例#8
0
 private void RussianRouletteCommand(CommandPacket packet, PluginContext context)
 {
     int spin = randomizer.Next(1, 6);
     int bullet = randomizer.Next(1, 6);
     context.ThisRoom.Respond("You place a bullet in the :gun: and spin it around. Then you put it to your head, and pull...");
     if (spin == bullet)
         context.ThisRoom.Respond("BLAM! You lose.");
     else
         context.ThisRoom.Respond(":phew: You're alright.");
 }
示例#9
0
        private void AutoJoin(CommandPacket packet, PluginContext context)
        {
            Action showHelp = () => context.ThisRoom.Respond("Usage: autojoin [add|del|list] [room]");

            var args = MessageHelper.MessageToArgs(packet.Message);
            if (args.Length != 2)
            {
                showHelp();
                return;
            }

            string cmd = args[0].ToLower().Trim(), room = args[1].ToLower().Trim().Trim('#');
            switch (cmd)
            {
                case "add":
                    if (context.BotSettings.AutoJoins.Contains(room))
                    {
                        context.ThisRoom.Respond("{0} is already on the autojoin list.", room);
                    }
                    else
                    {
                        context.BotSettings.AutoJoins.Add(room);
                        context.ThisRoom.Respond("Added {0} to the autojoin list.", room);
                    }
                    break;
                case "remove":
                case "del":
                case "delete":
                    if (!context.BotSettings.AutoJoins.Contains(room))
                    {
                        context.ThisRoom.Respond("{0} is not on the autojoin list.", room);
                    }
                    else
                    {
                        context.BotSettings.AutoJoins.Remove(room);
                        context.ThisRoom.Respond("Deleted {0} from the autojoin list.", room);
                    }
                    break;
                case "list":
                    var listOutput = new StringBuilder(string.Format("<abbr title='{0}'> </abbr><b>Autojoin List:</b><br>", packet.From));
                    foreach (string s in context.BotSettings.AutoJoins)
                        listOutput.Append("-> ").Append(s).Append("<br>");
                    context.ThisRoom.Say(listOutput.ToString());
                    break;
                case "auto":

                    break;
                default:
                    showHelp();
                    break;
            }
        }
示例#10
0
文件: Away.cs 项目: JonHaywood/Oberon
 private void AwayCommand(CommandPacket packet, PluginContext context)
 {
     var message = packet.Message;
     if (message.ToLower().Trim() == "back")
     {
         BackCommand(packet, context);
         return;
     }
     else
     {
         SetAway(packet.From, message, context);
     }
 }
示例#11
0
        private void CTrig(CommandPacket packet, PluginContext context)
        {
            string newTrigger = packet.Message;
            if (string.IsNullOrWhiteSpace(newTrigger))
            {
                context.ThisRoom.Respond("Usage: ctrig [trigger]");
                return;
            }

            context.BotSettings.Trigger = newTrigger;
            context.BotSettings.Save();
            context.ThisRoom.Say("** bot trigger changed to {0} by {1} *", newTrigger, packet.From);
        }
示例#12
0
 private void EightBall(CommandPacket packet, PluginContext context)
 {
     string question = packet.Message;
     if (string.IsNullOrWhiteSpace(question))
     {
         context.ThisRoom.Respond("Please ask a question!");
     }
     else
     {
         string answer = messages[random.Next(0, messages.Length)];
         context.ThisRoom.Say("The 8ball says <abbr title='{0}'> </abbr>: <b>{1}</b>", packet.From, answer);
     }
 }
示例#13
0
文件: Join.cs 项目: JonHaywood/Oberon
        private void Join(CommandPacket packet, PluginContext context)
        {
            string rooms = packet.Message.Trim().ToLower();
            if (string.IsNullOrWhiteSpace(rooms))
            {
                context.ThisRoom.Respond("You must specify a room to join.");
                return;
            }

            foreach (string r in rooms.Split(' '))
            {
                context.Client.Join(r);
                context.ThisRoom.Say("** joined the chatroom #{0} *", r);
            }
        }
示例#14
0
        private void DefineCommand(CommandPacket packet, PluginContext context)
        {
            string word = packet.Message;
            if (string.IsNullOrEmpty(word))
            {
                context.ThisRoom.Respond("Usage: define [word]");
                return;
            }

            string definition = GetDefinition(word);
            if (string.IsNullOrEmpty(definition))
                context.ThisRoom.Respond("<b>No definition was found for <u>{0}</u>.</b>", word);
            else
                context.ThisRoom.Say("<b><u>" + word + "</u></b>:<br /><sub>" + ParseDefinition(definition) + "</sub>");
        }
示例#15
0
文件: Kick.cs 项目: JonHaywood/Oberon
        private void Kick(CommandPacket packet, PluginContext context)
        {
            var args = MessageHelper.MessageToArgs(packet.Message).Iterator();
            string user = args.Next(), reason = args.Next();

            if (args.Length == 0)
            {
                context.ThisRoom.Respond("Usage: kick [user] [reason]");
                return;
            }

            if (string.IsNullOrWhiteSpace(reason))
                context.Client.Kick(packet.ChatRoom, user);
            else
                context.Client.Kick(packet.ChatRoom, user, reason);
        }
示例#16
0
        private void About(CommandPacket packet, PluginContext context)
        {
            var args = MessageHelper.MessageToArgs(packet.Message);
            if (args.Length == 0) args = new[] { "__default" };

            switch (args[0])
            {
                case "os":
                    context.ThisRoom.Action(string.Format("is running on {0} ({1} CPU{2}", Environment.OSVersion.VersionString, Environment.ProcessorCount,
                        (Environment.ProcessorCount == 1 ? ")" : "S)")));
                    break;
                case "framework":
                    Type t = Type.GetType("Mono.Runtime");
                    if (t != null)
                        context.ThisRoom.Action("is running on the Mono Framework.");
                    else
                        context.ThisRoom.Action("is running on the .NET Framework.");
                    break;
                case "credits":
                    context.ThisRoom.Say("<b>{0}</b> Credits:<br><sub>" +
                        "<b>:develectricnet:</b> - Without you, Botdom may very well not exist.<br>" +
                        "<b>#Botdom</b> - You guys are always full of ideas.<br>" +
                        "<b>:devplaguethenet:</b> - Inspired by your excellent work.", Oberon.Core.Framework.Bot.Name);
                    break;
                case "uptime":
                    //TODO: context.BotSettings.
                    break;
                case "damn":
                    context.ThisRoom.Say(@"/me is connected to {0} (dAmnServer 0.2) as {1}. For more information on dAmn visit http://chat.deviantart.com/
                        (dAmn's official page) and http://botdom.com/wiki/DAmn (The Botdom wiki dAmn entry)<abbr title='dAmn'> </abbr>",
                        packet.ChatRoom, context.BotSettings.UserName);
                    break;
                case "oberon":
                    context.ThisRoom.Say(@"{0}: started because :devonisemus: wanted to try building a chat bot in C# (pronounced C Sharp).
                        It's goal is to be fast and ultra-super simple to use. The commands are similar to Cheddar, another C# bot.",
                        Oberon.Core.Framework.Bot.Name);
                    break;
                case "__default":
                    context.ThisRoom.Action("is a bot running <a href=\"http://www.botdom.wiki/{0}\">{0} {1}</a> by :devonisemus: Owned and " +
                        "operated by :dev{2}:<abbr title='{3}'></abbr>",
                        Oberon.Core.Framework.Bot.Name,
                        Oberon.Core.Framework.Bot.Version,
                        context.BotSettings.Owner,
                        context.BotSettings.UserName);
                    break;
            }
        }
示例#17
0
        private void Plugin(CommandPacket packet, PluginContext context)
        {
            Action showHelp = () => context.ThisRoom.Respond("Usage: plugin [name] [on|off|info]");
            var args = MessageHelper.MessageToArgs(packet.Message).Iterator();

            if (args.Length <= 1) { showHelp(); return; }
            string pluginName = args.Next(ToLower);
            string cmd = args.Next(ToLower);

            PluginHandle plugin = context.Plugins.GetPlugin(pluginName);
            if (plugin == null)
            {
                context.ThisRoom.Respond("'{0}' is not a valid plugin.", pluginName);
                return;
            }

            if (string.IsNullOrWhiteSpace(cmd)) { cmd = "info"; }
            switch (cmd)
            {
                case "info":
                    var infoOutput = new StringBuilder();
                    infoOutput.AppendFormat("<b>Name:</b> {0}<br /><sub>", plugin.MetaData.Name);
                    infoOutput.AppendFormat("<b>Shortcut:</b> {0} :bulletblue: ", plugin.MetaData.ShortCutName);
                    if (!string.IsNullOrWhiteSpace(plugin.MetaData.Description))
                        infoOutput.AppendFormat("<b>Description:</b> {0} :bulletblue: ", plugin.MetaData.Description);
                    if (!string.IsNullOrWhiteSpace(plugin.MetaData.Author))
                        infoOutput.AppendFormat("<b>Author:</b> {0} :bulletblue: ", plugin.MetaData.Author);
                    if (plugin.MetaData.Version != null)
                        infoOutput.AppendFormat("<b>Version:</b> {0} :bulletblue: ", plugin.MetaData.Version);
                    if (plugin.MetaData.HomepageUrl != null)
                        infoOutput.AppendFormat("<b>Url:</b> {0} :bulletblue:", plugin.MetaData.HomepageUrl);
                    context.ThisRoom.Say(infoOutput.ToString());
                    break;
                case "on":
                case "off":
                    bool enable = cmd == "on" ? true : false;
                    if (plugin.IsSystemPlugin)
                    {
                        context.ThisRoom.Respond("** system plugins cannot be turned off *");
                        return;
                    }

                    plugin.Enabled = false;
                    context.ThisRoom.Say("** status for plugin '{0}' was set to {1} *", pluginName, cmd);
                    break;
            }
        }
示例#18
0
        private void Access(CommandPacket packet, PluginContext context)
        {
            var args = MessageHelper.MessageToArgs(packet.Message);
            if (args.Length != 2)
            {
                context.ThisRoom.Respond("Usage: access command role");
                return;
            }
            string roleName = args[0], commandName = args[1];
            if (!context.Authorizer.DoesRoleExists(roleName))
            {
                context.ThisRoom.Respond("'The role {0}' does not exist.", roleName);
                return;
            }
            else if (!context.Authorizer.DoesCommandExist(commandName))
            {
                context.ThisRoom.Respond("The command '{0}' does not exist.", commandName);
                return;
            }

            context.Authorizer.SetCommandRole(commandName, roleName);
            context.ThisRoom.Say("** Access level for command '{0}' was set to {1} *", commandName, roleName);
        }
示例#19
0
 private void FortuneCookie(CommandPacket packet, PluginContext context)
 {
     // pick random and send it
     int randomIndex = randomizer.Next(fortunes.Length);
     context.ThisRoom.Respond("Confucious say: <b>{0}</b>", fortunes[randomIndex]);
 }
示例#20
0
 private void HelloWorldCommand(CommandPacket packet, PluginContext context)
 {
     context.ThisRoom.Respond("Hello World");
 }
示例#21
0
 private void Restart(CommandPacket packet, PluginContext context)
 {
     context.ThisRoom.Say("** restarting the bot... *");
     context.Listener.Stop(true);
 }
示例#22
0
文件: Away.cs 项目: JonHaywood/Oberon
 private void BackCommand(CommandPacket packet, PluginContext context)
 {
     SetBack(packet.From, context);
 }
示例#23
0
文件: Part.cs 项目: JonHaywood/Oberon
 private void Part(CommandPacket packet, PluginContext context)
 {
     string room = string.IsNullOrWhiteSpace(packet.Message) ? packet.ChatRoom : packet.Message.Trim();
     context.Client.Part(room);
 }
示例#24
0
        /// <summary>
        /// Executes the command handler.
        /// </summary>
        /// <param name="commandData">The command data.</param>
        /// <param name="packet">The packet.</param>
        public void ExecuteCommandHandler(CommandData commandData, CommandPacket packet)
        {
            var context = GenerateContext(packet, commandData.Target);
            var handler = commandData.CommandHandler;

            try
            {
                // Since this is a system plugin the current thread is the main processing thread. we don't
                // want to be held back processing commands while new packets are arriving. so spawn off a
                // new thread to process the incoming command and keep on trucking while that happens.
                Task.Factory
                    .StartNew(() => handler(packet, context), TaskCreationOptions.PreferFairness)
                    .ContinueWith(t =>
                    {
                        // if this runs there was an exception executing the command on the thread
                        t.Exception.Handle(ex =>
                        {
                            console.WriteLine(string.Format("Error executing the command '{0}'. See bot log for details.", packet.Command), Style.Error);
                            Logger.Error(ex.Message, ex);
                            if (context.Client != null && context.Client.Connected) context.Client.Say(packet.ChatRoom, string.Format("{0}: error occured executing the command. Notify the bot admin.", packet.Command));
                            return true;
                        });
                    }, TaskContinuationOptions.OnlyOnFaulted);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                console.WriteLine("Error occured. See bot log for details.", Style.Error);
            }
        }
示例#25
0
        /// <summary>
        /// Invokes a command.
        /// </summary>
        /// <param name="command">The command.</param>
        private void InvokeCommand(string command)
        {
            var botSettings = Module.UIContext.BotSettings;

            // get the settings
            var botTrigger = botSettings.Trigger;
            var username = botSettings.UserName;
            var owner = botSettings.Owner;

            // create the command packet as if it from from the server
            string data = string.Format("recv chat:{0}\n\nmsg main\nfrom={1}\n\n{2}", chatroom.Name, owner, command);
            ServerPacket serverPacket = new ServerPacket(data);
            EventPacket eventPacket = new EventPacket(serverPacket);
            CommandPacket commandPacket = new CommandPacket(botTrigger, username, serverPacket);

            // create a plugin context
            PluginContext context = Module.UIContext.PluginContextFactory.Create(eventPacket, null);

            // send the command!
            Oberon.Core.Plugins.System.ValidateAndInvokeCommand(commandPacket, context);
        }
示例#26
0
 private void TrigCheck(CommandPacket packet, PluginContext context)
 {
     context.ThisRoom.Respond(context.BotSettings.Trigger);
 }
示例#27
0
 private void ChuckCommand(CommandPacket packet, PluginContext context)
 {
     int index = random.Next(facts.Length);
     string fact = facts[index];
     context.ThisRoom.Say("<b>" + fact + "</b>");
 }
示例#28
0
文件: Quit.cs 项目: JonHaywood/Oberon
 private void Quit(CommandPacket packet, PluginContext context)
 {
     context.ThisRoom.Say("** shutting down the bot... *");
     context.Listener.Stop();
 }