From 0123d4d4dd54003c144ec59fd66223a7e8407915 Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Sat, 2 Sep 2023 22:33:50 +0200 Subject: [PATCH] Move cleanwash to it's own module This commit moves cleanwash and brainwash to it's own module and furthermore removes the modules that weren't referenced --- plugins/tilde.py | 37 ------------------------------------- plugins/tildewash.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 plugins/tildewash.py diff --git a/plugins/tilde.py b/plugins/tilde.py index 6589b80..fee3a7f 100644 --- a/plugins/tilde.py +++ b/plugins/tilde.py @@ -2,9 +2,6 @@ import pinhook.plugin import util.tilde -import subprocess -from random import randint -from decimal import Decimal,ROUND_DOWN,ROUND_UP @pinhook.plugin.command('&tildescore', help_text='See how many tildes you have with ju.') @pinhook.plugin.command('&ts', help_text='Alias -- &tildescore') @@ -78,37 +75,3 @@ def tilde_guess_plugin(msg): resp = pinhook.plugin.message(chalres[0]) return resp -@pinhook.plugin.command('&brainwash', help_text='Alias -- &cleanwash') -@pinhook.plugin.command('&cleanwash', help_text='Clean your dirty money.') -def cleanwash_money(msg): - if util.tilde.ADMIN_ONLY and msg.nick not in msg.ops: - return - if msg.channel != util.tilde.GOOD_CHAN and not util.tilde.DEBUG: - return pinhook.plugin.message("{} is a meanie and gets no washed money. **ju only works in the {} channel.**".format(msg.nick, util.tilde.GOOD_CHAN)) - with open(util.tilde.SCORE_FILE, "r") as scorefile: - time = 0 - scores = scorefile.readlines() - for score in scores: - name, score_on_file, timestamp = score.strip("\n").split("&^%") - if name == msg.nick: - time = int(timestamp.split('.')[0]) - if time == 0 or time <= 1000: return pinhook.plugin.message("You must waste your time with &tilde twice.") - if util.tilde.too_recent(msg.timestamp, time) and not (util.tilde.DEBUG or util.tilde.TIMESKIP): return pinhook.plugin.message("You must wait until being able to use this again.") - nick = msg.nick - if msg.nick in msg.ops and msg.arg: nick = msg.arg - balance = Decimal(subprocess.check_output(['/home/jmjl/bin/coin','Ju','internal_balance',nick],universal_newlines=True)) - subprocess.check_output(['/home/jmjl/bin/coin','Ju','add_internal_balance',nick,f'-{str(balance)}'],universal_newlines=True).strip() - new_balance = Decimal(randint(80,110))/Decimal(100)*Decimal(balance) - new_balance = new_balance.quantize(Decimal('1.'), rounding=ROUND_DOWN) - percentage_return = new_balance/balance * Decimal(100) - percentage_return = percentage_return.quantize(Decimal('.00'), rounding=ROUND_DOWN) - jackpot_balance = (Decimal(0.10)*Decimal(balance)).quantize(Decimal('1.'), rounding=ROUND_DOWN) - with open(util.tilde.JACKPOT_FILE, "r+") as jackpotfile: - jackpot = int(jackpotfile.readline().strip("\n")) - jackpotfile.seek(0) - jackpotfile.truncate() - jackpot_now = str(jackpot + jackpot_balance) - jackpotfile.write(jackpot_now) - message = f"Cleanwashed {balance}TCN, and given the user {new_balance}TCN ({percentage_return}%) and contributed {jackpot_balance}TCN to the balance, jackpot at {jackpot_now}TCN" - util.tilde.admin_update_tilde(nick,amount=new_balance,time=msg.timestamp,comment=message) - return pinhook.plugin.message(message) diff --git a/plugins/tildewash.py b/plugins/tildewash.py new file mode 100644 index 0000000..ae6861a --- /dev/null +++ b/plugins/tildewash.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +import pinhook.plugin +import util.tilde +import subprocess +from random import randint +from decimal import Decimal,ROUND_DOWN,ROUND_UP + +@pinhook.plugin.command('&brainwash', help_text='Alias -- &cleanwash') +@pinhook.plugin.command('&cleanwash', help_text='Clean your dirty money.') +def cleanwash_money(msg): + if util.tilde.ADMIN_ONLY and msg.nick not in msg.ops: + return + if msg.channel != util.tilde.GOOD_CHAN and not util.tilde.DEBUG: + return pinhook.plugin.message("{} is a meanie and gets no washed money. **ju only works in the {} channel.**".format(msg.nick, util.tilde.GOOD_CHAN)) + with open(util.tilde.SCORE_FILE, "r") as scorefile: + time = 0 + scores = scorefile.readlines() + for score in scores: + name, score_on_file, timestamp = score.strip("\n").split("&^%") + if name == msg.nick: + time = int(timestamp.split('.')[0]) + if time == 0 or time <= 1000: return pinhook.plugin.message("You must waste your time with &tilde twice.") + if util.tilde.too_recent(msg.timestamp, time) and not (util.tilde.DEBUG or util.tilde.TIMESKIP): return pinhook.plugin.message("You must wait until being able to use this again.") + nick = msg.nick + if msg.nick in msg.ops and msg.arg: nick = msg.arg + balance = Decimal(subprocess.check_output(['/home/jmjl/bin/coin','Ju','internal_balance',nick],universal_newlines=True)) + subprocess.check_output(['/home/jmjl/bin/coin','Ju','add_internal_balance',nick,f'-{str(balance)}'],universal_newlines=True).strip() + new_balance = Decimal(randint(80,110))/Decimal(100)*Decimal(balance) + new_balance = new_balance.quantize(Decimal('1.'), rounding=ROUND_DOWN) + percentage_return = new_balance/balance * Decimal(100) + percentage_return = percentage_return.quantize(Decimal('.00'), rounding=ROUND_DOWN) + jackpot_balance = (Decimal(0.10)*Decimal(balance)).quantize(Decimal('1.'), rounding=ROUND_DOWN) + with open(util.tilde.JACKPOT_FILE, "r+") as jackpotfile: + jackpot = int(jackpotfile.readline().strip("\n")) + jackpotfile.seek(0) + jackpotfile.truncate() + jackpot_now = str(jackpot + jackpot_balance) + jackpotfile.write(jackpot_now) + message = f"Cleanwashed {balance}TCN, and given the user {new_balance}TCN ({percentage_return}%) and contributed {jackpot_balance}TCN to the balance, jackpot at {jackpot_now}TCN" + util.tilde.admin_update_tilde(nick,amount=new_balance,time=msg.timestamp,comment=message) + return pinhook.plugin.message(message)