Cleanup, fixed some bugs (yt etc)
This commit is contained in:
parent
59b67d9570
commit
6ac0e94180
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
||||||
__pycache__/
|
__pycache__
|
||||||
.idea/
|
|
||||||
|
|
||||||
/.env
|
|
||||||
/config.json
|
/config.json
|
||||||
|
/.env
|
||||||
|
/env
|
||||||
|
.idea/
|
||||||
|
|
|
@ -46,8 +46,4 @@ def main(cfg_file):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
main(sys.argv[1])
|
||||||
config = sys.argv[1]
|
|
||||||
else:
|
|
||||||
config = 'config.json'
|
|
||||||
main(config)
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from irc3 import IrcBot
|
from irc3 import IrcBot
|
||||||
from irc3.plugins.command import Commands
|
from irc3.plugins.command import Commands
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ class Plugin(BasePlugin):
|
||||||
|
|
||||||
|
|
||||||
# Import the PgSQL storage plugin
|
# Import the PgSQL storage plugin
|
||||||
from .storage import Storage # noqa: E402
|
from .storage import Storage # noqa
|
||||||
|
|
||||||
|
|
||||||
class DatabasePlugin(Plugin):
|
class DatabasePlugin(Plugin):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- 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
|
||||||
|
@ -14,6 +13,14 @@ from ..utils import re_generator
|
||||||
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
|
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
|
||||||
RAINBOW_LEN = len(RAINBOW)
|
RAINBOW_LEN = len(RAINBOW)
|
||||||
|
|
||||||
|
ISPS = (
|
||||||
|
't-ipconnect',
|
||||||
|
'telefonica',
|
||||||
|
'vodafone',
|
||||||
|
'kabel',
|
||||||
|
'unity-media',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@irc3.plugin
|
@irc3.plugin
|
||||||
class Useless(DatabasePlugin):
|
class Useless(DatabasePlugin):
|
||||||
|
@ -26,10 +33,14 @@ class Useless(DatabasePlugin):
|
||||||
'keep your woahs to yourself',
|
'keep your woahs to yourself',
|
||||||
)
|
)
|
||||||
|
|
||||||
@irc3.event(r'(?i)^:(?P<mask>\S+) JOIN :(?P<target>#\S+)$')
|
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({isps})\S+) JOIN :(?P<target>#\S+)$'.format(isps='|'.join(ISPS)))
|
||||||
def tehkuh(self, mask, target):
|
def bounce(self, mask, target):
|
||||||
if re.search(r'(?i).*(tehkuh).*@.*(telefonica|vodafone|kabel|unity-media).*', mask):
|
nick = IrcString(mask).nick
|
||||||
self.bot.privmsg(target, '{}: Bouncer'.format(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).*$')
|
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(woah|whoa).*$')
|
||||||
def woah(self, target: str):
|
def woah(self, target: str):
|
||||||
|
@ -93,7 +104,10 @@ class Useless(DatabasePlugin):
|
||||||
1
|
1
|
||||||
''')
|
''')
|
||||||
nick = args.get('<nick>') or mask.nick
|
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
|
@command
|
||||||
def waifu(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def waifu(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
@ -108,13 +122,14 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
insert into
|
||||||
users (nick, waifu)
|
users (nick, waifu)
|
||||||
values
|
values
|
||||||
(lower(%s), %s)
|
(lower(%s), %s)
|
||||||
on conflict (nick) do update set
|
on conflict (nick) do update set
|
||||||
waifu = excluded.waifu
|
waifu = excluded.waifu
|
||||||
''', [mask.nick, waifu])
|
''', [mask.nick, waifu])
|
||||||
|
self.con.commit()
|
||||||
|
|
||||||
self.bot.notice(mask.nick, 'Waifu set to: {}'.format(waifu))
|
self.bot.notice(mask.nick, 'Waifu set to: {}'.format(waifu))
|
||||||
except Error as ex:
|
except Error as ex:
|
||||||
|
@ -122,13 +137,13 @@ class Useless(DatabasePlugin):
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
else:
|
else:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
select
|
||||||
waifu
|
waifu
|
||||||
from
|
from
|
||||||
users
|
users
|
||||||
where
|
where
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
if result and result['waifu']:
|
if result and result['waifu']:
|
||||||
|
@ -147,13 +162,14 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
insert into
|
||||||
users (nick, husbando)
|
users (nick, husbando)
|
||||||
values
|
values
|
||||||
(lower(%s), %s)
|
(lower(%s), %s)
|
||||||
on conflict (nick) do update set
|
on conflict (nick) do update set
|
||||||
husbando = excluded.husbando
|
husbando = excluded.husbando
|
||||||
''', [mask.nick, nick])
|
''', [mask.nick, nick])
|
||||||
|
self.con.commit()
|
||||||
|
|
||||||
self.bot.notice(mask.nick, 'Husbando set to: {}'.format(nick))
|
self.bot.notice(mask.nick, 'Husbando set to: {}'.format(nick))
|
||||||
except Error as ex:
|
except Error as ex:
|
||||||
|
@ -161,13 +177,13 @@ class Useless(DatabasePlugin):
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
else:
|
else:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
select
|
||||||
husbando
|
husbando
|
||||||
from
|
from
|
||||||
users
|
users
|
||||||
where
|
where
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
if result and result['husbando']:
|
if result and result['husbando']:
|
||||||
|
@ -206,17 +222,18 @@ class Useless(DatabasePlugin):
|
||||||
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Kisses a user.
|
"""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
|
@command
|
||||||
def hug(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def hug(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Hugs a user.
|
"""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
|
@command
|
||||||
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
@ -242,8 +259,7 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
%%anhero
|
%%anhero
|
||||||
"""
|
"""
|
||||||
self.bot.privmsg(target, 'Sayonara bonzai-chan...')
|
self.bot.kick(target, mask.nick, 'Sayonara bonzai-chan...')
|
||||||
self.bot.kick(target, mask.nick)
|
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def sudoku(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
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."""
|
"""Requests the infos for a video id and formats them."""
|
||||||
data = self._api(self.API, id=video_id)
|
data = self._api(self.API, id=video_id)
|
||||||
|
|
||||||
if not data['items']:
|
if not data.get('items'):
|
||||||
return
|
return
|
||||||
|
|
||||||
item = data['items'][0]
|
item = data['items'][0]
|
||||||
|
@ -40,7 +40,8 @@ class YouTube(Plugin):
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
score = 0
|
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:,} ' \
|
'\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \
|
||||||
'views - {channel} on {date}' \
|
'views - {channel} on {date}' \
|
||||||
.format(title=item['snippet']['title'],
|
.format(title=item['snippet']['title'],
|
||||||
|
@ -52,7 +53,7 @@ class YouTube(Plugin):
|
||||||
views=views,
|
views=views,
|
||||||
date=date.strftime('%Y.%m.%d'))
|
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]+).*')
|
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')
|
||||||
def youtube_parser(self, target: str, video_id: str):
|
def youtube_parser(self, target: str, video_id: str):
|
||||||
data = self.get_video_data(video_id)
|
data = self.get_video_data(video_id)
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import irc3d
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
irc3d.run()
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
|
from typing import Tuple
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ def time_delta(text: str) -> timedelta:
|
||||||
return timedelta(**{unit: num})
|
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:
|
try:
|
||||||
val = int(val)
|
val = int(val)
|
||||||
if val is not 0:
|
if val is not 0:
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=nxy python irc bot
|
Description=nxy python irc bot
|
||||||
After=network.target znc.service
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=nxy
|
Restart=always
|
||||||
WorkingDirectory=/home/nxy/bot
|
Environment=PYTHONPATH=%h/nxy
|
||||||
ExecStart=/home/nxy/.virtualenvs/nxy/bin/python -m bot
|
WorkingDirectory=/home/nxy/nxy
|
||||||
|
ExecStart=/home/nxy/nxy/env/bin/python -m bot config.json
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=default.target
|
||||||
|
|
BIN
files/old.db
BIN
files/old.db
Binary file not shown.
|
@ -1,5 +1,4 @@
|
||||||
#git+https://github.com/gawel/irc3.git#egg=irc3
|
git+https://github.com/gawel/irc3.git#egg=irc3
|
||||||
git+https://github.com/mrhanky17/irc3.git#egg=irc3
|
|
||||||
psycopg2==2.7.1
|
psycopg2==2.7.1
|
||||||
requests==2.14.2
|
requests==2.14.2
|
||||||
feedparser==5.2.1
|
feedparser==5.2.1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user