Skip to content
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
54 changes: 32 additions & 22 deletions tasks/check_whitelabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@
async def check_whitelabel(bot: Bot):
async for item in bot.whitelabel.db.find({}):
try:
guild = await bot.fetch_guild(int(item["GuildID"])) # looking at the db, guild ids aren't always ints
except:
return
try:
owner = await guild.fetch_member(int(item["DiscordID"]))
except:
return
bot_member = guild.me
time = datetime.datetime.now(tz=datetime.UTC)
expiry = datetime.datetime.fromtimestamp(item["Expiry"])
if expiry > time:
await owner.send(embed=discord.Embed(
title="Whitelabel Subscription Expired",
description="Your whitelabel subscription has expired, therefore, the avatar, banner, and bio will be reset. Please renew your subscription through the web dashboard or open a ticket if you need assistance."
))
await bot_member.edit(avatar=None, banner=None, bio=None, reason="Whitelabel subscription expired")
return

session = aiohttp.ClientSession()
av = await (await session.post(item["UserData"]["AvatarURL"])).read()
banner = await (await session.post(item["UserData"]["BannerURL"])).read()
await bot_member.edit(avatar=av, banner=banner, bio=item["UserData"]["Bio"])
print(item)
if item["GuildID"] == 0:
await bot.whitelabel.delete(item["_id"])
continue
try:
guild = await bot.fetch_guild(int(item["GuildID"])) # looking at the db, guild ids aren't always ints
except:
return
try:
owner = await guild.fetch_member(int(item["DiscordID"]))
except:
return
bot_member = guild.me or guild.get_member(bot.user.id) or await guild.fetch_member(bot.user.id)

print(bot_member)
time = datetime.datetime.now(tz=datetime.UTC)
expiry = datetime.datetime.fromtimestamp(item["Expiry"], tz=datetime.UTC)
if expiry < time:
await owner.send(embed=discord.Embed(
title="Whitelabel Subscription Expired",
description="Your whitelabel subscription has expired, therefore, the avatar, banner, and bio will be reset. Please renew your subscription through the web dashboard or open a ticket if you need assistance."
))
await bot_member.edit(avatar=None, banner=None, bio=None, reason="Whitelabel subscription expired")
return

session = aiohttp.ClientSession()
av = await (await session.get(item["UserData"]["AvatarURL"])).read()
banner = await (await session.get(item["UserData"]["BannerURL"])).read()
await bot_member.edit(avatar=av, banner=banner, bio=item["UserData"]["Bio"])
except Exception as e:
print(str(e))
continue

4 changes: 2 additions & 2 deletions tasks/iterate_prc_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

count_aggregate = global_aggregate + [{"$count": "total"}]

@tasks.loop(minutes=7, reconnect=True)
@tasks.loop(minutes=5, reconnect=True)
async def iterate_prc_logs(bot):
try:
server_count_list = await (await bot.settings.db.aggregate(count_aggregate)).to_list(length=None)
server_count_list = [i async for i in await bot.settings.db.aggregate(count_aggregate)]
server_count = server_count_list[0]["total"] if server_count_list else 0

logging.warning(f"[ITERATE] Starting iteration for {server_count} servers")
Expand Down
Loading