Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: viewing voters for cleared suggestions #70

Merged
merged 1 commit into from Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions suggestions/cogs/view_voters_cog.py
Expand Up @@ -12,6 +12,7 @@
from suggestions import Colors
from suggestions.cooldown_bucket import InteractionBucket
from suggestions.objects import Suggestion
from suggestions.objects.suggestion import SuggestionState

if TYPE_CHECKING:
from alaric import Document
Expand Down Expand Up @@ -109,6 +110,13 @@ async def view_suggestion_voters(
channel_id=interaction.channel_id,
state=self.state,
)
if suggestion.state == SuggestionState.cleared:
return await interaction.send(
self.bot.get_locale(
"VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale
),
ephemeral=True,
)

up_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_up_vote()
down_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_down_vote()
Expand Down Expand Up @@ -140,6 +148,14 @@ async def view_suggestion_up_voters(
channel_id=interaction.channel_id,
state=self.state,
)
if suggestion.state == SuggestionState.cleared:
return await interaction.send(
self.bot.get_locale(
"VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale
),
ephemeral=True,
)

data = []
for voter in suggestion.up_voted_by:
data.append(f"<@{voter}>")
Expand All @@ -165,6 +181,14 @@ async def view_suggestion_down_voters(
channel_id=interaction.channel_id,
state=self.state,
)
if suggestion.state == SuggestionState.cleared:
return await interaction.send(
self.bot.get_locale(
"VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale
),
ephemeral=True,
)

data = []
for voter in suggestion.down_voted_by:
data.append(f"<@{voter}>")
Expand Down Expand Up @@ -203,6 +227,14 @@ async def view_voters(
guild_id=interaction.guild_id,
state=self.state,
)
if suggestion.state == SuggestionState.cleared:
return await interaction.send(
self.bot.get_locale(
"VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale
),
ephemeral=True,
)

data = []
up_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_up_vote()
down_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_down_vote()
Expand Down
3 changes: 2 additions & 1 deletion suggestions/locales/en_GB.json
Expand Up @@ -121,5 +121,6 @@
"SUGGESTION_ID_NAME": "suggestion_id",
"SUGGESTION_ID_DESCRIPTION": "The suggestions ID you wish to reference.",
"USER_ID_NAME": "user_id",
"USER_ID_DESCRIPTION": "The users discord id."
"USER_ID_DESCRIPTION": "The users discord id.",
"VIEW_VOTERS_CLEARED_SUGGESTION": "Cannot view a cleared suggestion."
}
3 changes: 2 additions & 1 deletion suggestions/state.py
Expand Up @@ -12,6 +12,7 @@
from alaric import AQ
from alaric.comparison import EQ
from alaric.logical import AND
from alaric.meta import Negate
from alaric.projections import PROJECTION, SHOW
from bot_base import NonExistentEntry
from bot_base.caches import TimedCache
Expand Down Expand Up @@ -166,7 +167,7 @@ async def populate_sid_cache(self, guild_id: int) -> list:
async def populate_view_voters_cache(self, guild_id: int) -> list:
self.view_voters_cache.delete_entry(guild_id)
data: List[Dict] = await self.database.suggestions.find_many(
AQ(EQ("guild_id", guild_id)),
AQ(AND(EQ("guild_id", guild_id), Negate(EQ("state", "cleared")))),
projections=PROJECTION(SHOW("_id")),
try_convert=False,
)
Expand Down