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