Update CoinCmds.py

This commit is contained in:
Sarasayed0118 2024-04-07 05:20:27 +05:30 committed by GitHub
parent 3d9cbd4e04
commit 8c6188982c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,9 +18,10 @@ from bastd.gameutils import SharedObjects
from tools import playlist from tools import playlist
from tools import logger, mongo from tools import logger, mongo
import set import set
import threading
import json import json
Commands = ['cjt', 'checkjointime', 'shop', 'donate','removepaideffect'] Commands = ['cjt', 'checkjointime', 'shop', 'donate','removepaideffect']
CommandAliases = ['give', 'buy', 'cts', 'stc', 'rpe'] CommandAliases = ['give', 'buy', 'cts', 'stc', 'rpe', 'scoretocash', 'cashtoscore']
BANK_PATH = _ba.env().get("python_directory_user", "") + "/bank.json" BANK_PATH = _ba.env().get("python_directory_user", "") + "/bank.json"
base_path = os.path.join(_ba.env()['python_directory_user'], "stats" + os.sep) base_path = os.path.join(_ba.env()['python_directory_user'], "stats" + os.sep)
@ -114,7 +115,7 @@ def shop(arguments, clientid):
with ba.Context(player): with ba.Context(player):
string = '==You can buy following items==\n' string = '==You can buy following items==\n'
if a == []: if a == []:
send("Usage: /shop commands, /shop effects and /shop tag", clientid) send("Usage: /shop commands, /shop effects", clientid)
elif a[0].startswith('effects'): elif a[0].startswith('effects'):
for x in set.availableeffects: for x in set.availableeffects:
string += f"{x} ---- {tic}{str(set.availableeffects[x])} ---- for 1 day\n" string += f"{x} ---- {tic}{str(set.availableeffects[x])} ---- for 1 day\n"
@ -148,7 +149,7 @@ def stc(arguments, clientid, accountid):
players = _ba.get_foreground_host_activity().players players = _ba.get_foreground_host_activity().players
player = _ba.get_foreground_host_activity() player = _ba.get_foreground_host_activity()
a = arguments a = arguments
with ba.Context(player): with ba.Context(player, exit_result=None):
try: try:
score = int(a[0]) score = int(a[0])
stats = mystats.get_all_stats() stats = mystats.get_all_stats()
@ -160,15 +161,43 @@ def stc(arguments, clientid, accountid):
send(f"You can only convert more than 500 scores", clientid) send(f"You can only convert more than 500 scores", clientid)
else: else:
stats[accountid]['scores'] -= score stats[accountid]['scores'] -= score
mystats.dump_stats(stats)
equivalentCoins = int(score / 5 * 0.9) equivalentCoins = int(score / 5 * 0.9)
addcoins(accountid, equivalentCoins) addcoins(accountid, equivalentCoins)
mystats.dump_stats(stats)
ba.screenmessage('Transaction Successful', color=(0,1,0)) ba.screenmessage('Transaction Successful', color=(0,1,0))
_ba.chatmessage(f"{str(equivalentCoins)}{tic} added to your account. [10% transaction fee deducted]") _ba.chatmessage(f"{str(equivalentCoins)}{tic} added to your account. [10% transaction fee deducted]")
mystats.refreshStats() thread=threading.Thread(target=mystats.refreshStats)
thread.start()
except: except:
send("Usage: /scoretocash or stc amount_of_score", clientid) send("Usage: /scoretocash or stc amount_of_score", clientid)
def cts(arguments, clientid, accountid):
players = _ba.get_foreground_host_activity().players
player = _ba.get_foreground_host_activity()
a = arguments
with ba.Context(player, exit_result=None):
try:
coins = int(a[0])
havecoins = getcoins(accountid)
if havecoins < coins:
send(f"Not enough {tic}{ticket} to perform the transaction", clientid)
send(f"You have {havecoins}{tic} only....", clientid)
elif coins < 100:
send(f"You can only convert more than 100{tic}", clientid)
else:
addcoins(accountid, coins * -1)
stats = mystats.get_all_stats()
equivalentScore = int(coins * 5 * 0.9)
stats[accountid]['scores'] += equivalentScore
mystats.dump_stats(stats)
ba.playsound(ba.getsound("cashRegister"))
ba.screenmessage(f'Transaction Successful', color=(0,1,0))
_ba.chatmessage(f"{str(equivalentScore)} scores added to your account stats. [10% transaction fee deducted]")
thread=threading.Thread(target=mystats.refreshStats)
thread.start()
except:
send("Usage: /cashtoscore or cts amount_of_cash", clientid)
def donate(arguments, clientid, accountid): def donate(arguments, clientid, accountid):
players = _ba.get_foreground_host_activity().players players = _ba.get_foreground_host_activity().players
@ -212,33 +241,6 @@ def donate(arguments, clientid, accountid):
ba.screenmessage('An error occurred. Check the console for details.', transient=True, clients=[clientid]) ba.screenmessage('An error occurred. Check the console for details.', transient=True, clients=[clientid])
def cts(arguments, clientid, accountid):
players = _ba.get_foreground_host_activity().players
player = _ba.get_foreground_host_activity()
a = arguments
with ba.Context(player):
try:
coins = int(a[0])
havecoins = getcoins(accountid)
if havecoins < coins:
send(f"Not enough {tic}{ticket} to perform the transaction", clientid)
send(f"You have {havecoins}{tic} only....", clientid)
elif coins < 100:
send(f"You can only convert more than 100{tic}", clientid)
else:
addcoins(accountid, coins * -1)
stats = mystats.get_all_stats()
equivalentScore = int(coins * 5 * 0.9)
stats[accountid]['scores'] += equivalentScore
ba.playsound(ba.getsound("cashRegister"))
ba.screenmessage(f'Transaction Successful', color=(0,1,0))
mystats.dump_stats(stats)
_ba.chatmessage(f"{str(equivalentScore)} scores added to your account stats. [10% transaction fee deducted]")
mystats.refreshStats()
except:
send("Usage: /cashtoscore or cts amount_of_cash", clientid)
def buy(arguments, clientid, accountid): def buy(arguments, clientid, accountid):
global effectCustomers global effectCustomers
players = _ba.get_foreground_host_activity().players players = _ba.get_foreground_host_activity().players
@ -254,7 +256,9 @@ def buy(arguments, clientid, accountid):
if havecoins >= costofeffect: if havecoins >= costofeffect:
customers = pdata.get_custom()['paideffects'] customers = pdata.get_custom()['paideffects']
if accountid not in customers: if accountid not in customers:
expiry = datetime.now() + timedelta(days=1) dayss = settings["Paideffects"]["timedelta"]
settime = settings["Paideffects"]["ExpriyPaideffectTime"]
expiry = datetime.now() + timedelta(dayss=settime)
customers[accountid] = {'effect': effect, 'expiry': expiry.strftime('%d-%m-%Y %H:%M:%S')} customers[accountid] = {'effect': effect, 'expiry': expiry.strftime('%d-%m-%Y %H:%M:%S')}
addcoins(accountid, costofeffect * -1) addcoins(accountid, costofeffect * -1)
_ba.chatmessage(f"Success! That cost you {str(costofeffect)}{tic}") _ba.chatmessage(f"Success! That cost you {str(costofeffect)}{tic}")