tell: fix sending unique constraint violating message multiple times

This commit is contained in:
jkhsjdhjs 2021-03-09 15:16:39 +00:00
parent 31631e3e4d
commit 452796556f

View File

@ -39,10 +39,6 @@ class Tell(DatabasePlugin):
nick = args['<nick>'].lower() nick = args['<nick>'].lower()
tell = [nick, mask.nick, ' '.join(args['<message>']).strip(), datetime.utcnow()] tell = [nick, mask.nick, ' '.join(args['<message>']).strip(), datetime.utcnow()]
if nick not in self.tell_queue:
self.tell_queue[nick] = []
self.tell_queue[nick].append(tell[1:])
try: try:
with self.con.cursor() as cur: with self.con.cursor() as cur:
cur.execute(''' cur.execute('''
@ -52,13 +48,15 @@ class Tell(DatabasePlugin):
(%s, %s, %s, %s) (%s, %s, %s, %s)
''', tell) ''', tell)
self.con.commit() self.con.commit()
if nick not in self.tell_queue:
self.tell_queue[nick] = []
self.tell_queue[nick].append(tell[1:])
self.bot.notice(mask.nick, "I will tell that to {} when I see them.".format(nick)) self.bot.notice(mask.nick, "I will tell that to {} when I see them.".format(nick))
except Error as ex: except Error as ex:
self.log.error(ex) self.log.error(ex)
self.con.rollback() self.con.rollback()
self.bot.notice(mask.nick, "database error") self.bot.notice(mask.nick, "database error (is the user already awaiting such a message?)")
@irc3.event(r'(?i)^:(?P<mask>.*) PRIVMSG .* :.*') @irc3.event(r'(?i)^:(?P<mask>.*) PRIVMSG .* :.*')
def on_message(self, mask: str): def on_message(self, mask: str):