-local_config.ini\r
-persistent_config.ini\r
+local_config.ini
+persistent_config.ini
.idea
distbot.egg-info
})
)
- def get_amqp_routing_key(self, msg):
+ @staticmethod
+ def get_amqp_routing_key(nick, msg):
# simplify the key significantly
+ offset = 0
key = shlex.split(re.sub(r'[^a-zäöüß0-9 "\']', '', msg["body"].lower()))
if not key:
# simple dots, smilies, emoji shit, pass through
key = shlex.split(msg["body"].lower())
# cut the nick from the message
- if self.nick.lower() in key[0].lower():
+ if nick.lower() in key[0].lower():
if msg["body"][0] == '>':
key.pop(0)
key.insert(0, "quoted_nick")
else:
key.pop(0)
key.insert(0, "nick")
+ offset = msg["body"].find(nick) + len(nick) + 1
routing_key = '.'.join(key).encode("UTF-8")[:255]
- return routing_key
+
+ return offset, routing_key
def message(self, msg):
logger.debug("msg is " + str(msg))
self.initialize_actionthreads()
self.echo("Worker One available for master.")
- routing_key = self.get_amqp_routing_key(msg)
+ nick_offset, routing_key = self.get_amqp_routing_key(self.nick, msg)
if msg["type"] == "groupchat":
recipient = msg["mucroom"]
else:
recipient = msg["from"].jid
- offset = msg["body"].find(self.nick) + len(self.nick) + 1
process_message(
routing_key=routing_key,
body=json.dumps({
"from": msg["from"].jid,
"to": recipient,
- "body": msg["body"][offset:].strip()
+ "body": msg["body"][nick_offset:].strip()
})
)
action.event = Action.deserialize(action.event)
return action
+ def __eq__(self, other):
+ if isinstance(other, Action):
+ return self.serializable == other.serializable
+ else:
+ return False
+
def send_action(actionqueue, action):
connection = pika.BlockingConnection(
--- /dev/null
+# -*- coding: utf-8 -*-
+
+
+def message():
+ return {"body": "message in a bottle"}
+
+
+def test_pipeline():
+ pass
--- /dev/null
+# -*- coding: utf-8 -*-
+import pytest
+
+from distbot.bot.bot import Bot
+
+
+@pytest.mark.parametrize(
+ argnames='nick, message, expected_key, expected_offset',
+ argvalues=[
+ ("schrottbot", "schrottbot make me happy", b"nick.make.me.happy", 11),
+ ("schrottbot", "schrottbot, make me happy", b"nick.make.me.happy", 11),
+ ("schrottbot", "schrottbot: make me happy", b"nick.make.me.happy", 11),
+ ("schrottbot", "> schrottbot: make me happy", b"quoted_nick.make.me.happy", 13),
+ ("schrottbot", "> schrottbot, make me happy", b"quoted_nick.make.me.happy", 13),
+ ("schrottbot", "> schrottbot make me happy", b"quoted_nick.make.me.happy", 13),
+ ("schrottbot", "https://docs.pytest.org/en/latest/warnings.html", b"httpsdocspytestorgenlatestwarningshtml", 0),
+ ]
+)
+def test_get_amqp_routing_key(nick, message, expected_key, expected_offset):
+ msgobj = {"body": message}
+ offset, key = Bot.get_amqp_routing_key(nick, msgobj)
+ assert offset == expected_offset
+ assert key == expected_key
--- /dev/null
+# -*- coding: utf-8 -*-
+from distbot.bot.worker import Worker
+
+import pytest
+
+from distbot.common.action import Action
+
+
+@pytest.mark.parametrize(
+ argnames='message, expected_action',
+ argvalues=[
+ ('http://debianforum.de', Action(msg="Title: Trollspielwiese")),
+ ]
+)
+def test_urlresolver(monkeypatch, message, expected_action):
+ monkeypatch.setattr(Worker, "register_plugin", lambda x: None)
+ import distbot.plugins.url as url
+ monkeypatch.setattr(url, "extract_title", lambda x: "Trollspielwiese")
+
+ worker = url.URLResolver("_")
+
+ result = worker.parse_body(msg={"body": message})
+ assert result == expected_action