Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: moved db loading to discord utils from loop_utils #189

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

async def connect_db():
bot.db = await aiosqlite.connect("database.db")

# Discord Member Table:
await bot.db.execute("""CREATE TABLE IF NOT EXISTS members (
discord_id integer PRIMARY KEY NOT NULL,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/discord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from src.utils.consts import (config, log_channel_id, neutral_color, ticket_categories,
guild_handle)
from src.utils.db_utils import check_uuid_in_db
from src.utils.db_utils import check_uuid_in_db, connect_db
from src.utils.request_utils import get_mojang_profile
from src.utils.ticket_utils import *
from src.utils.ticket_utils.tickets import name_grabber
Expand Down Expand Up @@ -162,7 +162,6 @@ async def after_cache_ready():
# Set owner id(s) and guild
bot.owner_ids = config["owner_ids"]
bot.guild = bot.get_guild(config["guild_id"])

# Set roles
bot.admin = discord.utils.get(bot.guild.roles, name="Admin")
bot.staff = discord.utils.get(bot.guild.roles, name="Staff")
Expand All @@ -184,14 +183,15 @@ async def after_cache_ready():
bot.tag_allowed_roles = (bot.active_role, bot.staff, bot.former_staff,
bot.server_booster, bot.rich_kid, bot.gvg, bot.veteran, bot.recruiter)

from src.utils.discord_utils import name_grabber
bot.staff_names = [(await get_mojang_profile(await name_grabber(member)))[0] for member in bot.staff.members]
await connect_db()

from src.utils.loop_utils import check_giveaways, send_gexp_lb, update_invites
check_giveaways.start()
send_gexp_lb.start()
update_invites.start()

from src.utils.discord_utils import name_grabber
bot.staff_names = [(await get_mojang_profile(await name_grabber(member)))[0] for member in bot.staff.members]

@after_cache_ready.before_loop
async def before_cache_loop():
Expand Down
5 changes: 0 additions & 5 deletions src/utils/loop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ async def check_giveaways():
await bot.db.commit()


@check_giveaways.before_loop
async def before_giveaway_check():
await bot.wait_until_ready()
await connect_db()


@tasks.loop(hours=24)
async def send_gexp_lb():
Expand Down
Loading