nxy/nxy/plugins/useless.py

309 lines
9.2 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
import re
2017-05-16 10:06:29 +00:00
2017-06-30 12:09:46 +00:00
import irc3
2017-05-15 22:26:10 +00:00
from docopt import Dict as DocOptDict
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-05-15 22:26:10 +00:00
2017-07-04 13:22:20 +00:00
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
2017-05-15 22:26:10 +00:00
RAINBOW_LEN = len(RAINBOW)
2017-05-16 05:45:10 +00:00
@irc3.plugin
class Useless(DatabasePlugin):
requires = ['irc3.plugins.command',
'nxy.plugins.storage']
2017-07-04 13:22:20 +00:00
WOAH = (
'woah',
'woah indeed',
'woah woah woah!',
'keep your woahs to yourself',
)
2017-07-06 16:37:28 +00:00
@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):
2017-07-06 16:37:28 +00:00
self.bot.privmsg(target, '{}: Bouncer'.format(nick))
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)
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :reeeeee$')
def reeeeee(self, target: str):
2017-05-31 12:07:57 +00:00
"""Returns a REEEE."""
self.bot.privmsg(target, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEE')
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."""
self.bot.privmsg(target, '\x02[{msg} INTENSIFIES]'.format(
2017-05-29 21:21:42 +00:00
msg=msg.upper()))
@command
2017-06-30 17:33:26 +00:00
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
''')
2017-07-04 13:22:20 +00:00
self.bot.action(target, self.cur.fetchone()['item']
.format(nick=args.get('<nick>') or mask.nick))
@command
2017-06-30 17:33:26 +00:00
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
''')
2017-07-04 13:22:20 +00:00
self.bot.action(target, self.cur.fetchone()['item']
.format(nick=args.get('<nick>') or mask.nick))
2017-06-30 17:33:26 +00:00
@command
def waifu(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Get waifu for a user.
2017-07-04 13:22:20 +00:00
%%waifu [<nick>...]
2017-06-30 17:33:26 +00:00
"""
2017-07-04 13:22:20 +00:00
nick = ' '.join(args.get('<nick>')) or mask.nick
2017-06-30 17:33:26 +00:00
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.bot.notice(mask.nick, 'Waifu set to: {waifu}'
.format(waifu=waifu))
except Error as ex:
print(ex)
self.con.rollback()
2017-06-30 17:33:26 +00:00
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 {nick}: {waifu}'.format(
nick=nick,
waifu=result['waifu'])
@command
def husbando(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Get husbando for a user.
2017-07-04 13:22:20 +00:00
%%husbando [<nick>...]
2017-06-30 17:33:26 +00:00
"""
2017-07-04 13:22:20 +00:00
nick = ' '.join(args.get('<nick>')) or mask.nick
2017-06-30 17:33:26 +00:00
if nick.startswith('='):
2017-07-04 13:22:20 +00:00
nick = nick[1:]
2017-06-30 17:33:26 +00:00
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.bot.notice(mask.nick, 'Husbando set to: {husbando}'
.format(husbando=nick))
except Error:
print(ex)
self.con.rollback()
2017-06-30 17:33:26 +00:00
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 {nick}: {husbando}'.format(
nick=nick,
husbando=result['husbando'])
@command
def storyofpomfface(self, mask: IrcString, target: IrcString,
args: DocOptDict):
2017-05-28 12:07:35 +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
def choose(self, mask: IrcString, target: IrcString, args: DocOptDict):
2017-05-29 11:29:23 +00:00
"""Decides between items separated by comma.
%%choose <items>...
"""
choice = random.choice(' '.join(args['<items>']).split(','))
2017-06-30 18:14:02 +00:00
return '{nick}: {choice}'.format(nick=mask.nick,
choice=choice.strip())
2017-05-29 11:29:23 +00:00
2017-05-15 22:26:10 +00:00
@command
def jn(self, mask: IrcString, target: IrcString, args: DocOptDict):
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'])
return '{nick}: \x02\x03{choice}\x0F'.format(nick=mask.nick,
choice=choice)
2017-05-15 22:26:10 +00:00
@command
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
2017-05-28 12:07:35 +00:00
"""Kisses a user.
2017-05-28 11:27:40 +00:00
2017-05-15 22:26:10 +00:00
%%kiss <nick>
"""
2017-06-01 15:38:34 +00:00
return '(づ。◕‿‿◕。)\x034。。・゜゜・。。・゜❤\x0F {nick} \x034❤'.format(
2017-05-29 16:44:26 +00:00
nick=args['<nick>'])
2017-05-15 22:26:10 +00:00
@command
def hug(self, mask: IrcString, target: IrcString, args: DocOptDict):
2017-05-28 12:07:35 +00:00
"""Hugs a user.
2017-05-28 11:27:40 +00:00
2017-05-15 22:26:10 +00:00
%%hug <nick>
"""
2017-06-01 15:38:34 +00:00
return '\x034♥♡❤♡♥\x03 {nick} \x034♥♡❤♡♥'.format(nick=args['<nick>'])
2017-05-15 22:26:10 +00:00
@command
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Gives nick a beer.
2017-06-01 15:38:34 +00:00
%%bier [<nick>]
"""
2017-07-04 13:22:20 +00:00
self.bot.action(target, 'schenkt ein kühles Blondes an {nick} aus.'
2017-06-01 15:38:34 +00:00
.format(nick=args.get('<nick>') or mask.nick))
@command
def fucken(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kills and fucks a nick.
2017-06-01 15:38:34 +00:00
%%fucken [<nick>]
"""
self.bot.action(target, 'fuckt {nick} und tötet {nick} anschließend.'
2017-06-01 15:38:34 +00:00
.format(nick=args.get('<nick>') or mask.nick))
@command
def anhero(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Kicks a nick.
%%anhero
"""
self.bot.privmsg(target, 'Sayonara bonzai-chan...')
self.bot.kick(target, mask.nick)
@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):
2017-05-28 12:07:35 +00:00
"""Hacks (a user).
2017-05-28 11:27:40 +00:00
%%hack [<nick>]
"""
nick = args.get('<nick>') or ''
2017-05-29 16:44:26 +00:00
return 'hacking{nick}...'.format(nick=' %s' % nick if nick else '')
2017-05-15 22:26:10 +00:00
@command
def gay(self, mask: IrcString, target: IrcString, args: DocOptDict):
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
def rainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
2017-05-28 12:07:35 +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
def wrainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
2017-05-28 12:07:35 +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-05-29 16:44:26 +00:00
return ' '.join([self._rainbow(i, word) for i, word
in enumerate(args['<words>'])])
2017-07-04 13:22:20 +00:00
def _rainbow(self, i, char):
2017-05-29 16:44:26 +00:00
return '\x03{color}{char}'.format(color=RAINBOW[i % RAINBOW_LEN],
char=char)