2017-05-31 12:05:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import random
|
|
|
|
|
2017-08-22 13:57:57 +00:00
|
|
|
from docopt import Dict
|
2017-05-31 12:05:55 +00:00
|
|
|
from irc3.plugins.command import command
|
|
|
|
from irc3.utils import IrcString
|
|
|
|
|
|
|
|
from . import DatabasePlugin
|
|
|
|
|
|
|
|
|
|
|
|
class Rape(DatabasePlugin):
|
|
|
|
@command
|
2017-08-22 13:57:57 +00:00
|
|
|
def owe(self, mask: IrcString, target: IrcString, args: Dict):
|
2017-08-22 14:15:52 +00:00
|
|
|
"""Shows how much a nick owes
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
%%owe [<nick>]
|
2017-05-31 12:05:55 +00:00
|
|
|
"""
|
2017-08-21 14:59:27 +00:00
|
|
|
nick = args.get('<nick>', mask.nick)
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
# Fetch result from database
|
2020-03-16 21:51:32 +00:00
|
|
|
with self.con.cursor() as cur:
|
|
|
|
cur.execute('''
|
|
|
|
SELECT
|
|
|
|
fines
|
|
|
|
FROM
|
|
|
|
users
|
|
|
|
WHERE
|
|
|
|
lower(nick) = lower(%s)
|
|
|
|
''', [nick])
|
|
|
|
owes = cur.fetchone()
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-29 21:57:15 +00:00
|
|
|
# Colorize owe amount and return string
|
2021-01-25 19:43:53 +00:00
|
|
|
if owes and owes['fines'] > 0:
|
2017-08-22 19:20:43 +00:00
|
|
|
fines = '4${}'.format(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-08-22 13:57:57 +00:00
|
|
|
def rape(self, mask: IrcString, target: IrcString, args: Dict):
|
2017-08-22 14:15:52 +00:00
|
|
|
"""Rapes a nick and eventually charge for it
|
2017-05-31 12:05:55 +00:00
|
|
|
|
|
|
|
%%rape <nick>
|
|
|
|
"""
|
2017-08-21 14:59:27 +00:00
|
|
|
nick = args.get('<nick>', mask.nick)
|
2017-05-31 12:05:55 +00:00
|
|
|
rand = random.randint(0, 3)
|
|
|
|
|
2017-06-30 12:04:50 +00:00
|
|
|
if rand not in (0, 1):
|
2017-08-22 19:20:43 +00:00
|
|
|
self.bot.action(target, 'rapes {}'.format(nick))
|
2017-06-30 12:04:50 +00:00
|
|
|
else:
|
|
|
|
fine = random.randint(1, 500)
|
|
|
|
|
2017-08-22 19:20:43 +00:00
|
|
|
# Get reason based on rand value
|
|
|
|
fined = (mask.nick, nick)[rand]
|
|
|
|
reason = ('raping', 'being too lewd and getting raped')[rand]
|
|
|
|
|
2017-08-22 14:15:52 +00:00
|
|
|
# Insert or add fine to database and return total owe
|
2020-03-16 21:51:32 +00:00
|
|
|
with self.con.cursor() as cur:
|
|
|
|
cur.execute('''
|
|
|
|
INSERT INTO
|
|
|
|
users (nick, fines)
|
|
|
|
VALUES
|
|
|
|
(lower(%s), %s)
|
|
|
|
ON CONFLICT (nick) DO UPDATE SET
|
|
|
|
fines = users.fines + excluded.fines
|
|
|
|
RETURNING
|
|
|
|
fines
|
|
|
|
''', [fined, fine])
|
|
|
|
self.con.commit()
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2020-03-16 21:51:32 +00:00
|
|
|
# Print fine and total owe
|
|
|
|
self.bot.action(target, 'fines {nick} \x02${fine}\x02 for {reason}. You owe: \x0304${total}\x03'.format(
|
|
|
|
nick=fined,
|
|
|
|
fine=fine,
|
|
|
|
reason=reason,
|
|
|
|
total=cur.fetchone()['fines'],
|
|
|
|
))
|