示例#1
0
        /// <summary>
        /// Called when a plugin has been unloaded
        /// </summary>
        /// <param name="sender"></param>
        internal void OnPluginUnloaded(Plugin sender)
        {
            List <DirectMessageCommand> dmCommands    = new List <DirectMessageCommand>();
            List <GuildCommand>         guildCommands = new List <GuildCommand>();

            // Remove all discord commands which were registered by the plugin
            foreach (DirectMessageCommand cmd in _directMessageCommands.Values)
            {
                if (cmd.Plugin.Name == sender.Name)
                {
                    dmCommands.Add(cmd);
                }
            }

            foreach (GuildCommand cmd in _guildCommands.Values)
            {
                if (cmd.Plugin.Name == sender.Name)
                {
                    guildCommands.Add(cmd);
                }
            }

            for (int index = 0; index < dmCommands.Count; index++)
            {
                DirectMessageCommand cmd = dmCommands[index];
                RemoveDmCommand(cmd);
            }

            for (int index = 0; index < guildCommands.Count; index++)
            {
                GuildCommand cmd = guildCommands[index];
                RemoveGuildCommand(cmd);
            }
        }
示例#2
0
        /// <summary>
        /// Removes a discord command
        /// Sourced from Command.cs of OxideMod (https://github.com/OxideMod/Oxide.Rust/blob/develop/src/Libraries/Command.cs#L314)
        /// </summary>
        /// <param name="command"></param>
        private void RemoveDmCommand(DirectMessageCommand command)
        {
            DirectMessageCommand dmCommand = _directMessageCommands[command.Name];

            dmCommand.OnRemoved();
            _directMessageCommands.Remove(command.Name);
        }
示例#3
0
        public void RemoveDiscordCommand(string command, Plugin plugin)
        {
            DirectMessageCommand dmCommand = _directMessageCommands[command];

            if (dmCommand != null && dmCommand.Plugin == plugin)
            {
                RemoveDmCommand(dmCommand);
            }

            GuildCommand guildCommand = _guildCommands[command];

            if (guildCommand != null && guildCommand.Plugin == plugin)
            {
                RemoveGuildCommand(guildCommand);
            }
        }
示例#4
0
        /// <summary>
        /// Adds a discord direct message command
        /// Sourced From Command.cs of OxideMod (https://github.com/OxideMod/Oxide.Rust/blob/develop/src/Libraries/Command.cs#L134)
        /// </summary>
        /// <param name="command">Command to add</param>
        /// <param name="plugin">Plugin to add the command for</param>
        /// <param name="callback">Method name of the callback</param>
        public void AddDirectMessageCommand(string command, Plugin plugin, Action <DiscordMessage, string, string[]> callback)
        {
            string commandName = command.ToLowerInvariant();

            if (_directMessageCommands.TryGetValue(commandName, out DirectMessageCommand cmd))
            {
                string previousPluginName = cmd.Plugin?.Name ?? "an unknown plugin";
                string newPluginName      = plugin?.Name ?? "An unknown plugin";
                DiscordExtension.GlobalLogger.Warning($"{newPluginName} has replaced the '{commandName}' discord direct message command previously registered by {previousPluginName}");
            }

            cmd = new DirectMessageCommand(commandName, plugin, callback);

            // Add the new command to collections
            _directMessageCommands[commandName] = cmd;
        }
示例#5
0
        /// <summary>
        /// Handles the specified direct message command
        /// Sourced from Command.cs of OxideMod (https://github.com/OxideMod/Oxide.Rust/blob/develop/src/Libraries/Command.cs#L361)
        /// </summary>
        /// <param name="client"></param>
        /// <param name="channel"></param>
        /// <param name="name"></param>
        /// <param name="args"></param>
        /// <param name="message"></param>
        internal bool HandleDirectMessageCommand(BotClient client, DiscordMessage message, DiscordChannel channel, string name, string[] args)
        {
            DirectMessageCommand command = _directMessageCommands[name];

            if (command == null || !command.CanRun(client) || !command.CanHandle(message, channel))
            {
                return(false);
            }

            if (!command.Plugin.IsLoaded)
            {
                _directMessageCommands.Remove(name);
                return(false);
            }

            if (!client.IsPluginRegistered(command.Plugin))
            {
                return(false);
            }

            command.HandleCommand(message, name, args);
            return(true);
        }