From a0b1946d290d324502c3264f324f18e1fce6c1f5 Mon Sep 17 00:00:00 2001 From: yashasingh Date: Tue, 28 Nov 2017 16:30:39 +0530 Subject: [PATCH] plugins/explain.py: Added explanation for do not ask to ask This patch adds response in case a user asks abrupt question. Closes https://github.com/coala/corobo/issues/389 --- config.py | 3 +++ plugins/deprecate_bot_prefixes.plug | 9 +++++++++ plugins/deprecate_bot_prefixes.py | 22 ++++++++++++++++++++++ plugins/explain.py | 10 ++++++++++ tests/deprecate_bot_prefixes_test.py | 7 +++++++ utils/deprecate_cobot.plug | 10 ---------- utils/deprecate_cobot.py | 18 ------------------ 7 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 plugins/deprecate_bot_prefixes.plug create mode 100644 plugins/deprecate_bot_prefixes.py create mode 100644 tests/deprecate_bot_prefixes_test.py delete mode 100644 utils/deprecate_cobot.plug delete mode 100644 utils/deprecate_cobot.py diff --git a/config.py b/config.py index 70323740..bfa72da7 100644 --- a/config.py +++ b/config.py @@ -21,6 +21,9 @@ if not os.environ.get('COBOT_PREFIX'): BOT_ALT_PREFIXES = ('cobot ', ) +BOT_DEPRECATED_PREFIXES = os.environ.get( + 'BOT_DEPRECATED_PREFIXES', '').split() or ('cobot ', ) + BOT_ADMINS = os.environ.get('BOT_ADMINS', '').split() or ('*@localhost', ) # Text is a special case if BACKEND == 'Text': diff --git a/plugins/deprecate_bot_prefixes.plug b/plugins/deprecate_bot_prefixes.plug new file mode 100644 index 00000000..97add126 --- /dev/null +++ b/plugins/deprecate_bot_prefixes.plug @@ -0,0 +1,9 @@ +[Core] +name = deprecate_bot_prefixes +module = deprecate_bot_prefixes + +[Documentation] +description = A callback for every message that starts with depecrated prefix, hence, leaving a deprecation notice + +[Python] +version = 3 diff --git a/plugins/deprecate_bot_prefixes.py b/plugins/deprecate_bot_prefixes.py new file mode 100644 index 00000000..ac4d9886 --- /dev/null +++ b/plugins/deprecate_bot_prefixes.py @@ -0,0 +1,22 @@ +from errbot import BotPlugin + + +class DeprecateBotPrefixes(BotPlugin): + """ + A callback for every message that starts with depecrated prefix, hence, + leaving a deprecation notice + """ + + def callback_message(self, msg): + """ + Notify the user issuing the command that use deprecated prefix. + """ + + for deprecated_prefix in self.bot_config.BOT_DEPRECATED_PREFIXES: + if msg.body.startswith(deprecated_prefix): + self.send( + msg.frm, + "@{} usage of {} has been deprecated, please use {} " + "from now on.".format(msg.frm.nick, deprecated_prefix, + self.bot_config.BOT_PREFIX) + ) diff --git a/plugins/explain.py b/plugins/explain.py index 936d2e83..894f7f1a 100644 --- a/plugins/explain.py +++ b/plugins/explain.py @@ -83,6 +83,16 @@ class Explain(BotPlugin): 'newcomer Pull Request\n- merge a difficulty/low Pull ' 'Request\n- review at least a difficulty/low or higher ' 'Pull Request' + 'do not ask to ask': 'This is a lazy way of asking your question ' + 'because you\'re asking for more than what ' + 'you think you\'re asking. The solution is not ' + 'to ask to ask, but just to ask by actaully ' + 'formalizing it in words. Someone who is idling ' + 'on the channel and only occasionally glances' + 'at what\'s going on is unlikely to answer ' + 'to your "asking to ask" question, but your ' + 'actual problem description may pique their ' + 'interest and get them to answer.' } ERROR_MSG = ( diff --git a/tests/deprecate_bot_prefixes_test.py b/tests/deprecate_bot_prefixes_test.py new file mode 100644 index 00000000..97eb75cd --- /dev/null +++ b/tests/deprecate_bot_prefixes_test.py @@ -0,0 +1,7 @@ +pytest_plugins = ['errbot.backends.test'] +extra_plugin_dir = 'plugins' + +def test_deprecated_prefixes_other(testbot): + testbot.bot_config.BOT_DEPRECATED_PREFIXES = ('oldbot', 'deprecatedbot') + testbot.assertCommand('oldbot just a test', 'has been deprecated') + testbot.assertCommand('deprecatedbot just a test', 'has been deprecated') diff --git a/utils/deprecate_cobot.plug b/utils/deprecate_cobot.plug deleted file mode 100644 index 3f22156c..00000000 --- a/utils/deprecate_cobot.plug +++ /dev/null @@ -1,10 +0,0 @@ -[Core] -name = deprecate_cobot -module = deprecate_cobot - -[Documentation] -description = A callback for every message that starts with cobot, hence, leaving a deprecation notice - -[Python] -version = 3 - diff --git a/utils/deprecate_cobot.py b/utils/deprecate_cobot.py deleted file mode 100644 index f2c38d55..00000000 --- a/utils/deprecate_cobot.py +++ /dev/null @@ -1,18 +0,0 @@ -from errbot import BotPlugin - - -class Deprecate_corobo(BotPlugin): - """ - A callback for every message that starts with cobot, hence, leaving a deprecation notice - """ - - def callback_message(self, msg): - """ - Notify the user issuing the command that cobot is deprecated. - """ - if msg.body.startswith("cobot "): - self.send( - msg.frm, - "@{} usage of `cobot` has been deprecated, please use `corobo` " - "from now on.".format(msg.frm.nick) - )