Cleanup, fixed some bugs (yt etc)
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from irc3 import IrcBot
|
||||
from irc3.plugins.command import Commands
|
||||
|
||||
@ -20,7 +19,7 @@ class Plugin(BasePlugin):
|
||||
|
||||
|
||||
# Import the PgSQL storage plugin
|
||||
from .storage import Storage # noqa: E402
|
||||
from .storage import Storage # noqa
|
||||
|
||||
|
||||
class DatabasePlugin(Plugin):
|
||||
|
@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
import re
|
||||
|
||||
import irc3
|
||||
from docopt import Dict as DocOptDict
|
||||
@ -14,6 +13,14 @@ from ..utils import re_generator
|
||||
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
|
||||
RAINBOW_LEN = len(RAINBOW)
|
||||
|
||||
ISPS = (
|
||||
't-ipconnect',
|
||||
'telefonica',
|
||||
'vodafone',
|
||||
'kabel',
|
||||
'unity-media',
|
||||
)
|
||||
|
||||
|
||||
@irc3.plugin
|
||||
class Useless(DatabasePlugin):
|
||||
@ -26,10 +33,14 @@ class Useless(DatabasePlugin):
|
||||
'keep your woahs to yourself',
|
||||
)
|
||||
|
||||
@irc3.event(r'(?i)^:(?P<mask>\S+) JOIN :(?P<target>#\S+)$')
|
||||
def tehkuh(self, mask, target):
|
||||
if re.search(r'(?i).*(tehkuh).*@.*(telefonica|vodafone|kabel|unity-media).*', mask):
|
||||
self.bot.privmsg(target, '{}: Bouncer'.format(IrcString(mask).nick))
|
||||
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({isps})\S+) JOIN :(?P<target>#\S+)$'.format(isps='|'.join(ISPS)))
|
||||
def bounce(self, mask, target):
|
||||
nick = IrcString(mask).nick
|
||||
|
||||
if nick == self.bot.nick:
|
||||
return
|
||||
|
||||
self.bot.privmsg(target, '{}: Du musst bouncen!'.format(nick))
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(woah|whoa).*$')
|
||||
def woah(self, target: str):
|
||||
@ -93,7 +104,10 @@ class Useless(DatabasePlugin):
|
||||
1
|
||||
''')
|
||||
nick = args.get('<nick>') or mask.nick
|
||||
self.bot.action(target, self.cur.fetchone()['item'].format(nick))
|
||||
self.bot.action(target, self.cur.fetchone()['item'].format(
|
||||
nick=args.get('<nick>') or mask.nick,
|
||||
yiffer=mask.nick,
|
||||
))
|
||||
|
||||
@command
|
||||
def waifu(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
@ -108,13 +122,14 @@ class Useless(DatabasePlugin):
|
||||
|
||||
try:
|
||||
self.cur.execute('''
|
||||
insert into
|
||||
users (nick, waifu)
|
||||
values
|
||||
(lower(%s), %s)
|
||||
on conflict (nick) do update set
|
||||
waifu = excluded.waifu
|
||||
''', [mask.nick, waifu])
|
||||
insert into
|
||||
users (nick, waifu)
|
||||
values
|
||||
(lower(%s), %s)
|
||||
on conflict (nick) do update set
|
||||
waifu = excluded.waifu
|
||||
''', [mask.nick, waifu])
|
||||
self.con.commit()
|
||||
|
||||
self.bot.notice(mask.nick, 'Waifu set to: {}'.format(waifu))
|
||||
except Error as ex:
|
||||
@ -122,13 +137,13 @@ class Useless(DatabasePlugin):
|
||||
self.con.rollback()
|
||||
else:
|
||||
self.cur.execute('''
|
||||
select
|
||||
waifu
|
||||
from
|
||||
users
|
||||
where
|
||||
lower(nick) = lower(%s)
|
||||
''', [nick])
|
||||
select
|
||||
waifu
|
||||
from
|
||||
users
|
||||
where
|
||||
lower(nick) = lower(%s)
|
||||
''', [nick])
|
||||
result = self.cur.fetchone()
|
||||
|
||||
if result and result['waifu']:
|
||||
@ -147,13 +162,14 @@ class Useless(DatabasePlugin):
|
||||
|
||||
try:
|
||||
self.cur.execute('''
|
||||
insert into
|
||||
users (nick, husbando)
|
||||
values
|
||||
(lower(%s), %s)
|
||||
on conflict (nick) do update set
|
||||
husbando = excluded.husbando
|
||||
''', [mask.nick, nick])
|
||||
insert into
|
||||
users (nick, husbando)
|
||||
values
|
||||
(lower(%s), %s)
|
||||
on conflict (nick) do update set
|
||||
husbando = excluded.husbando
|
||||
''', [mask.nick, nick])
|
||||
self.con.commit()
|
||||
|
||||
self.bot.notice(mask.nick, 'Husbando set to: {}'.format(nick))
|
||||
except Error as ex:
|
||||
@ -161,13 +177,13 @@ class Useless(DatabasePlugin):
|
||||
self.con.rollback()
|
||||
else:
|
||||
self.cur.execute('''
|
||||
select
|
||||
husbando
|
||||
from
|
||||
users
|
||||
where
|
||||
lower(nick) = lower(%s)
|
||||
''', [nick])
|
||||
select
|
||||
husbando
|
||||
from
|
||||
users
|
||||
where
|
||||
lower(nick) = lower(%s)
|
||||
''', [nick])
|
||||
result = self.cur.fetchone()
|
||||
|
||||
if result and result['husbando']:
|
||||
@ -206,17 +222,18 @@ class Useless(DatabasePlugin):
|
||||
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Kisses a user.
|
||||
|
||||
%%kiss <nick>
|
||||
%%kiss [<nick>]
|
||||
|
||||
"""
|
||||
return '(づ。◕‿‿◕。)\x0304。。・゜゜・。。・゜❤\x0F {} \x0304❤'.format(args['<nick>'])
|
||||
return '(づ。◕‿‿◕。)\x0304。。・゜゜・。。・゜❤\x0F {} \x0304❤'.format(args.get('<nick>') or mask.nick)
|
||||
|
||||
@command
|
||||
def hug(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Hugs a user.
|
||||
|
||||
%%hug <nick>
|
||||
%%hug [<nick>]
|
||||
"""
|
||||
return '\x0304♥♡❤♡♥\x0F {} \x0304♥♡❤♡♥'.format(args['<nick>'])
|
||||
return '\x0304♥♡❤♡♥\x0F {} \x0304♥♡❤♡♥'.format(args.get('<nick>') or mask.nick)
|
||||
|
||||
@command
|
||||
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
@ -242,8 +259,7 @@ class Useless(DatabasePlugin):
|
||||
|
||||
%%anhero
|
||||
"""
|
||||
self.bot.privmsg(target, 'Sayonara bonzai-chan...')
|
||||
self.bot.kick(target, mask.nick)
|
||||
self.bot.kick(target, mask.nick, 'Sayonara bonzai-chan...')
|
||||
|
||||
@command
|
||||
def sudoku(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
|
@ -24,7 +24,7 @@ class YouTube(Plugin):
|
||||
"""Requests the infos for a video id and formats them."""
|
||||
data = self._api(self.API, id=video_id)
|
||||
|
||||
if not data['items']:
|
||||
if not data.get('items'):
|
||||
return
|
||||
|
||||
item = data['items'][0]
|
||||
@ -40,7 +40,8 @@ class YouTube(Plugin):
|
||||
except ZeroDivisionError:
|
||||
score = 0
|
||||
|
||||
return '{title} - length {length} -\x033 {likes:,}\x03 /' \
|
||||
return '\x02[YouTube]\x0F ' \
|
||||
'{title} - length {length} -\x033 {likes:,}\x03 /' \
|
||||
'\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \
|
||||
'views - {channel} on {date}' \
|
||||
.format(title=item['snippet']['title'],
|
||||
@ -52,7 +53,7 @@ class YouTube(Plugin):
|
||||
views=views,
|
||||
date=date.strftime('%Y.%m.%d'))
|
||||
|
||||
@irc3.event(r'(?i)^:.* PRIVMSG (?P<target>.*) :.*(?:youtube.*?(?:v=|/v/)'
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?:youtube.*?(?:v=|/v/)'
|
||||
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')
|
||||
def youtube_parser(self, target: str, video_id: str):
|
||||
data = self.get_video_data(video_id)
|
||||
|
Reference in New Issue
Block a user