aboutsummaryrefslogtreecommitdiff
path: root/discord/ext/commands/bot.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-09 15:16:28 -0500
committerRapptz <[email protected]>2016-01-09 15:16:28 -0500
commit0a07fc088c0634176707cab6d2eb965d6f8e36b9 (patch)
tree6344fefc29e2cd23e6cf7deba294c6b98f888610 /discord/ext/commands/bot.py
parent[commands] Add local error handlers. (diff)
downloaddiscord.py-0a07fc088c0634176707cab6d2eb965d6f8e36b9.tar.xz
discord.py-0a07fc088c0634176707cab6d2eb965d6f8e36b9.zip
[commands] Inject the internal variables for bot.say & co explicitly.
This is to catch cases where it wouldn't fail to find it when inspecting the stack to catch these stack variables.
Diffstat (limited to 'discord/ext/commands/bot.py')
-rw-r--r--discord/ext/commands/bot.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index fbdaa75a..7b6cd675 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -33,6 +33,16 @@ from .view import StringView
from .context import Context
from .errors import CommandNotFound
+def _get_variable(name):
+ stack = inspect.stack()
+ try:
+ for frames in stack:
+ current_locals = frames[0].f_locals
+ if name in current_locals:
+ return current_locals[name]
+ finally:
+ del stack
+
def when_mentioned(bot, msg):
"""A callable that implements a command prefix equivalent
to being mentioned, e.g. ``@bot ``."""
@@ -71,13 +81,6 @@ class Bot(GroupMixin, discord.Client):
# internal helpers
- def _get_variable(self, name):
- stack = inspect.stack()
- for frames in stack:
- current_locals = frames[0].f_locals
- if name in current_locals:
- return current_locals[name]
-
def _get_prefix(self, message):
prefix = self.command_prefix
if callable(prefix):
@@ -122,7 +125,7 @@ class Bot(GroupMixin, discord.Client):
content : str
The content to pass to :class:`Client.send_message`
"""
- destination = self._get_variable('_internal_channel')
+ destination = _get_variable('_internal_channel')
result = yield from self.send_message(destination, content)
return result
@@ -141,7 +144,7 @@ class Bot(GroupMixin, discord.Client):
content : str
The content to pass to :class:`Client.send_message`
"""
- destination = self._get_variable('_internal_author')
+ destination = _get_variable('_internal_author')
result = yield from self.send_message(destination, content)
return result
@@ -161,8 +164,8 @@ class Bot(GroupMixin, discord.Client):
content : str
The content to pass to :class:`Client.send_message`
"""
- author = self._get_variable('_internal_author')
- destination = self._get_variable('_internal_channel')
+ author = _get_variable('_internal_author')
+ destination = _get_variable('_internal_channel')
fmt = '{0.mention}, {1}'.format(author, str(content))
result = yield from self.send_message(destination, fmt)
return result
@@ -184,7 +187,7 @@ class Bot(GroupMixin, discord.Client):
name
The second parameter to pass to :meth:`Client.send_file`
"""
- destination = self._get_variable('_internal_channel')
+ destination = _get_variable('_internal_channel')
result = yield from self.send_file(destination, fp, name)
return result
@@ -202,7 +205,7 @@ class Bot(GroupMixin, discord.Client):
---------
The :meth:`Client.send_typing` function.
"""
- destination = self._get_variable('_internal_channel')
+ destination = _get_variable('_internal_channel')
yield from self.send_typing(destination)
# listener registration