Пример #1
0
	def test_ifTimelimitExceeded_whileProcessingMessage_thenAbortMessage(self):
		msg = AsyncMock()
		msg.content = "1000000d1000000h1"
		msg.channel.send = AsyncMock()
		msg.author.display_name = "bert"
		with self.assertLogs("main", logging.WARNING):
			with self.assertRaises(ParserTimeoutError):
				run(on_message(msg))
		msg.channel.send.assert_called()
Пример #2
0
	def test_doesNothing_whenMessageHasNoDice(self):
		msg = Mock()
		for content in (
			"hello world",
			"indi12",
			"4+4d",
			"",
			"d\n67",
		):
			msg.content = content
			res = run(on_message(msg))
			self.assertEqual(res, "no dice")
Пример #3
0
	def test_sendsReply_whenMessageContainsDiceCodes(self):
		msg = Mock()
		msg.channel.send = AsyncMock()
		for content in (
			"d20",
			"Hello d20dis world",
			"hit for d20adv+3 then d6+2 damage.",
			"d8\nd9+4",
			"hello\nthere\nd2",
		):
			msg.content = content
			run(on_message(msg))
			msg.channel.send.assert_called()
Пример #4
0
def root():
    msg = Message(request.json)

    if msg.type.lower() == 'ping':
        return

    if msg.type.lower() == 'message':
        return bot.on_message(msg)

    try:
        handler = getattr(bot, msg.type)
    except AttributeError:
        return {"message": "TODO: " + msg.type}
    else:
        return handler(msg)
Пример #5
0
	def test_logsError_whenRaisingException(self):
		with self.assertLogs("main", logging.ERROR):
			run(on_message(Mock(side_effect=Exception("test exception"))))
Пример #6
0
	def test_doesNothing_whenMessageIsFromSelf(self):
		bot.client = Mock()
		msg = Mock()
		msg.author = bot.client.user = Mock()
		res = run(on_message(msg))
		self.assertEqual(res, "own message")