more tests
This commit is contained in:
+5
-4
@@ -193,7 +193,7 @@ class Bot(object):
|
|||||||
message.content = re.sub(r"<@!?[^>]+>", "", message.content)
|
message.content = re.sub(r"<@!?[^>]+>", "", message.content)
|
||||||
elif is_mention:
|
elif is_mention:
|
||||||
message.content = re.sub(
|
message.content = re.sub(
|
||||||
f"^<@!?{self.client.user.id}>", "", message.content
|
f"<@!?{self.client.user.id}>", "", message.content, count=1
|
||||||
)
|
)
|
||||||
|
|
||||||
command_args = parse_arguments(message.content)
|
command_args = parse_arguments(message.content)
|
||||||
@@ -212,12 +212,13 @@ class Bot(object):
|
|||||||
|
|
||||||
command_found = False
|
command_found = False
|
||||||
|
|
||||||
|
if self.lower_command_names:
|
||||||
|
command_args[0] = command_args[0].lower()
|
||||||
|
|
||||||
for command in self.__commands:
|
for command in self.__commands:
|
||||||
if re.match(
|
if re.match(
|
||||||
command.regex,
|
command.regex,
|
||||||
command_args[0].lower()
|
command_args[0],
|
||||||
if self.lower_command_names
|
|
||||||
else command_args[0],
|
|
||||||
):
|
):
|
||||||
if self.log_calls:
|
if self.log_calls:
|
||||||
debug(message, str(command_args))
|
debug(message, str(command_args))
|
||||||
|
|||||||
@@ -122,6 +122,17 @@ class TestHelp(AsyncTestCase):
|
|||||||
"desc2", reference=message, mention_author=False
|
"desc2", reference=message, mention_author=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch_discord
|
||||||
|
def test_not_found(self):
|
||||||
|
bot = Bot("app_name", "version")
|
||||||
|
message = AsyncMock()
|
||||||
|
self._await(bot.help(None, message, "help", "notfound"))
|
||||||
|
message.channel.send.assert_awaited_once_with(
|
||||||
|
f"Command `notfound` not found",
|
||||||
|
reference=message,
|
||||||
|
mention_author=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestRegisterEvent(TestCase):
|
class TestRegisterEvent(TestCase):
|
||||||
@skip
|
@skip
|
||||||
@@ -313,25 +324,171 @@ class TestOnMessage(AsyncTestCase):
|
|||||||
f" #test_channel in server 'test_guild'"
|
f" #test_channel in server 'test_guild'"
|
||||||
)
|
)
|
||||||
|
|
||||||
@skip
|
@patch_discord
|
||||||
def test_mention_self(self):
|
def test_mention_self(self):
|
||||||
self.fail("not implemented")
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> test arg0 arg1"
|
||||||
|
message.author = bot.client.user
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_not_awaited()
|
||||||
|
watcher_callback.assert_not_awaited()
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
@skip
|
@patch_discord
|
||||||
def test_mention_direct(self):
|
def test_mention_direct(self):
|
||||||
self.fail("not implemented")
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> test arg0 arg1"
|
||||||
|
message.channel.type == discord.ChannelType.private
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_awaited_once_with(
|
||||||
|
bot.client, message, "test", "arg0", "arg1"
|
||||||
|
)
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
@skip
|
@patch_discord
|
||||||
def test_any_mention(self):
|
def test_any_mention(self):
|
||||||
self.fail("not implemented")
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.any_mention = True
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "test <@12345> arg0 arg1"
|
||||||
|
message.channel.type == discord.ChannelType.private
|
||||||
|
message.mentions = [bot.client.user]
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_awaited_once_with(
|
||||||
|
bot.client, message, "test", "arg0", "arg1"
|
||||||
|
)
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
@skip
|
@patch_discord
|
||||||
|
def test_any_mention_off(self):
|
||||||
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.any_mention = False
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "test <@12345> arg0 arg1"
|
||||||
|
message.channel.type == discord.ChannelType.private
|
||||||
|
message.mentions = [bot.client.user]
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_not_awaited()
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
|
@patch_discord
|
||||||
def test_remove_mentions(self):
|
def test_remove_mentions(self):
|
||||||
self.fail("not implemented")
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.remove_mentions = True
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> test <@12345> arg1"
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_awaited_once_with(bot.client, message, "test", "arg1")
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
@skip
|
@patch_discord
|
||||||
|
def test_remove_mentions_off(self):
|
||||||
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.remove_mentions = False
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> test <@12345> arg1"
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_awaited_once_with(
|
||||||
|
bot.client, message, "test", "<@12345>", "arg1"
|
||||||
|
)
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
|
@patch_discord
|
||||||
def test_lower_command_names(self):
|
def test_lower_command_names(self):
|
||||||
self.fail("not implemented")
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.lower_command_names = True
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> Test arg0 arg1"
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_awaited_once_with(
|
||||||
|
bot.client, message, "test", "arg0", "arg1"
|
||||||
|
)
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_not_awaited()
|
||||||
|
|
||||||
|
@patch_discord
|
||||||
|
def test_lower_command_names_off(self):
|
||||||
|
bot = Bot("app_name", "version")
|
||||||
|
bot.enforce_write_permission = False
|
||||||
|
bot.lower_command_names = False
|
||||||
|
bot.client.user.id = "12345"
|
||||||
|
simple_callback = AsyncMock()
|
||||||
|
bot.register_command("test", simple_callback, "short", "long")
|
||||||
|
watcher_callback = AsyncMock()
|
||||||
|
bot.register_watcher(watcher_callback)
|
||||||
|
fallback_callback = AsyncMock()
|
||||||
|
bot.register_fallback(fallback_callback)
|
||||||
|
message = AsyncMock()
|
||||||
|
message.content = "<@12345> Test arg0 arg1"
|
||||||
|
self._await(bot.on_message(message))
|
||||||
|
simple_callback.assert_not_awaited()
|
||||||
|
watcher_callback.assert_awaited_once_with(bot.client, message)
|
||||||
|
fallback_callback.assert_awaited_once_with(
|
||||||
|
bot.client, message, "Test", "arg0", "arg1"
|
||||||
|
)
|
||||||
|
|
||||||
@skip
|
@skip
|
||||||
def test_fire_registered_event(self):
|
def test_fire_registered_event(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user