Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot: fix per-channel configuration by plugin names #1840

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,28 @@ def call(self, func, sopel, trigger):

# if "*" is used, we are disabling all plugins on provided channel
if '*' in disabled_plugins:
LOGGER.debug(
"All plugins disabled in %s; skipping execution of %s.%s",
trigger.sender, func.plugin_name, func.__name__
)
return
if func.__module__ in disabled_plugins:
if func.plugin_name in disabled_plugins:
LOGGER.debug(
"Plugin %s is disabled in %s; skipping execution of %s",
func.plugin_name, trigger.sender, func.__name__
)
return

# disable chosen methods from plugins
if 'disable_commands' in channel_config:
disabled_commands = literal_eval(channel_config.disable_commands)

if func.__module__ in disabled_commands:
if func.__name__ in disabled_commands[func.__module__]:
if func.plugin_name in disabled_commands:
if func.__name__ in disabled_commands[func.plugin_name]:
LOGGER.debug(
"Skipping execution of %s.%s in %s: disabled_commands matched",
func.plugin_name, func.__name__, trigger.sender
)
return

try:
Expand Down
5 changes: 5 additions & 0 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import inspect
import imp
import importlib
import itertools
import os

from sopel import loader
Expand Down Expand Up @@ -259,6 +260,10 @@ def has_setup(self):

def register(self, bot):
relevant_parts = loader.clean_module(self._module, bot.config)
for part in itertools.chain(*relevant_parts):
# annotate all callables in relevant_parts with `plugin_name`
# attribute to make per-channel config work; see #1839
setattr(part, 'plugin_name', self.name)
bot.add_plugin(self, *relevant_parts)

def unregister(self, bot):
Expand Down