2020-01-30 14:59:48 +00:00
|
|
|
import re
|
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
2020-01-30 16:28:16 +00:00
|
|
|
_name = "MSG"
|
|
|
|
|
2020-01-30 14:59:48 +00:00
|
|
|
@utils.hook("received.command.msearch")
|
2020-01-30 16:31:38 +00:00
|
|
|
@utils.spec("!r~channel !<pattern>string")
|
2020-01-30 14:59:48 +00:00
|
|
|
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))
|
2020-01-30 14:59:48 +00:00
|
|
|
message_count = len(message_list)
|
|
|
|
|
|
|
|
if message_list:
|
|
|
|
messages = []
|
2020-01-30 15:13:15 +00:00
|
|
|
for i, message in enumerate(message_list):
|
2020-01-30 14:59:48 +00:00
|
|
|
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,
|
2020-01-30 21:12:31 +00:00
|
|
|
utils.datetime.format.to_pretty_time(seconds),
|
2020-01-30 14:59:48 +00:00
|
|
|
message.line.format()))
|
|
|
|
|
2020-01-30 15:37:10 +00:00
|
|
|
event["stdout"].write("%s: found: %s"
|
2020-01-30 15:13:15 +00:00
|
|
|
% (event["user"].nickname, "\n".join(messages)))
|
2020-01-30 14:59:48 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("%s: no messages found"
|
|
|
|
% event["user"].nickname)
|