summaryrefslogtreecommitdiff
path: root/initialise_db.py
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2021-11-28 18:43:59 +0000
committerJoe Robinson <joe@lc8n.com>2021-11-28 18:43:59 +0000
commit54b564a8788ca2fd29203331c1532deaf557f621 (patch)
treebe263ce73d3d89901f38b3dcb6d40c82fc32ffc1 /initialise_db.py
parente8be5f63b792845bff0bef0b277c888b268b83c0 (diff)
Add DB initialisation
Diffstat (limited to 'initialise_db.py')
-rw-r--r--initialise_db.py91
1 files changed, 74 insertions, 17 deletions
diff --git a/initialise_db.py b/initialise_db.py
index 62e6316..fc89ad9 100644
--- a/initialise_db.py
+++ b/initialise_db.py
@@ -1,35 +1,64 @@
from models.user import User
+from models.level import Level
+from models.item import Item
+from models.inventory import Inventory
from mee6_py_api import API
-from base import db, config, client
+from base import db
import datetime
+import discord
+import yaml
+import logging
+
+logger = logging.getLogger("peewee")
+logger.addHandler(logging.StreamHandler())
+logger.setLevel(logging.DEBUG)
+
+with open("config.yaml", "r") as yamlfile:
+ config = yaml.load(yamlfile, Loader=yaml.CLoader)
+ print("Read config successful")
+ config = config
+
+client = discord.Client()
# Runs once bot has connected to discord
@client.event
async def on_ready():
- db.create_tables([User])
+ db.create_tables([User, Level, Item, Inventory])
time_now = datetime.datetime.utcnow()
print(f"{time_now}: {client.user} has connected to Discord!")
- users = []
for guild in client.guilds:
if guild.id == config["discord_server_id"]:
print(f"{time_now}: {client.user} has joined {guild.name}!")
- for member in guild.members:
- print(member)
- print(member.display_name)
- print(member.nick)
- print(member.joined_at)
- users.append(
- User(
- username=member.name,
- display_name=member.display_name,
- discord_id=member.id,
- joined_date=member.joined_at,
- )
- )
+ # populate_users(guild.members)
+ # cur_exp = 0
+ # for i in range(10):
+ # print(f"level {i}: {cur_exp} exp")
+ # level = Level(level=i, exp_required=cur_exp)
+ # level.save()
+ # print(f"{cur_exp} + 5 * {(pow(i,2))} + {(50 * i)} + 100")
+ # cur_exp = cur_exp + 5 * pow(i, 2) + (50 * i) + 100
+ populate_levels()
+ # populate_items()
+
+
+def populate_users(users: list):
+ for member in guild.members:
+ print(member)
+ print(member.display_name)
+ print(member.nick)
+ print(member.joined_at)
+ users.append(
+ User(
+ username=member.name,
+ display_name=member.display_name,
+ discord_id=member.id,
+ joined_date=member.joined_at,
+ )
+ )
mee6API = API(config["discord_server_id"])
- mee6_levels = await mee6API.levels.get_leaderboard_page(0)
+ mee6_levels = mee6API.levels.get_leaderboard_page(0)
for user in users:
for mee6_user in mee6_levels["players"]:
if mee6_user["username"] == user.username:
@@ -40,4 +69,32 @@ async def on_ready():
user.save()
+def populate_levels():
+ cur_exp = 0
+ for i in range(100):
+ reward_currency = i * 10
+ if i % 10 == 0:
+ reward_currency *= 1.5
+ print(f"level {i}: {cur_exp} exp, {reward_currency} coins")
+ level = Level(level=i, exp_required=cur_exp, reward_currency=reward_currency)
+ level.save()
+ print(f"{cur_exp} + 5 * {(pow(i,2))} + {(50 * i)} + 100")
+ cur_exp = cur_exp + 5 * pow(i, 2) + (50 * i) + 100
+
+
+def populate_items():
+ with open("shop.yaml", "r") as yamlfile:
+ shop = yaml.load(yamlfile, Loader=yaml.CLoader)
+ print("Read shop successful")
+ for name, shop_item in shop["items"].items():
+ print(f"{name}: {shop_item}")
+ if "rank" in shop_item.keys():
+ item = Item(
+ name=name, price=shop_item["price"], text=shop_item["text"], rank=shop_item["rank"]
+ )
+ else:
+ item = Item(name=name, price=shop_item["price"], text=shop_item["text"])
+ item.save()
+
+
client.run(config["discord_token"])