2023-09-02 20:33:50 +00:00
#!/usr/bin/python3
import pinhook . plugin
import util . tilde
import subprocess
2023-09-28 17:53:28 +00:00
import uuid
2023-09-02 20:33:50 +00:00
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 ) )
2023-10-04 17:46:35 +00:00
if balance == Decimal ( 0 ) : return pinhook . plugin . message ( " You don ' t have any tildecoins with us, so you can ' t cleanwash " )
2023-09-02 20:33:50 +00:00
subprocess . check_output ( [ ' /home/jmjl/bin/coin ' , ' Ju ' , ' add_internal_balance ' , nick , f ' - { str ( balance ) } ' ] , universal_newlines = True ) . strip ( )
2024-02-13 05:36:49 +00:00
#new_balance = Decimal(randint(80,110))/Decimal(100)*Decimal(balance)
new_balance = Decimal ( randint ( 59 , 110 ) ) / Decimal ( 100 ) * Decimal ( balance )
2023-09-02 20:33:50 +00:00
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 )
2023-12-11 16:02:41 +00:00
message = f " { msg . nick } : 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 "
2024-02-13 05:36:49 +00:00
time_to_file = __import__ ( ' time ' ) . time ( )
if float ( msg . time ) - float ( time ) < 86400 : # Limit gain time to 24 hours
time_to_file = float ( msg . timestamp ) + float ( util . tilde . WAIT_TIME )
else :
time_to_file = float ( msg . timestamp ) - float ( 86400 ) + float ( util . tilde . WAIT_TIME )
util . tilde . admin_update_tilde ( nick , amount = new_balance , time = time_to_file , comment = message )
2023-09-02 20:33:50 +00:00
return pinhook . plugin . message ( message )
2023-09-28 17:53:28 +00:00
@pinhook.plugin.command ( ' &brainwashreturnbeforeplaying ' , help_text = ' Alias -- &cleanwashreturnbeforeplaying ' )
@pinhook.plugin.command ( ' &cleanwashreturnbeforeplaying ' , help_text = ' Give you back your money, if it wasn \' t dirty money. ' )
def cleanwash_return_before ( 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 ) )
nick = msg . nick
if msg . nick in msg . ops and msg . arg : nick = msg . arg . split ( ' ' ) [ 1 ]
amount_to_return = None
try :
if msg . arg :
amount_to_return_str = msg . arg . split ( ' ' ) [ 0 ]
amount_to_return = Decimal ( amount_to_return_str )
except Exception : return pinhook . plugin . message ( f " { msg . nick } : Error, { msg . arg . split ( ' ' ) [ 0 ] } is probably not a number " )
balance = Decimal ( subprocess . check_output ( [ ' /home/jmjl/bin/coin ' , ' Ju ' , ' internal_balance ' , nick ] , universal_newlines = True ) )
if not amount_to_return : amount_to_return = balance
if amount_to_return > balance : return pinhook . plugin . message ( f " { msg . nick } : Error, { amount_to_return } is more than what you have with us. (You have { balance } TCN returnable with us) " )
2023-11-05 06:02:10 +00:00
sentproc = subprocess . run ( [ ' /home/jmjl/bin/coin ' , ' Ju ' , ' send ' , nick , str ( amount_to_return . quantize ( Decimal ( ' .00 ' ) , rounding = ROUND_DOWN ) ) , f " Requested by { msg . nick } at { __import__ ( ' time ' ) . time ( ) } " ] , capture_output = True , text = True )
2023-09-28 17:53:28 +00:00
if sentproc . returncode == 0 : return pinhook . plugin . message ( f " { msg . nick } : Succesfully sent { amount_to_return } TCN back " )
else :
err_id = str ( uuid . uuid4 ( ) )
return pinhook . plugin . message ( f " { msg . nick } : Failed for some reason, consult bot admin. [ { err_id } " )
print ( f " [ERROR]: ju/tildewash: Failed to return { amount_to_return } TCN from { nick } [ { err_id } " )
print ( f " Stdout [ { err_id } ] " )
print ( sentproc . stdout )
print ( f " Stderr [ { err_id } ] " )
print ( sentproc . stderr )
print ( f " End [ { err_id } ] " )