Skip to content

Commit dc46f7d

Browse files
authored
Merge pull request #308 from practical-python-org/JaffaCat---fix/sugges
fix: rework /suggest
2 parents 044fd10 + a9f5ac5 commit dc46f7d

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

Resources/ServerConfig/PracticalPython/channel_info.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ python_help_1 = 903542455675260928
2727
python_help_2 = 903542494409674803
2828
challenges_channel = 1045104938071633994
2929
news_channel = 1071848336442794094
30+
suggestions_channel = 962415552737996800
3031

3132
[channels.log_channel]
3233
server_change_log = 953545221260595280
@@ -83,4 +84,4 @@ employer = 1113020504148815944
8384
#############
8485
[rss_feeds.links]
8586
jetbrains = 'https: //blog.jetbrains.com/pycharm/feed/'
86-
Python_Software_foundation = 'https: //feeds.feedburner.com/PythonSoftwareFoundationNews'
87+
Python_Software_foundation = 'https: //feeds.feedburner.com/PythonSoftwareFoundationNews'

Resources/ServerConfig/Zorak-Dev/channel_info.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ python_help_1 = 1062302503351365632
2727
python_help_2 = 12345
2828
challenges_channel = 1045104938071633994
2929
news_channel = 1071095960538718261
30+
suggestions_channel = 1179390629999026207
31+
3032

3133
[channels.log_channel]
3234
server_change_log = 1062269270047862884

src/zorak/cogs/general/general_suggest.py

Lines changed: 15 additions & 5 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

@@ -28,11 +32,17 @@ async def suggest(self, ctx, question):
2832
, ctx.author.name
2933
, ctx.command)
3034

31-
embed = discord.Embed(description=question)
32-
embed.set_author(name=f"Suggestion by {ctx.author.name}")
33-
msg = await ctx.send(embed=embed)
34-
await msg.add_reaction("👍")
35-
await msg.add_reaction("👎")
35+
'''
36+
If the channel name/ID of the command matches with the current
37+
channel, the suggestion will be posted. If not, an error message will occur.
38+
'''
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))
42+
await msg.add_reaction("👍")
43+
await msg.add_reaction("👎")
44+
else:
45+
await ctx.respond(embed=embed_suggestion_error(suggest_channel))
3646

3747

3848
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)