Exemple #1
0
        /// <summary>
        /// Stops the plugin and removes all its functionality available in the bot.
        /// Changes the status from <see cref="PluginStatus.Active"/> to <see cref="PluginStatus.Ready"/> when successful or <see cref="PluginStatus.Error"/> otherwise.
        /// </summary>
        /// <param name="bot">The bot instance where this plugin should be stopped. Can be null when not required.</param>
        public PluginResponse Stop(Bot bot)
        {
            switch (Type)
            {
            case PluginType.None:
                break;

            case PluginType.BotPlugin:
                if (bot is null)
                {
                    foreach (var pluginObjs in botPluginList.Values)
                    {
                        DestroyPluginObjects(pluginObjs);
                    }
                    botPluginList.Clear();
                }
                else
                {
                    if (botPluginList.TryGetValue(bot, out var pluginObjs))
                    {
                        botPluginList.Remove(bot);
                        DestroyPluginObjects(pluginObjs);
                    }
                }
                break;

            case PluginType.CorePlugin:
                if (corePlugin != null)
                {
                    BotManager.IterateAll(b =>
                    {
                        if (b.Injector.TryGet <CommandManager>(out var commandManager))
                        {
                            commandManager.UnregisterCollection(corePlugin.Bag);
                        }
                    });
                    DestroyPluginObjects(corePlugin);
                    corePlugin = null;
                }
                break;

            case PluginType.Factory:
                ResourceResolver.RemoveResolver(factoryObject);
                break;

            case PluginType.Commands:
                if (corePlugin != null)
                {
                    DestroyPluginObjects(corePlugin);
                }
                break;

            default:
                throw Tools.UnhandledDefault(Type);
            }

            status = PluginStatus.Ready;

            return(PluginResponse.Ok);
        }