Skip to content

Commit a9f5ac5

Browse files
committed
Moved embeds into external file. Added check for the #suggestion channel instead of explicit naming
1 parent 450162d commit a9f5ac5

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/zorak/cogs/general/general_suggest.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import discord
77
from discord.ext import commands
88

9+
from zorak.utilities.cog_helpers._embeds import (
10+
embed_suggestion,
11+
embed_suggestion_error# pylint: disable=E0401
12+
)
913

1014
logger = logging.getLogger(__name__)
1115

@@ -27,25 +31,18 @@ async def suggest(self, ctx, question):
2731
logger.info("%s used the %s command."
2832
, ctx.author.name
2933
, ctx.command)
30-
31-
'''
32-
33-
'''
34-
embed = discord.Embed(description= question)
35-
embed.set_author(name= f"Suggestion by user {ctx.author.name}")
36-
error_embed = discord.Embed(title= "**Oops...**", description= "Slow down, please only use /suggest in #📎suggestions!", color= discord.Color.red())
37-
3834

3935
'''
40-
If the channel name/ID of the command matches with the current
36+
If the channel name/ID of the command matches with the current
4137
channel, the suggestion will be posted. If not, an error message will occur.
4238
'''
43-
if ctx.channel.name == "📎suggestions" or ctx.channel_id == "962415552737996800":
44-
msg = await ctx.respond(embed=embed)
39+
suggest_channel = await self.bot.fetch_channel(self.bot.server_settings.normal_channel["suggestions_channel"])
40+
if ctx.channel_id == suggest_channel.id:
41+
msg = await ctx.respond(embed = embed_suggestion(ctx.author, question))
4542
await msg.add_reaction("👍")
4643
await msg.add_reaction("👎")
4744
else:
48-
await ctx.respond(embed=error_embed)
45+
await ctx.respond(embed=embed_suggestion_error(suggest_channel))
4946

5047

5148
def setup(bot):

src/zorak/utilities/cog_helpers/_embeds.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def embed_message_delete(some_member, some_message):
9191
)
9292

9393
embed.set_thumbnail(
94-
url=some_member.avatar # the person who DELETED the message
94+
url=some_member.avatar # the person who DELETED the message
9595
)
9696
if len(some_message.content) > 1020:
9797
the_message = some_message.content[0:1020] + '...'
@@ -385,6 +385,7 @@ def embed_spammer(message_to_report):
385385
embed.add_field(name="Message:", value=message_to_report, inline=True)
386386
return embed
387387

388+
388389
def embed_spammer_warn(channel1, channel2):
389390
"""
390391
Embedding warn for detected spam messages.
@@ -406,6 +407,32 @@ def embed_spammer_warn(channel1, channel2):
406407
return embed
407408

408409

410+
def embed_suggestions(author, question):
411+
embed = discord.Embed(
412+
title=f'Suggestion by user {author.name}'
413+
, description=f'Please vote using reactions.'
414+
, color=discord.Color.yellow()
415+
, timestamp=datetime.utcnow()
416+
)
417+
418+
embed.add_field(
419+
name='Suggestion:'
420+
, value=f'{question}'
421+
, inline=True
422+
)
423+
424+
return embed
425+
426+
def embed_suggestion_error(channel):
427+
embed = discord.Embed(
428+
title='Oops!'
429+
, description=f'Please only use the /suggest command in {channel.mention}'
430+
, color=discord.Color.red()
431+
, timestamp=datetime.utcnow()
432+
)
433+
return embed
434+
435+
409436
def embed_leaderboard(people_list, server_name, server_logo):
410437
"""
411438
Embedding for the leaderboard command.
@@ -421,7 +448,7 @@ def embed_leaderboard(people_list, server_name, server_logo):
421448
)
422449
for place, person in enumerate(people_list):
423450
embed.add_field(
424-
name=f"#{place+1} - {person[0].display_name}"
451+
name=f"#{place + 1} - {person[0].display_name}"
425452
, value=f"Points: {person[1]}"
426453
, inline=False
427454
)

0 commit comments

Comments
 (0)