-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_effects.py
62 lines (48 loc) · 2.11 KB
/
item_effects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json
import random
from datetime import datetime
from main import bot, economy_data, shop_instance
@bot.command(name='usekeycard')
async def use_keycard(ctx):
if datetime.today().weekday() != 6:
await ctx.send("You can only use a keycard on Sundays!")
return
member_id = str(ctx.author.id)
if member_id not in economy_data or 'keycard' not in economy_data[member_id].get(
"inventory", {}):
await ctx.send("You do not have a keycard to use.")
return
# If the user has a keycard, decrease the keycard count by one
economy_data[member_id]["inventory"]["keycard"] -= 1
if economy_data[member_id]["inventory"]["keycard"] <= 0:
del economy_data[member_id]["inventory"]["keycard"]
# Get a random item from the shop
shop_items = shop_instance.list_items()
if not shop_items:
await ctx.send("The shop is currently empty.")
return
random_item = random.choice(list(shop_items.keys()))
item_quantity = shop_items[random_item]["quantity"]
if item_quantity <= 0:
await ctx.send(f"Sorry, {random_item} is out of stock.")
return
# Add the random item to the user's inventory
if random_item not in economy_data[member_id].get("inventory", {}):
economy_data[member_id]["inventory"][random_item] = 0
economy_data[member_id]["inventory"][random_item] += 1
# Check if the random item is a "Potion" before the return statement.
if random_item == "Potion":
economy_data[member_id]["balance"] *= 2
try:
user = await bot.fetch_user(ctx.author.id)
if user.dm_channel is None:
await user.create_dm()
user = user.dm_channel.recipient
await user.send(f"""You used a potion and gained
{economy_data[member_id]['balance']} coins!""")
# Decrease the quantity of the item in the shop
shop_instance.remove_item(random_item, 1)
await ctx.send(f"You used a keycard and received a {random_item}!")
# Save the updated economy data
with open('economy_data.json', 'w') as file:
json.dump(economy_data, file, indent=4)