Skip to content

Commit

Permalink
Merge pull request #26 from TheophileDiot/dev
Browse files Browse the repository at this point in the history
Searching more in cache rather that making API requests + add sanctio…
  • Loading branch information
TheophileDiot authored Sep 8, 2021
2 parents f51b3c0 + 716540a commit d2d4163
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cogs/events/on_button_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def on_button_click(self, interaction: MessageInteraction):
interaction.guild.id, interaction.author.id
)
return await interaction.respond(
content=f"You already have an existing ticket channel! {(await self.bot.fetch_channel(ticket['id'])).mention}",
content=f"You already have an existing ticket channel! {(self.bot.get_channel(ticket['id']) or await self.bot.fetch_channel(ticket['id'])).mention}",
ephemeral=True,
)

Expand Down
4 changes: 3 additions & 1 deletion cogs/events/on_raw_message_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ async def on_raw_message_edit(self, payload: RawMessageUpdateEvent):
if not payload.guild_id:
return

channel = await self.bot.fetch_channel(payload.channel_id)
channel = self.bot.get_channel(
payload.channel_id
) or await self.bot.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)

if message.is_system() or message.author.bot:
Expand Down
19 changes: 11 additions & 8 deletions cogs/events/on_raw_reaction_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
)
]
)
await self.send_message_to_mods(
await self.bot.utils_class.send_message_to_mods(
f"⚠️ - I don't have the right permissions to remove the roles {roles} from the member `{payload.member}`!",
payload.guild_id,
)

try:
return await payload.member.send(
f"⚠️ - I don't have the right permissions to remove the roles {roles} from you so you can't pass the prestige! Please inform a server administrator! (Guild: {await self.bot.fetch_guild(payload.guild_id).name}, ID: {payload.guild_id})"
f"⚠️ - I don't have the right permissions to remove the roles {roles} from you so you can't pass the prestige! Please inform a server administrator! (Guild: {(self.bot.get_guild(payload.guild_id) or await self.bot.fetch_guild(payload.guild_id)).name}, ID: {payload.guild_id})"
)
except Forbidden:
try:
channel = await self.bot.fetch_channel(
channel = self.bot.get_channel(
payload.channel_id
)
) or await self.bot.fetch_channel(payload.channel_id)
except Forbidden as f:
f.text = f"⚠️ - I don't have the right permissions to fetch the channel under the ID {payload.channel_id}!"
raise
Expand All @@ -110,17 +110,19 @@ async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
]
)
except Forbidden:
await self.send_message_to_mods(
await self.bot.utils_class.send_message_to_mods(
f"⚠️ - I don't have the right permissions to add the role {self.bot.configs[payload.guild_id]['xp']['prestiges'][(int(db_user['prestige']) + 1) or 1]} to the member `{payload.member}`!",
payload.guild_id,
)

try:
return await payload.member.send(
f"⚠️ - I don't have the right permissions to add the role {self.bot.configs[payload.guild_id]['xp']['prestiges'][(int(db_user['prestige']) + 1) or 1]} to you so you can't pass the prestige! Please inform a server administrator! (Guild: {await self.bot.fetch_guild(payload.guild_id).name}, ID: {payload.guild_id})"
f"⚠️ - I don't have the right permissions to add the role {self.bot.configs[payload.guild_id]['xp']['prestiges'][(int(db_user['prestige']) + 1) or 1]} to you so you can't pass the prestige! Please inform a server administrator! (Guild: {(self.bot.get_guild(payload.guild_id) or await self.bot.fetch_guild(payload.guild_id)).name}, ID: {payload.guild_id})"
)
except Forbidden:
channel = await self.bot.fetch_channel(payload.channel_id)
channel = self.bot.get_channel(
payload.channel_id
) or await self.bot.fetch_channel(payload.channel_id)

try:
return await channel.send(
Expand Down Expand Up @@ -151,7 +153,8 @@ async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
raise
finally:
message = await (
await self.bot.fetch_channel(payload.channel_id)
self.bot.get_channel(payload.channel_id)
or await self.bot.fetch_channel(payload.channel_id)
).fetch_message(payload.message_id)
await message.remove_reaction("✅", self.bot.user)
await message.remove_reaction("❌", self.bot.user)
Expand Down
11 changes: 9 additions & 2 deletions cogs/events/on_ready.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from logging import info
from typing import Union

from discord import Activity, ActivityType
from discord import Activity, ActivityType, NotFound
from discord.ext.commands import Cog
from lavalink import add_event_hook, Client
from lavalink.events import NodeConnectedEvent, QueueEndEvent, TrackEndEvent
Expand Down Expand Up @@ -74,7 +74,14 @@ async def track_hook(self, event: Union[TrackEndEvent, QueueEndEvent]):
# it indicates that there are no tracks left in the player's queue.
# To save on resources, we can tell the bot to disconnect from the voicechannel.
guild_id = int(event.player.guild_id)
guild = await self.bot.fetch_guild(guild_id)

try:
guild = self.bot.get_guild(guild_id) or await self.bot.fetch_guild(
guild_id
)
except NotFound:
return

await self.bot.utils_class.clear_playlist(guild)
await guild.change_voice_state(channel=None)
elif isinstance(event, TrackEndEvent):
Expand Down
2 changes: 1 addition & 1 deletion cogs/moderation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,7 @@ async def config_channels_polls_command(
ctx.guild.id,
poll_msg.id,
poll["duration_s"]
- (time() - poll["created_at_ms"]),
- (time() - poll["created_at_s"]),
time(),
poll["choices"],
poll["responses"] if "responses" in poll else None,
Expand Down
4 changes: 2 additions & 2 deletions cogs/moderation/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def poll_infos_command(self, ctx: Context, id_message: int = None):
em.add_field(
name="**⏲️ - Time remaining:**",
value=self.bot.utils_class.duration(
poll["duration_s"] - (time() - poll["created_at_ms"])
poll["duration_s"] - (time() - poll["created_at_s"])
),
inline=True,
)
Expand Down Expand Up @@ -247,7 +247,7 @@ async def poll_infos_command(self, ctx: Context, id_message: int = None):
]
em.add_field(
name=f'Poll "*{poll_message.embeds[0].title}*":',
value=f"**⏲️ - Time remaining:** {self.bot.utils_class.duration(poll['duration_s'] - (time() - poll['created_at_ms']))}{nl}**🔘 - Number of choices:** {len(poll['choices'])}{nl}**🔢 - Number of answers:** {len(poll['responses']) if 'responses' in poll else 'No answers recorded.'}{nl}**🏆 - Leading choice:** {', '.join(winner_choices) if len(winner_choices) != len(poll['choices']) else 'No leading choice.'}",
value=f"**⏲️ - Time remaining:** {self.bot.utils_class.duration(poll['duration_s'] - (time() - poll['created_at_s']))}{nl}**🔘 - Number of choices:** {len(poll['choices'])}{nl}**🔢 - Number of answers:** {len(poll['responses']) if 'responses' in poll else 'No answers recorded.'}{nl}**🏆 - Leading choice:** {', '.join(winner_choices) if len(winner_choices) != len(poll['choices']) else 'No leading choice.'}",
inline=True,
)
x += 1
Expand Down
Loading

0 comments on commit d2d4163

Please sign in to comment.