m4pl1mp/plugins/tell_plugin.py
2022-02-01 22:44:42 -06:00

46 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
from datetime import datetime
import irc3
import re
TELL_RE = re.compile('maple.tell\s(.+?)\s(.+)')
###########################################################################################
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
#######################################################################################
def __init__(self, bot):
self.bot = bot
#######################################################################################
#######################################################################################
@irc3.event(irc3.rfc.PRIVMSG)
def on_privmsg_search_to_tell(self, mask=None, target=None, data=None, **kw):
if mask.nick.lower() == "maple":
return
messages_to_send = self.bot.db.getlist("tell_%s" % mask.nick.lower())
if messages_to_send:
msg = messages_to_send[0]
irc_message = "TCPDIRECT/TOLD: {} <{}> told <{}> {}".format(msg.get("time"),msg.get("from"),mask.nick,msg.get("message"))
self.bot.privmsg(target, self.bot.emo(irc_message))
self.bot.db.setlist("tell_%s" % mask.nick.lower(), messages_to_send[1:])
#######################################################################################
#######################################################################################
@irc3.event(irc3.rfc.PRIVMSG)
def on_privmsg_search_for_tell(self, mask=None, target=None, data=None, **kw):
match_list = TELL_RE.findall(data)
if len(match_list) > 0:
tell_nick, message = match_list[0]
if tell_nick == 'me' or tell_nick == 'us' or tell_nick == 'a' or tell_nick == 'some': return
message_list = self.bot.db.getlist("tell_%s" % tell_nick.lower())
new_message = {"from": mask.nick.lower(), "message": message, "time": datetime.now().isoformat() }
if not message_list:
message_list = self.bot.db.setlist("tell_%s" % tell_nick.lower(), [new_message])
else:
message_list.append(new_message)
self.bot.db.setlist("tell_%s" % tell_nick.lower(), message_list)
irc_message = "TCPDIRECT/TELL: {} <{}> telling <{}> {}".format(new_message.get("time"),new_message.get("from"),tell_nick,new_message.get("message"))
self.bot.privmsg(target, self.bot.emo(irc_message))
#######################################################################################
#######################################################################################
###########################################################################################
###########################################################################################