forked from HurricanKai/Werewolf_Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop.py
69 lines (57 loc) · 3.39 KB
/
shop.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
63
64
65
66
67
68
69
'''
███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ██████╗ ████████╗
██╔════╝██║ ██║██╔═══██╗██╔══██╗ ██╔══██╗██╔═══██╗╚══██╔══╝
███████╗███████║██║ ██║██████╔╝ ██████╔╝██║ ██║ ██║
╚════██║██╔══██║██║ ██║██╔═══╝ ██╔══██╗██║ ██║ ██║
███████║██║ ██║╚██████╔╝██║ ██████╔╝╚██████╔╝ ██║
╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝
- = https://github.com/werewolves-devs/werewolf_bot = -
'''
import discord
import asyncio
import random
import json
from emoji import emojize, demojize
# Import config data
import config
shops = []
class Shop():
# This class holds both the shop's id (the message ID) and the shop's config (a JSON value)
def __init__(self, message_id, config):
self.message_id = message_id
self.config = config
def find_shop_by_id(id):
# Finds a shop config based on a shop (message) id
for shop in shops:
if shop.message_id == id:
return shop.config
return None
def get_shop_config():
# Returns a json value with the default shop config file
with open('shop.json') as f:
return json.load(f) # Load shop config file
def is_shop(message_id):
# returns True if 'message_id' is in the 'shops' list. Else returns false
for shop in shops:
if shop.message_id == message_id:
return True
return False
async def instantiate_shop(shop_config, channel, client):
# Creates a new shop instance
if shop_config == '':
shop_config = get_shop_config() # If no config specified, use default
embed = discord.Embed(title="Shop (Page 1/1)", description=shop_config["shop_description"], color=0x00ff00)
for item in shop_config["items"]:
embed.add_field(name="[{}] {}".format(item["emoji"], item["name"]), value="{} {}\n*{}*\n".format(item["price"], shop_config["currency"], item["description"]), inline=False) # Add Each item, in turn, to shop
message = await channel.send(embed=embed)
for item in shop_config["items"]:
await message.add_reaction(emojize(item["emoji"], use_aliases=True)) # Add reactions to shop
shops.append(Shop(message.id, shop_config)) # Add a new Shop() instance to the 'shops' list
return message # Return the message so we can use it later
async def find_item_from_key(column, query, message_id):
# Returns the item object based on 'column' from the shop associated with 'message_id' when it matches 'query'
shop_config = find_shop_by_id(message_id)
for item in shop_config["items"]:
# print("Testing {} against {}".format(item[column], query)) # This is very useful when trying to find the full emoji name of something
if emojize(item[column]) == emojize(query):
return item