Cleanup, fixed some bugs (yt etc)

This commit is contained in:
mrhanky 2017-07-31 15:29:59 +02:00
parent 59b67d9570
commit 6ac0e94180
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
10 changed files with 75 additions and 67 deletions

8
.gitignore vendored
View File

@ -1,5 +1,5 @@
__pycache__/
.idea/
/.env
__pycache__
/config.json
/.env
/env
.idea/

View File

@ -46,8 +46,4 @@ def main(cfg_file):
if __name__ == '__main__':
if len(sys.argv) > 1:
config = sys.argv[1]
else:
config = 'config.json'
main(config)
main(sys.argv[1])

View File

@ -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):

View File

@ -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):

View File

@ -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)

View File

@ -1,5 +0,0 @@
# -*- coding: utf-8 -*-
import irc3d
if __name__ == '__main__':
irc3d.run()

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import re
import random
from typing import Tuple
from pprint import pprint
from datetime import datetime, timedelta
@ -34,7 +35,7 @@ def time_delta(text: str) -> timedelta:
return timedelta(**{unit: num})
def parse_int(val: str, select: bool = True) -> tuple:
def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
try:
val = int(val)
if val is not 0:

View File

@ -1,12 +1,13 @@
[Unit]
Description=nxy python irc bot
After=network.target znc.service
After=network.target
[Service]
Type=simple
User=nxy
WorkingDirectory=/home/nxy/bot
ExecStart=/home/nxy/.virtualenvs/nxy/bin/python -m bot
Restart=always
Environment=PYTHONPATH=%h/nxy
WorkingDirectory=/home/nxy/nxy
ExecStart=/home/nxy/nxy/env/bin/python -m bot config.json
[Install]
WantedBy=multi-user.target
WantedBy=default.target

Binary file not shown.

View File

@ -1,5 +1,4 @@
#git+https://github.com/gawel/irc3.git#egg=irc3
git+https://github.com/mrhanky17/irc3.git#egg=irc3
git+https://github.com/gawel/irc3.git#egg=irc3
psycopg2==2.7.1
requests==2.14.2
feedparser==5.2.1