nxy/bot/plugins/useless.py
2017-07-31 15:29:59 +02:00

315 lines
9.2 KiB
Python

# -*- coding: utf-8 -*-
import random
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
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):
requires = ['irc3.plugins.command',
'bot.plugins.storage']
WOAH = (
'woah',
'woah indeed',
'woah woah woah!',
'keep your woahs to yourself',
)
@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):
"""Colorize words in a sentence with rainbow colors."""
if random.randint(0, 4) is 0:
self.bot.privmsg(target, random.choice(self.WOAH))
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?P<msg>huehuehue)$')
def huehuehue(self, target: str, msg: str):
"""Returns a huehuehue when someone writes it."""
self.bot.privmsg(target, msg)
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :re+$')
def reeeeee(self, target: str):
"""Returns a REEEE."""
self.bot.privmsg(target, re_generator())
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :same$')
def same(self, target: str):
"""Returns a plain same when a user writes same."""
self.bot.privmsg(target, 'same')
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :\[(?P<msg>.*)\]$')
def intensifies(self, target: str, msg: str):
"""String with brackets around will be returned with INTENSIFIES."""
self.bot.privmsg(target, '\x02[{} INTENSIFIES]'.format(msg.upper()))
@command
def kill(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kills a user with a random message.
%%kill [<nick>]
"""
self.cur.execute('''
select
item
from
kills
order by
random()
limit
1
''')
nick = args.get('<nick>') or mask.nick
self.bot.action(target, self.cur.fetchone()['item'].format(nick))
@command
def yiff(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Yiffs a user with a random message.
%%yiff [<nick>]
"""
self.cur.execute('''
select
item
from
yiffs
order by
random()
limit
1
''')
nick = args.get('<nick>') or mask.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):
"""Get waifu for a user.
%%waifu [<nick>...]
"""
nick = ' '.join(args.get('<nick>')) or mask.nick
if nick.startswith('='):
waifu = nick[1:]
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])
self.con.commit()
self.bot.notice(mask.nick, 'Waifu set to: {}'.format(waifu))
except Error as ex:
print(ex)
self.con.rollback()
else:
self.cur.execute('''
select
waifu
from
users
where
lower(nick) = lower(%s)
''', [nick])
result = self.cur.fetchone()
if result and result['waifu']:
return '\x02[Waifu]\x0F {}: {}'.format(nick, result['waifu'])
@command
def husbando(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Get husbando for a user.
%%husbando [<nick>...]
"""
nick = ' '.join(args.get('<nick>')) or mask.nick
if nick.startswith('='):
nick = nick[1:]
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])
self.con.commit()
self.bot.notice(mask.nick, 'Husbando set to: {}'.format(nick))
except Error as ex:
print(ex)
self.con.rollback()
else:
self.cur.execute('''
select
husbando
from
users
where
lower(nick) = lower(%s)
''', [nick])
result = self.cur.fetchone()
if result and result['husbando']:
return '\x02[Husbando]\x0F {}: {}'.format(nick, result['husbando'])
@command
def storyofpomfface(self, mask: IrcString, target: IrcString,
args: DocOptDict):
"""Story of pomf face.
%%storyofpomfface
"""
for face in (':O C==3', ':OC==3', ':C==3', ':C=3', ':C3', ':3'):
self.bot.privmsg(target, face)
@command
def choose(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Decides between items separated by comma.
%%choose <items>...
"""
choice = random.choice(' '.join(args['<items>']).split(','))
return '{}: {}'.format(mask.nick, choice.strip())
@command
def jn(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Decides between yes and no (for a question).
%%jn <question>...
%%jn
"""
choice = random.choice(['3Ja', '4Nein'])
return '{}: \x02\x030{}'.format(mask.nick, choice)
@command
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kisses a user.
%%kiss [<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>]
"""
return '\x0304♥♡❤♡♥\x0F {} \x0304♥♡❤♡♥'.format(args.get('<nick>') or mask.nick)
@command
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Gives nick a beer.
%%bier [<nick>]
"""
nick = args.get('<nick>') or mask.nick
self.bot.action(target, 'schenkt ein kühles Blondes an {} aus.'.format(nick))
@command
def fucken(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kills and fucks a nick.
%%fucken [<nick>]
"""
nick = args.get('<nick>') or mask.nick
self.bot.action(target, 'fuckt {0} und tötet {0} anschließend.'.format(nick, nick))
@command
def anhero(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kicks a nick.
%%anhero
"""
self.bot.kick(target, mask.nick, 'Sayonara bonzai-chan...')
@command
def sudoku(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kicks a nick.
%%sudoku
"""
self.anhero(mask, target, args)
@command
def hack(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Hacks (a user).
%%hack [<nick>]
"""
nick = args.get('<nick>') or ''
return 'hacking{}...'.format(' %s' % nick if nick else '')
@command
def gay(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Make someone gay (alias to rainbow)
%%gay <word>...
"""
return self.rainbow(mask, target, args)
@command
def rainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Colorize a word in rainbow colors.
%%rainbow <word>...
"""
last = 0
word = []
for char in ' '.join(args.get('<word>')):
if char != ' ':
char = self._rainbow(last, char)
last += 1
word.append(char)
return ''.join(word)
@command
def wrainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Colorize words in a sentence with rainbow colors.
%%wrainbow <words>...
"""
return ' '.join([self._rainbow(i, word) for i, word in enumerate(args['<words>'])])
# noinspection PyMethodMayBeStatic
def _rainbow(self, i, char):
return '\x030{}{}'.format(RAINBOW[i % RAINBOW_LEN], char)