summaryrefslogtreecommitdiff
path: root/initialise_db.py
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2021-11-25 03:25:44 +0000
committerJoe Robinson <joe@lc8n.com>2021-11-25 03:25:44 +0000
commit439022f058cb2b9bbf6e2b46c067f4c828a1cab0 (patch)
treee1f40f477d3bb3597f52250541326885f9dbfdf8 /initialise_db.py
Initial commit
Diffstat (limited to 'initialise_db.py')
-rw-r--r--initialise_db.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/initialise_db.py b/initialise_db.py
new file mode 100644
index 0000000..62e6316
--- /dev/null
+++ b/initialise_db.py
@@ -0,0 +1,43 @@
+from models.user import User
+from mee6_py_api import API
+from base import db, config, client
+import datetime
+
+
+# Runs once bot has connected to discord
+@client.event
+async def on_ready():
+
+ db.create_tables([User])
+ 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,
+ )
+ )
+ mee6API = API(config["discord_server_id"])
+ mee6_levels = await mee6API.levels.get_leaderboard_page(0)
+ for user in users:
+ for mee6_user in mee6_levels["players"]:
+ if mee6_user["username"] == user.username:
+ user.level = mee6_user["level"]
+ user.exp = mee6_user["xp"]
+ user.message_count = mee6_user["message_count"]
+ print(user)
+ user.save()
+
+
+client.run(config["discord_token"])