2017-05-31 12:05:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import random
|
|
|
|
|
2017-06-30 12:04:50 +00:00
|
|
|
import irc3
|
2017-05-31 12:05:55 +00:00
|
|
|
from docopt import Dict as DocOptDict
|
|
|
|
from irc3.plugins.command import command
|
|
|
|
from irc3.utils import IrcString
|
2017-06-30 13:03:01 +00:00
|
|
|
from psycopg2 import Error
|
2017-05-31 12:05:55 +00:00
|
|
|
|
|
|
|
from . import DatabasePlugin
|
|
|
|
|
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
@irc3.plugin
|
2017-05-31 12:05:55 +00:00
|
|
|
class Rape(DatabasePlugin):
|
|
|
|
requires = ['irc3.plugins.command',
|
2017-07-07 00:11:20 +00:00
|
|
|
'bot.plugins.storage']
|
2017-05-31 12:05:55 +00:00
|
|
|
|
|
|
|
@command
|
2017-06-29 21:57:15 +00:00
|
|
|
def owe(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
2017-05-31 12:05:55 +00:00
|
|
|
"""Shows how much a nick owes.
|
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
%%owe [<nick>]
|
2017-05-31 12:05:55 +00:00
|
|
|
"""
|
2017-06-29 21:57:15 +00:00
|
|
|
nick = args.get('<nick>') or mask.nick
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
# Fetch result from database
|
2017-06-30 12:04:50 +00:00
|
|
|
self.cur.execute('''
|
|
|
|
select
|
2017-06-30 15:47:24 +00:00
|
|
|
fines
|
2017-06-30 12:04:50 +00:00
|
|
|
from
|
2017-06-30 15:47:24 +00:00
|
|
|
users
|
2017-06-30 12:04:50 +00:00
|
|
|
where
|
2017-06-30 15:47:24 +00:00
|
|
|
lower(nick) = lower(%s)
|
2017-06-30 12:04:50 +00:00
|
|
|
''', [nick])
|
2017-05-31 12:05:55 +00:00
|
|
|
owes = self.cur.fetchone()
|
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
# Colorize owe amount and return string
|
2017-06-30 12:04:50 +00:00
|
|
|
if owes:
|
2017-06-30 15:47:24 +00:00
|
|
|
fines = '4${fines}'.format(fines=owes['fines'])
|
2017-06-30 12:04:50 +00:00
|
|
|
else:
|
2017-06-30 15:47:24 +00:00
|
|
|
fines = '3$0'
|
2017-06-30 12:04:50 +00:00
|
|
|
|
|
|
|
# Return total owes
|
2017-06-30 15:47:24 +00:00
|
|
|
return '{nick} owes: \x03{fines}\x03'.format(nick=nick, fines=fines)
|
2017-05-31 12:05:55 +00:00
|
|
|
|
|
|
|
@command
|
2017-06-29 21:57:15 +00:00
|
|
|
def rape(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
2017-05-31 12:05:55 +00:00
|
|
|
"""Rapes a nick and eventually charge for it.
|
|
|
|
|
|
|
|
%%rape <nick>
|
|
|
|
"""
|
|
|
|
nick = args.get('<nick>') or mask.nick
|
|
|
|
rand = random.randint(0, 3)
|
|
|
|
|
2017-06-30 12:04:50 +00:00
|
|
|
if rand not in (0, 1):
|
|
|
|
self.bot.action(target, 'rapes {nick}'.format(nick=nick))
|
|
|
|
else:
|
|
|
|
fine = random.randint(1, 500)
|
|
|
|
|
2017-06-30 13:03:01 +00:00
|
|
|
try:
|
|
|
|
# Insert or add fine to database and return total owe
|
|
|
|
self.cur.execute('''
|
|
|
|
insert into
|
2017-06-30 17:33:26 +00:00
|
|
|
users (nick, fines)
|
2017-06-30 13:03:01 +00:00
|
|
|
values
|
2017-07-05 02:15:04 +00:00
|
|
|
(lower(%s), %s)
|
2017-06-30 13:03:01 +00:00
|
|
|
on conflict (nick) do update set
|
2017-06-30 15:47:24 +00:00
|
|
|
fines = users.fines + excluded.fines
|
2017-06-30 13:03:01 +00:00
|
|
|
returning
|
2017-06-30 15:47:24 +00:00
|
|
|
fines
|
2017-06-30 18:14:02 +00:00
|
|
|
''', [mask.nick, fine])
|
2017-06-30 13:03:01 +00:00
|
|
|
self.con.commit()
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-30 13:03:01 +00:00
|
|
|
# Get reason based on rand value
|
|
|
|
reason = ('raping', 'being too lewd and getting raped')[rand]
|
2017-06-30 12:04:50 +00:00
|
|
|
|
2017-06-30 13:03:01 +00:00
|
|
|
# Print fine and total owe
|
|
|
|
self.bot.action(target,
|
|
|
|
'fines {nick} \x02${fine}\x02 for {reason}. '
|
|
|
|
'You owe: \x0304${total}\x03'
|
2017-06-30 18:14:02 +00:00
|
|
|
.format(nick=mask.nick,
|
2017-06-30 13:03:01 +00:00
|
|
|
fine=fine,
|
|
|
|
reason=reason,
|
2017-06-30 15:47:24 +00:00
|
|
|
total=self.cur.fetchone()['fines']))
|
2017-06-30 13:03:01 +00:00
|
|
|
except Error:
|
|
|
|
# Rollback transaction on error
|
|
|
|
self.con.rollback()
|