Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
moved reactionrole strings to yaml file (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed May 2, 2020
1 parent e953d18 commit 69cc195
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cogs/reactionrole.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from database import run_in_thread, db
from models.reactionrole import ReactionRole
from translations import translations
from util import permission_level, send_to_changelog, FixedEmojiConverter


Expand Down Expand Up @@ -74,7 +75,7 @@ async def list_links(self, ctx: Context, message: Optional[Message] = None):
channels[channel][msg.jump_url].add(link.emoji)

if not channels:
await ctx.send("No ReactionRole links have been created yet.")
await ctx.send(translations.no_reactionrole_links)
else:
await ctx.send(
"\n\n".join(
Expand All @@ -98,7 +99,7 @@ async def list_links(self, ctx: Context, message: Optional[Message] = None):
continue
out.append(f"{link.emoji} -> `@{role}`")
if not out:
await ctx.send("No ReactionRole links have been created yet for this message.")
await ctx.send(translations.no_reactionrole_links_for_msg)
else:
await ctx.send("\n".join(out))

Expand All @@ -111,14 +112,12 @@ async def add(self, ctx: Context, message: Message, emoji: FixedEmojiConverter,
emoji: PartialEmoji

if await run_in_thread(ReactionRole.get, message.channel.id, message.id, str(emoji)) is not None:
raise CommandError("A link already exists for this reaction on this message.")
raise CommandError(translations.rr_link_already_exists)

await run_in_thread(ReactionRole.create, message.channel.id, message.id, str(emoji), role.id)
await message.add_reaction(emoji)
await ctx.send("Link has been created successfully.")
await send_to_changelog(
ctx.guild, f"ReactionRole link for {emoji} -> `@{role}` has been created on {message.jump_url}"
)
await ctx.send(translations.rr_link_created)
await send_to_changelog(ctx.guild, translations.f_log_rr_link_created(emoji, role, message.jump_url))

@reactionrole.command(name="remove", aliases=["r", "del", "d", "-"])
async def remove(self, ctx: Context, message: Message, emoji: FixedEmojiConverter):
Expand All @@ -129,11 +128,11 @@ async def remove(self, ctx: Context, message: Message, emoji: FixedEmojiConverte
emoji: PartialEmoji

if (link := await run_in_thread(ReactionRole.get, message.channel.id, message.id, str(emoji))) is None:
raise CommandError("Such a link does not exist.")
raise CommandError(translations.rr_link_not_found)

await run_in_thread(db.delete, link)
for reaction in message.reactions:
if str(emoji) == str(reaction.emoji):
await reaction.clear()
await ctx.send("Link has been removed successfully.")
await send_to_changelog(ctx.guild, f"ReactionRole link for {emoji} has been deleted on {message.jump_url}")
await ctx.send(translations.rr_link_removed)
await send_to_changelog(ctx.guild, translations.f_log_rr_link_removed(emoji, message.jump_url))
10 changes: 10 additions & 0 deletions translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,13 @@ pin_messages_now_disabled: Pin Messages have been disabled.
no_blocked_role: No blocked role configured.
blocked_role: "Blocked role: `@{}`"
blocked_role_updated: Blocked role has been updated.

# reactionrole
no_reactionrole_links: No ReactionRole links have been created yet.
no_reactionrole_links_for_msg: No ReactionRole links have been created yet for this message.
rr_link_already_exists: A link already exists for this reaction on this message.
rr_link_created: Link has been created successfully.
log_rr_link_created: ReactionRole link for {} -> `@{}` has been created on {}
rr_link_not_found: Such a link does not exist.
rr_link_removed: Link has been removed successfully.
log_rr_link_removed: ReactionRole link for {} has been deleted on {}

0 comments on commit 69cc195

Please sign in to comment.