TehKuh regex, rollback and print(exception) for waifu

This commit is contained in:
mrhanky 2017-07-06 19:06:38 +02:00
parent 71ab473f01
commit 3e86c605f8
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8

View File

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
import random
import re
import irc3
from docopt import Dict as DocOptDict
from irc3.plugins.command import command
from irc3.utils import IrcString
from psycopg2 import Error
from . import DatabasePlugin
@ -23,17 +25,9 @@ class Useless(DatabasePlugin):
'keep your woahs to yourself',
)
ISP_HOSTS = (
'vodafone',
'telefonica',
'kabel',
'unity-media',
)
@irc3.event(r'(?i)^:(?P<mask>\S+) JOIN :(?P<target>#\S+)$')
def tehkuh(self, mask, target):
nick = IrcString(mask).nick
if 'TehKuh' in mask.lower() and self.ISP_HOSTS in mask.lower():
if re.search(r'(?i).*(tehkuh).*@.*(telefonica|vodafone|kabel|unity-media).*', mask):
self.bot.privmsg(target, '{}: Bouncer'.format(nick))
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(woah|whoa).*$')
@ -112,17 +106,21 @@ class Useless(DatabasePlugin):
if nick.startswith('='):
waifu = nick[1:]
self.cur.execute('''
insert into
users (nick, waifu)
values
(%s, %s)
on conflict (nick) do update set
waifu = excluded.waifu
''', [mask.nick, waifu])
try:
self.cur.execute('''
insert into
users (nick, waifu)
values
(%s, %s)
on conflict (nick) do update set
waifu = excluded.waifu
''', [mask.nick, waifu])
self.bot.notice(mask.nick, 'Waifu set to: {waifu}'
.format(waifu=waifu))
self.bot.notice(mask.nick, 'Waifu set to: {waifu}'
.format(waifu=waifu))
except Error as ex:
print(ex)
self.con.rollback()
else:
self.cur.execute('''
select