nxy/bot/useless.py

335 lines
9.9 KiB
Python
Raw Normal View History

2017-05-15 22:26:10 +00:00
# -*- coding: utf-8 -*-
2017-05-16 10:06:29 +00:00
import random
2017-08-22 12:57:07 +00:00
import re
2017-05-16 10:06:29 +00:00
2017-06-30 12:09:46 +00:00
import irc3
2017-08-22 13:57:57 +00:00
from docopt import Dict
2017-05-15 22:26:10 +00:00
from irc3.plugins.command import command
from irc3.utils import IrcString
from psycopg2 import Error
2017-05-15 22:26:10 +00:00
from . import DatabasePlugin
2017-08-22 15:43:48 +00:00
from .utils import re_generator
2017-05-15 22:26:10 +00:00
class Useless(DatabasePlugin):
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
2017-07-04 13:22:20 +00:00
WOAH = (
'woah',
'woah indeed',
'woah woah woah!',
'keep your woahs to yourself',
)
ISPS = (
't-ipconnect',
'telefonica',
'vodafone',
'kabel',
'unity-media',
)
GENDERS = (
'male',
'female',
'shemale',
'hermaphrodite',
)
2017-08-16 12:39:44 +00:00
@command(permission='admin', show_in_help=False)
2017-08-22 13:57:57 +00:00
def kim(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-16 12:39:44 +00:00
"""Kicks Kim, most useful command.
%%kim
"""
self.bot.kick(target, 'Kim')
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({})\S+) JOIN :(?P<target>#\S+)$'.format('|'.join(ISPS)))
2017-07-31 13:29:59 +00:00
def bounce(self, mask, target):
nick = IrcString(mask).nick
2017-08-22 13:16:29 +00:00
if target == '#w0bm' and nick != self.bot.nick:
self.bot.privmsg(target, '{}: Du musst bouncen!'.format(nick))
2017-07-06 16:37:28 +00:00
2017-07-04 13:22:20 +00:00
@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))
2017-05-15 22:26:10 +00:00
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?P<msg>huehuehue)$')
def huehuehue(self, target: str, msg: str):
2017-05-30 10:56:20 +00:00
"""Returns a huehuehue when someone writes it."""
self.bot.privmsg(target, msg)
2017-07-07 00:11:20 +00:00
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :re+$')
def reeeeee(self, target: str):
2017-05-31 12:07:57 +00:00
"""Returns a REEEE."""
2017-07-07 00:11:20 +00:00
self.bot.privmsg(target, re_generator())
2017-05-31 12:07:57 +00:00
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :same$')
def same(self, target: str):
2017-05-30 10:56:20 +00:00
"""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):
2017-05-30 10:56:20 +00:00
"""String with brackets around will be returned with INTENSIFIES."""
2017-07-07 00:11:20 +00:00
self.bot.privmsg(target, '\x02[{} INTENSIFIES]'.format(msg.upper()))
@command
2017-08-22 13:57:57 +00:00
def kill(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Kills a user with a random message
%%kill [<nick>]
"""
self.cur.execute('''
2017-08-16 12:39:44 +00:00
SELECT
item
2017-08-16 12:39:44 +00:00
FROM
kills
2017-08-16 12:39:44 +00:00
ORDER BY
random()
2017-08-16 12:39:44 +00:00
LIMIT
1
''')
2017-07-31 16:11:44 +00:00
self.bot.action(target, self.cur.fetchone()['item'].format(
nick=args.get('<nick>', mask.nick),
2017-07-31 16:11:44 +00:00
))
@command
2017-08-22 13:57:57 +00:00
def yiff(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Yiffs a user with a random message
%%yiff [<nick>]
"""
self.cur.execute('''
2017-08-16 12:39:44 +00:00
SELECT
item
2017-08-16 12:39:44 +00:00
FROM
yiffs
2017-08-16 12:39:44 +00:00
ORDER BY
random()
2017-08-16 12:39:44 +00:00
LIMIT
1
''')
2017-07-31 13:29:59 +00:00
self.bot.action(target, self.cur.fetchone()['item'].format(
nick=args.get('<nick>', mask.nick),
2017-07-31 13:29:59 +00:00
yiffer=mask.nick,
))
2017-06-30 17:33:26 +00:00
@command
2017-08-22 13:57:57 +00:00
def waifu(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:19:57 +00:00
"""Get waifu for a user (set with prefixing the user with =)
2017-06-30 17:33:26 +00:00
2017-07-04 13:22:20 +00:00
%%waifu [<nick>...]
2017-06-30 17:33:26 +00:00
"""
return self.husbando_waifu('waifu', mask, target, args)
2017-06-30 17:33:26 +00:00
@command
2017-08-22 13:57:57 +00:00
def husbando(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:19:57 +00:00
"""Get husbando for a user (set with prefixing the user with =)
2017-06-30 17:33:26 +00:00
2017-07-04 13:22:20 +00:00
%%husbando [<nick>...]
2017-06-30 17:33:26 +00:00
"""
return self.husbando_waifu('husbando', mask, target, args)
2017-06-30 17:33:26 +00:00
@command
2017-08-22 13:57:57 +00:00
def storyofpomfface(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Story of pomf face
2017-05-16 12:27:34 +00:00
%%storyofpomfface
"""
for face in (':O C==3', ':OC==3', ':C==3', ':C=3', ':C3', ':3'):
self.bot.privmsg(target, face)
2017-05-29 11:29:23 +00:00
@command
2017-08-22 13:57:57 +00:00
def choose(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Decides between items (separated by comma)
2017-05-29 11:29:23 +00:00
%%choose <items>...
"""
choice = random.choice(' '.join(args['<items>']).split(','))
2017-07-07 00:11:20 +00:00
return '{}: {}'.format(mask.nick, choice.strip())
2017-05-29 11:29:23 +00:00
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def jn(self, mask: IrcString, target: IrcString, args: Dict):
2017-05-28 12:07:35 +00:00
"""Decides between yes and no (for a question).
2017-05-16 12:27:34 +00:00
%%jn <question>...
2017-05-16 06:54:47 +00:00
%%jn
2017-05-15 22:26:10 +00:00
"""
2017-06-01 15:38:34 +00:00
choice = random.choice(['3Ja', '4Nein'])
2017-07-07 00:11:20 +00:00
return '{}: \x02\x030{}'.format(mask.nick, choice)
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def kiss(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Kisses a user
2017-05-28 11:27:40 +00:00
2017-07-31 13:29:59 +00:00
%%kiss [<nick>]
2017-05-15 22:26:10 +00:00
"""
2017-08-22 13:16:29 +00:00
return '(づ。◕‿‿◕。)\x0304。。・゜゜・。。・゜❤\x03 {} \x0304❤'.format(args.get('<nick>', mask.nick))
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def hug(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Hugs a user
2017-05-28 11:27:40 +00:00
2017-07-31 13:29:59 +00:00
%%hug [<nick>]
2017-05-15 22:26:10 +00:00
"""
2017-08-22 13:16:29 +00:00
return '\x0304♥♡❤♡♥\x03 {} \x0304♥♡❤♡♥'.format(args.get('<nick>', mask.nick))
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def bier(self, mask: IrcString, target: IrcString, args: Dict):
"""Gives a user a beer
2017-06-01 15:38:34 +00:00
%%bier [<nick>]
"""
nick = args.get('<nick>', mask.nick)
2017-07-07 00:11:20 +00:00
self.bot.action(target, 'schenkt ein kühles Blondes an {} aus.'.format(nick))
@command
2017-08-22 13:57:57 +00:00
def fucken(self, mask: IrcString, target: IrcString, args: Dict):
"""Kills and fucks a user
2017-06-01 15:38:34 +00:00
%%fucken [<nick>]
"""
nick = args.get('<nick>', mask.nick)
2017-07-07 00:11:20 +00:00
self.bot.action(target, 'fuckt {0} und tötet {0} anschließend.'.format(nick, nick))
@command(aliases=['anhero', 'sudoku'])
2017-08-22 13:57:57 +00:00
def seppuku(self, mask: IrcString, target: IrcString, args: Dict):
"""Kicks a user
%%seppuku
"""
2017-07-31 13:29:59 +00:00
self.bot.kick(target, mask.nick, 'Sayonara bonzai-chan...')
@command
2017-08-22 13:57:57 +00:00
def hack(self, mask: IrcString, target: IrcString, args: Dict):
"""Hacks (a user)
2017-05-28 11:27:40 +00:00
%%hack [<nick>]
"""
nick = args.get('<nick>')
2017-07-07 00:11:20 +00:00
return 'hacking{}...'.format(' %s' % nick if nick else '')
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def gay(self, mask: IrcString, target: IrcString, args: Dict):
2017-05-16 12:27:34 +00:00
"""Make someone gay (alias to rainbow)
2017-05-28 11:27:40 +00:00
2017-05-15 22:26:10 +00:00
%%gay <word>...
"""
return self.rainbow(mask, target, args)
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def rainbow(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Colorize a word in rainbow colors
2017-05-28 11:27:40 +00:00
2017-05-15 22:26:10 +00:00
%%rainbow <word>...
"""
last = 0
word = []
2017-05-30 10:56:20 +00:00
for char in ' '.join(args.get('<word>')):
2017-05-15 22:26:10 +00:00
if char != ' ':
2017-05-29 16:44:26 +00:00
char = self._rainbow(last, char)
2017-05-15 22:26:10 +00:00
last += 1
word.append(char)
2017-05-29 16:44:26 +00:00
return ''.join(word)
2017-05-15 22:26:10 +00:00
@command
2017-08-22 13:57:57 +00:00
def wrainbow(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Colorize words in a sentence with rainbow colors
2017-05-16 12:27:34 +00:00
2017-05-15 22:26:10 +00:00
%%wrainbow <words>...
"""
2017-07-07 00:11:20 +00:00
return ' '.join([self._rainbow(i, word) for i, word in enumerate(args['<words>'])])
2017-05-29 16:44:26 +00:00
2017-08-22 14:23:54 +00:00
@command(aliases=['hw'])
2017-08-22 13:57:57 +00:00
def halfwidth(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 12:57:07 +00:00
"""Turns UPPERCASE words into halfwidth characters
2017-08-22 13:16:29 +00:00
%%halfwidth <words>...
2017-08-22 12:57:07 +00:00
"""
2017-08-22 13:16:29 +00:00
def replace(match):
2017-08-22 13:08:33 +00:00
return ''.join(chr(0xFF20 + (ord(c) - 64)) for c in match.group(0))
2017-08-22 13:16:29 +00:00
return '\x02[HALFWIDTH]\x02 {}'.format(re.sub(r'(?:\b)[A-Z]+(?:\b)', replace, ' '.join(args['<words>'])))
2017-08-22 12:57:07 +00:00
@command
2017-08-22 13:57:57 +00:00
def asshole(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Checks how much of an asshole you are
2017-08-18 09:31:56 +00:00
%%asshole [<nick>]
"""
nick = args.get('<nick>', mask.nick)
2017-08-18 09:31:56 +00:00
2017-08-22 09:31:32 +00:00
if nick.lower() == 'mrhanky':
2017-08-21 16:33:26 +00:00
perc_min = 100
2017-08-22 09:31:32 +00:00
elif nick.lower() == 'flummi':
2017-08-21 16:33:26 +00:00
perc_min = 90
else:
perc_min = 0
2017-08-18 09:31:56 +00:00
2017-08-21 16:33:26 +00:00
asshole_perc = random.randint(perc_min, 100)
2017-08-21 11:38:31 +00:00
return 'Asshole scan... {} is {}% of an asshole.'.format(nick, asshole_perc)
2017-08-18 09:31:56 +00:00
2017-08-18 10:01:06 +00:00
@command
2017-08-22 13:57:57 +00:00
def assume(self, mask: IrcString, target: IrcString, args: Dict):
2017-08-22 13:16:29 +00:00
"""Assumes the gender of a nick or yourself
2017-08-18 10:01:06 +00:00
%%assume [<nick>]
"""
nick = args.get('<nick>', mask.nick)
gender = random.choice(self.GENDERS)
2017-08-18 10:01:06 +00:00
2017-08-21 16:24:39 +00:00
return 'Assuming {}\'s gender... they\'re a {}.'.format(nick, gender)
2017-08-18 10:01:06 +00:00
2017-08-22 14:23:54 +00:00
@command
def spit(self, mask: IrcString, target: IrcString, args: Dict):
"""Spits a user
%%spit [<nick>]
"""
nick = args.get('<nick>', mask.nick)
self.bot.action(target, 'spits on {} like a dirty whore.'.format(nick))
2017-08-22 13:57:57 +00:00
def husbando_waifu(self, field: str, mask: IrcString, target: IrcString, args: Dict):
nick = args.get('<nick>', mask.nick)
if isinstance(nick, list):
nick = ' '.join(nick)
if nick.startswith('='):
nick = nick[1:]
try:
self.cur.execute('''
INSERT INTO
users (nick, {0})
VALUES
(lower(%s), %s)
ON CONFLICT (nick) DO UPDATE SET
{0} = excluded.{0}
'''.format(field), [mask.nick, nick])
self.con.commit()
self.bot.notice(mask.nick, '{} set to: {}'.format(field.title(), nick))
except Error as ex:
self.log.error(ex)
self.con.rollback()
else:
self.cur.execute('''
SELECT
{}
FROM
users
WHERE
lower(nick) = lower(%s)
'''.format(field), [nick])
result = self.cur.fetchone()
if result and result[field]:
return '\x02[{}]\x02 {}: {}'.format(field.title(), nick, result[field])
2017-07-07 00:11:20 +00:00
# noinspection PyMethodMayBeStatic
2017-07-04 13:22:20 +00:00
def _rainbow(self, i, char):
return '\x03{0:02d}{1}'.format(self.RAINBOW[i % len(self.RAINBOW)], char)