bitbot-3.11-fork/modules/messages.py

27 lines
997 B
Python
Raw Normal View History

import re
from src import ModuleManager, utils
class Module(ModuleManager.BaseModule):
2020-01-30 16:28:16 +00:00
_name = "MSG"
@utils.hook("received.command.msearch")
2020-01-30 16:31:38 +00:00
@utils.spec("!r~channel !<pattern>string")
def msearch(self, event):
2020-01-30 16:31:38 +00:00
pattern = re.compile(event["spec"][1], re.I)
message_list = list(event["spec"][0].buffer.find_all(pattern))
message_count = len(message_list)
if message_list:
messages = []
2020-01-30 15:13:15 +00:00
for i, message in enumerate(message_list):
seconds = utils.datetime.seconds_since(message.line.timestamp)
2020-01-30 15:13:15 +00:00
messages.append("(%d/%d) %s ago %s" % (i+1, message_count,
utils.datetime.format.to_pretty_since(seconds),
message.line.format()))
event["stdout"].write("%s: found: %s"
2020-01-30 15:13:15 +00:00
% (event["user"].nickname, "\n".join(messages)))
else:
event["stderr"].write("%s: no messages found"
% event["user"].nickname)