Skip to content

Commit

Permalink
Merge branch 'FRCDiscord:master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
skruglov2023 authored Mar 18, 2024
2 parents dd7d221 + bc5f31e commit 2b9cfde
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
38 changes: 28 additions & 10 deletions dozer/cogs/firstqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,34 @@ async def data(ctx: DozerContext, level: str, question: int) -> Union[str, None]
url=forum_url + str(question),
color=discord.Color.blue()
)
embed.add_field(
name="Question",
value=a[a.find(" Q: ") + 1:a.find(" A: ")],
inline=False
)
embed.add_field(
name="Answer",
value=a[a.find(" A: ") + 1:a.find(" ( Asked by ")],
inline=False
)
ques = a[a.find(" Q: ") + 1:a.find(" A: ")]
ans = a[a.find(" A: ") + 1:a.find(" ( Asked by ")]
if len(ques) < 1024:
embed.add_field(
name="Question",
value=ques,
inline=False
)
else:
for i in range(0, len(ques), 1024):
embed.add_field(
name="Question" if i == 0 else "",
value=ques[i+2:i + 1024] if i == 0 else ques[i:i + 1024] or ques[i:],
inline=False
)
if len(ans) < 1024:
embed.add_field(
name="Answer",
value=ans,
inline=False
)
else:
for i in range(0, len(ans), 1024):
embed.add_field(
name="Answer" if i == 0 else "",
value=ans[i+2:i + 1024] if i == 0 else ans[i:i + 1024] or ans[i:],
inline=False
)
embed.set_footer(text=a[a.find(" ( Asked by ") + 1:])
return embed

Expand Down
13 changes: 10 additions & 3 deletions dozer/cogs/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,19 @@ async def createmenu(self, ctx: DozerContext, channel: discord.TextChannel, *, n
@guild_only()
async def addrole(self, ctx: DozerContext, channel: typing.Optional[discord.TextChannel], message_id,
role: discord.Role,
emoji: discord.Emoji):
emoji):
"""Adds a reaction role to a message or a role menu"""
message_id = int(message_id)
if isinstance(emoji, discord.Emoji) and emoji.guild_id != ctx.guild.id:
raise BadArgument(f"The emoji {emoji} is a custom emoji not from this server!")
try:
emoji_id = int(emoji.split(":")[-1][:-1]) # Extracting ID from the string
server_emoji_ids = [(emoji.name, str(emoji.id)) for emoji in await ctx.guild.fetch_emojis()]

if (emoji.split(":")[1], str(emoji_id)) not in server_emoji_ids:
raise BadArgument("That emoji is not from this server!")

except ValueError:
pass

if role > ctx.author.top_role:
raise BadArgument('Cannot give roles higher than your top role!')

Expand Down
14 changes: 10 additions & 4 deletions dozer/cogs/starboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import discord
from discord.ext import commands
from discord.ext.commands import guild_only, has_permissions
from discord.ext.commands import guild_only, has_permissions, BadArgument
from discord.utils import escape_markdown
from loguru import logger

Expand Down Expand Up @@ -266,9 +266,15 @@ async def config(self, ctx: DozerContext, channel: discord.TextChannel,
message = await channel.send('Testing Reaction')
await message.add_reaction(emoji)
await message.remove_reaction(emoji, ctx.guild.me)
if isinstance(emoji, discord.Emoji) and emoji.guild_id != ctx.guild.id:
await ctx.send(f"The emoji {emoji} is a custom emoji not from this server!")
return
try:
emoji_id = int(emoji.split(":")[-1][:-1]) # Extracting ID from the string
server_emoji_ids = [(emoji.name, str(emoji.id)) for emoji in await ctx.guild.fetch_emojis()]

if (emoji.split(":")[1], str(emoji_id)) not in server_emoji_ids:
raise BadArgument("That emoji is not from this server!")

except ValueError:
pass
except discord.HTTPException as err:
await ctx.send(f"{ctx.author.mention}, bad argument: '{emoji}' is not an emoji, or isn't from a server "
f"{ctx.me.name} is in, error: {err}")
Expand Down

0 comments on commit 2b9cfde

Please sign in to comment.