Loading cog/bot.py +15 −1 Original line number Diff line number Diff line Loading @@ -289,7 +289,7 @@ class CogBot(discord.Client): with cogdb.session_scope(cogdb.Session) as session: # Check permissions before full parsing cmd = content[len(self.prefix):content.find(' ')] cmd = cmd_from_content(self.prefix, content) cogdb.query.check_perms(session, message, cmd) args = self.parser.parse_args(re.split(r'\s+', content)) Loading Loading @@ -492,6 +492,20 @@ async def simple_heartbeat(delay=30): await asyncio.sleep(delay) def cmd_from_content(prefix, content): """ Determine the command that was asked for from the content of the message. Returns: The command without the prefix or any other content. """ cont = content[len(prefix):] index = content.find(' ') if index != -1: cont = cont[:index - 1] return cont def main(): # pragma: no cover """ Entry here! """ sqlalchemy_log = '--db' in sys.argv Loading tests/cog/test_bot.py +15 −1 Original line number Diff line number Diff line """ Test the bot's main functions. """ from cog.bot import EmojiResolver from cog.bot import EmojiResolver, cmd_from_content from tests.conftest import Guild, Emoji Loading Loading @@ -44,3 +44,17 @@ def test_emoji_fix(): emo.update([guild]) assert emo.fix(":duck: :sleep:", guild) == "[duck] [sleep]" def test_cmd_from_content_no_space(): content = "!fort" prefix = '!' assert "fort" == cmd_from_content(prefix, content) def test_cmd_from_content_has_space(): content = "!bgs subCmd some text" prefix = '!' assert "bgs" == cmd_from_content(prefix, content) Loading
cog/bot.py +15 −1 Original line number Diff line number Diff line Loading @@ -289,7 +289,7 @@ class CogBot(discord.Client): with cogdb.session_scope(cogdb.Session) as session: # Check permissions before full parsing cmd = content[len(self.prefix):content.find(' ')] cmd = cmd_from_content(self.prefix, content) cogdb.query.check_perms(session, message, cmd) args = self.parser.parse_args(re.split(r'\s+', content)) Loading Loading @@ -492,6 +492,20 @@ async def simple_heartbeat(delay=30): await asyncio.sleep(delay) def cmd_from_content(prefix, content): """ Determine the command that was asked for from the content of the message. Returns: The command without the prefix or any other content. """ cont = content[len(prefix):] index = content.find(' ') if index != -1: cont = cont[:index - 1] return cont def main(): # pragma: no cover """ Entry here! """ sqlalchemy_log = '--db' in sys.argv Loading
tests/cog/test_bot.py +15 −1 Original line number Diff line number Diff line """ Test the bot's main functions. """ from cog.bot import EmojiResolver from cog.bot import EmojiResolver, cmd_from_content from tests.conftest import Guild, Emoji Loading Loading @@ -44,3 +44,17 @@ def test_emoji_fix(): emo.update([guild]) assert emo.fix(":duck: :sleep:", guild) == "[duck] [sleep]" def test_cmd_from_content_no_space(): content = "!fort" prefix = '!' assert "fort" == cmd_from_content(prefix, content) def test_cmd_from_content_has_space(): content = "!bgs subCmd some text" prefix = '!' assert "bgs" == cmd_from_content(prefix, content)