Skip to content

Commit

Permalink
plugins/explain.py: Added explanation for do not ask to ask
Browse files Browse the repository at this point in the history
This patch adds response in case a user asks abrupt question.

Closes #389
  • Loading branch information
yashasingh committed Nov 28, 2017
1 parent 340bf99 commit a0b1946
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
9 changes: 9 additions & 0 deletions plugins/deprecate_bot_prefixes.plug
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions plugins/deprecate_bot_prefixes.py
Original file line number Diff line number Diff line change
@@ -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)
)
10 changes: 10 additions & 0 deletions plugins/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
7 changes: 7 additions & 0 deletions tests/deprecate_bot_prefixes_test.py
Original file line number Diff line number Diff line change
@@ -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')
10 changes: 0 additions & 10 deletions utils/deprecate_cobot.plug

This file was deleted.

18 changes: 0 additions & 18 deletions utils/deprecate_cobot.py

This file was deleted.

0 comments on commit a0b1946

Please sign in to comment.