Skip to content

Commit

Permalink
Try to fix bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Sep 17, 2024
1 parent b29f5d2 commit f421c49
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions worldtimezone/extensions/edit_world_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@

plugin = lightbulb.Plugin("EditWorldClock")

@tasks.task(m=5, auto_start=True, pass_app=True)
async def edit_world_clock(bot: lightbulb.BotApp) -> None:
def create_embed(guild_id, u, tz):
user_ = bot.cache.get_member(guild_id, int(u))
embed = (
hikari.Embed(
title=f"WorldTimeClock - {user_.display_name}",
description=f"Timezone: {tz}",
)
.set_author(name=f"{user_.display_name}")
.set_thumbnail(user_.avatar_url)
)
now = datetime.datetime.now()
new_tz = pytz.timezone(tz)
new_now = now.astimezone(new_tz)
embed.add_field("Time", f"{new_now}", inline=False)
return embed

for guild_id in bot.d.data.get_guilds_list():
embeds = []
guild_world_clock = bot.d.data.get_world_clock(guild_id)
channel_world_clock = guild_world_clock["channel_id"]
message_world_clock = guild_world_clock["message_id"]

for u in bot.d.data.get_members_list(guild_id):
member = bot.d.data.get_member(guild_id, u)
if "tz" in member:
embeds.append(create_embed(guild_id, u, member["tz"]))
await bot.rest.edit_message(
channel_world_clock, message_world_clock, None, embeds=embeds
)

def load(bot: lightbulb.BotApp):
@tasks.task(m=5, auto_start=True)
async def edit_world_clock() -> None:
def create_embed(guild_id, u, tz):
user_ = bot.cache.get_member(guild_id, int(u))
embed = (
hikari.Embed(
title=f"WorldTimeClock - {user_.display_name}",
description=f"Timezone: {tz}",
)
.set_author(name=f"{user_.display_name}")
.set_thumbnail(user_.avatar_url)
)
now = datetime.datetime.now()
new_tz = pytz.timezone(tz)
new_now = now.astimezone(new_tz)
embed.add_field("Time", f"{new_now}", inline=False)
return embed

for guild_id in bot.d.data.get_guilds_list():
embeds = []
guild_world_clock = bot.d.data.get_world_clock(guild_id)
channel_world_clock = guild_world_clock["channel_id"]
message_world_clock = guild_world_clock["message_id"]

for u in bot.d.data.get_members_list(guild_id):
member = bot.d.data.get_member(guild_id, u)
if "tz" in member:
embeds.append(create_embed(guild_id, u, member["tz"]))
await bot.rest.edit_message(
channel_world_clock, message_world_clock, None, embeds=embeds
)
pass


def unload(bot: lightbulb.BotApp):
Expand Down

0 comments on commit f421c49

Please sign in to comment.