-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: version 3.28 * fix: da locale location * chore: rework deps to include disnake[speed] explicitly * fix: failing to close threads due to missing state We now save a thread_id instead of trying to find the thread via message.id Closes #98 * chore: update some deps * migrate to new disnake syntax * Upgrade disnake and disnake ext componenets (#99) * migrate to new disnake syntax * Start working on new buttons * Implement all new buttons * fix: Dockerfile builds
- Loading branch information
Showing
21 changed files
with
1,330 additions
and
907 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
FROM python:3.10 | ||
|
||
# Set pip to have cleaner logs and no saved cache | ||
ENV PIP_NO_CACHE_DIR=false | ||
|
||
RUN mkdir -p /bot | ||
WORKDIR bot | ||
FROM python:3.11-alpine | ||
|
||
WORKDIR /code | ||
RUN pip install poetry | ||
|
||
COPY ./pyproject.toml /bot/pyproject.toml | ||
COPY ./poetry.lock /bot/poetry.lock | ||
|
||
RUN poetry install | ||
|
||
COPY . /bot | ||
COPY . /code | ||
|
||
|
||
CMD poetry run python3 main.py | ||
CMD ["poetry", "run", "python", "main.py"] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
[tool.poetry] | ||
name = "suggestions bot" | ||
version = "3.27" | ||
version = "3.28" | ||
description = "A Discord bot designed to build better communities by encouraging a positive and constructive relationship between community and staff." | ||
authors = ["Your Name <[email protected]>"] | ||
authors = ["Suggestions Bot"] | ||
license = "AGPL-3.0" | ||
readme = "README.md" | ||
readme = "readme.md" | ||
package-mode = false | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
disnake = "2.9.2" | ||
disnake = {extras = ["speed"], version = "2.10.1"} | ||
alaric = "^1.5.0" | ||
function-cooldowns = "^2.0.1" | ||
httpx = "^0.27.2" | ||
httpx = "^0.28.1" | ||
orjson = "^3.10.11" | ||
skelmis-commons = "^1.4.0" | ||
zonis = "^2.1.0" | ||
aiobotocore = "^2.15.2" | ||
logoo = "^1.5.1" | ||
disnake-ext-components = {git = "https://github.com/suggestionsbot/disnake-ext-components.git", rev = "91689ed74ffee73f631453a39e548af9b824826d"} | ||
typing-extensions = "^4.12.2" | ||
python-dotenv = "^1.0.1" | ||
humanize = "^4.11.0" | ||
disnake-ext-components = {git = "https://github.com/DisnakeCommunity/disnake-ext-components.git", rev = "rewrite"} | ||
|
||
|
||
[tool.poetry.group.dev.dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .suggestions_components import ( | ||
SuggestionUpVote, | ||
SuggestionDownVote, | ||
SuggestionsQueueApprove, | ||
SuggestionsQueueReject, | ||
) | ||
from .virtual_queue import ( | ||
QueueButton, | ||
QueueNextButton, | ||
QueuePreviousButton, | ||
QueueStopButton, | ||
VirtualApproveButton, | ||
VirtualRejectButton, | ||
) | ||
|
||
__all__ = ( | ||
"SuggestionUpVote", | ||
"SuggestionDownVote", | ||
"SuggestionsQueueApprove", | ||
"SuggestionsQueueReject", | ||
"QueueButton", | ||
"QueueNextButton", | ||
"QueuePreviousButton", | ||
"VirtualApproveButton", | ||
"VirtualRejectButton", | ||
"QueueStopButton", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
from __future__ import annotations | ||
|
||
import typing | ||
|
||
import logoo | ||
from disnake.ext import components | ||
from disnake.ext.components import interaction | ||
|
||
from suggestions.clunk2 import update_suggestion_message | ||
from suggestions.interaction_handler import InteractionHandler | ||
from suggestions.objects import Suggestion, QueuedSuggestion | ||
from suggestions.objects.suggestion import SuggestionState | ||
from suggestions.utility import wrap_with_error_handler | ||
|
||
if typing.TYPE_CHECKING: | ||
from suggestions.cogs.suggestion_cog import SuggestionsCog | ||
|
||
logger = logoo.Logger(__name__) | ||
manager = components.get_manager("suggestions") | ||
|
||
|
||
@manager.register # type: ignore | ||
class SuggestionUpVote(components.RichButton): | ||
suggestion_id: str | ||
|
||
@wrap_with_error_handler() | ||
async def callback( # type: ignore | ||
self, | ||
inter: components.MessageInteraction, | ||
) -> None: | ||
ih: InteractionHandler = await InteractionHandler.new_handler(inter._wrapped) | ||
suggestion: Suggestion = await Suggestion.from_id( | ||
self.suggestion_id, inter.guild_id, ih.bot.state | ||
) | ||
if suggestion.state != SuggestionState.pending: | ||
return await ih.send( | ||
translation_key="SUGGESTION_UP_VOTE_INNER_NO_MORE_CASTING" | ||
) | ||
|
||
member_id = inter.author.id | ||
if member_id in suggestion.up_voted_by: | ||
return await ih.send( | ||
translation_key="SUGGESTION_UP_VOTE_INNER_ALREADY_VOTED" | ||
) | ||
|
||
if member_id in suggestion.down_voted_by: | ||
suggestion.down_voted_by.discard(member_id) | ||
suggestion.up_voted_by.add(member_id) | ||
await ih.bot.state.suggestions_db.upsert(suggestion, suggestion) | ||
# await suggestion.update_vote_count(self.bot, inter) | ||
# lock.enqueue(suggestion.update_vote_count(self.bot, inter)) | ||
await ih.send(translation_key="SUGGESTION_UP_VOTE_INNER_MODIFIED_VOTE") | ||
logger.debug( | ||
f"Member {member_id} modified their vote on {self.suggestion_id} to a up vote", | ||
extra_metadata={ | ||
"suggestion_id": self.suggestion_id, | ||
"guild_id": inter.guild_id, | ||
}, | ||
) | ||
else: | ||
suggestion.up_voted_by.add(member_id) | ||
await ih.bot.state.suggestions_db.upsert(suggestion, suggestion) | ||
await ih.send(translation_key="SUGGESTION_UP_VOTE_INNER_REGISTERED_VOTE") | ||
logger.debug( | ||
f"Member {member_id} up voted {self.suggestion_id}", | ||
extra_metadata={ | ||
"suggestion_id": self.suggestion_id, | ||
"guild_id": inter.guild_id, | ||
}, | ||
) | ||
|
||
await update_suggestion_message(suggestion=suggestion, bot=ih.bot) | ||
|
||
|
||
@manager.register # type: ignore | ||
class SuggestionDownVote(components.RichButton): | ||
suggestion_id: str | ||
|
||
@wrap_with_error_handler() | ||
async def callback( # type: ignore | ||
self, | ||
inter: interaction.MessageInteraction, | ||
) -> None: | ||
ih: InteractionHandler = await InteractionHandler.new_handler(inter._wrapped) | ||
suggestion: Suggestion = await Suggestion.from_id( | ||
self.suggestion_id, inter.guild_id, ih.bot.state | ||
) | ||
if suggestion.state != SuggestionState.pending: | ||
return await ih.send( | ||
translation_key="SUGGESTION_DOWN_VOTE_INNER_NO_MORE_CASTING" | ||
) | ||
|
||
member_id = inter.author.id | ||
if member_id in suggestion.down_voted_by: | ||
return await ih.send( | ||
translation_key="SUGGESTION_DOWN_VOTE_INNER_ALREADY_VOTED" | ||
) | ||
|
||
if member_id in suggestion.up_voted_by: | ||
suggestion.up_voted_by.discard(member_id) | ||
suggestion.down_voted_by.add(member_id) | ||
await ih.bot.state.suggestions_db.upsert(suggestion, suggestion) | ||
await ih.send(translation_key="SUGGESTION_DOWN_VOTE_INNER_MODIFIED_VOTE") | ||
logger.debug( | ||
f"Member {member_id} modified their vote on {self.suggestion_id} to a down vote", | ||
extra_metadata={ | ||
"suggestion_id": self.suggestion_id, | ||
"guild_id": inter.guild_id, | ||
}, | ||
) | ||
else: | ||
suggestion.down_voted_by.add(member_id) | ||
await ih.bot.state.suggestions_db.upsert(suggestion, suggestion) | ||
await ih.send(translation_key="SUGGESTION_DOWN_VOTE_INNER_REGISTERED_VOTE") | ||
logger.debug( | ||
f"Member {member_id} down voted {self.suggestion_id}", | ||
extra_metadata={ | ||
"suggestion_id": self.suggestion_id, | ||
"guild_id": inter.guild_id, | ||
}, | ||
) | ||
|
||
await update_suggestion_message(suggestion=suggestion, bot=ih.bot) | ||
|
||
|
||
@manager.register # type:ignore | ||
class SuggestionsQueueApprove(components.RichButton): | ||
@wrap_with_error_handler() | ||
async def callback(self, inter: interaction.MessageInteraction): | ||
ih = await InteractionHandler.new_handler(inter._wrapped) | ||
qs = await QueuedSuggestion.from_message_id( | ||
inter.message.id, inter.message.channel.id, ih.bot.state | ||
) | ||
cog: SuggestionsCog = ih.bot.cogs.get("SuggestionsCog") # type: ignore | ||
await cog.qs_core.resolve_queued_suggestion( | ||
ih, queued_suggestion=qs, was_approved=True | ||
) | ||
await ih.send(translation_key="PAGINATION_INNER_QUEUE_ACCEPTED") | ||
|
||
|
||
@manager.register # type:ignore | ||
class SuggestionsQueueReject(components.RichButton): | ||
@wrap_with_error_handler() | ||
async def callback(self, inter: interaction.MessageInteraction): | ||
ih = await InteractionHandler.new_handler(inter._wrapped) | ||
qs = await QueuedSuggestion.from_message_id( | ||
inter.message.id, inter.message.channel.id, ih.bot.state | ||
) | ||
cog: SuggestionsCog = ih.bot.cogs.get("SuggestionsCog") # type: ignore | ||
await cog.qs_core.resolve_queued_suggestion( | ||
ih, queued_suggestion=qs, was_approved=False | ||
) | ||
await ih.send(translation_key="PAGINATION_INNER_QUEUE_REJECTED") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import annotations | ||
|
||
import typing | ||
|
||
import logoo | ||
from disnake.ext import components | ||
from disnake.ext.components import interaction | ||
|
||
from suggestions.interaction_handler import InteractionHandler | ||
from suggestions.utility import wrap_with_error_handler | ||
|
||
if typing.TYPE_CHECKING: | ||
from suggestions.cogs.suggestion_queue_cog import SuggestionsQueueCog | ||
|
||
logger = logoo.Logger(__name__) | ||
manager = components.get_manager("suggestions") | ||
|
||
|
||
class QueueButton(components.RichButton): | ||
pid: str | ||
|
||
@wrap_with_error_handler() | ||
async def callback( # type: ignore | ||
self, | ||
inter: interaction.MessageInteraction, | ||
): | ||
ih = await InteractionHandler.new_handler(inter._wrapped) | ||
cog: SuggestionsQueueCog = ih.bot.cogs.get("SuggestionsQueueCog") # type: ignore | ||
await getattr(cog.core, core_mapping[self.__class__])(ih, self.pid) # type: ignore | ||
|
||
|
||
@manager.register # type: ignore | ||
class VirtualApproveButton(QueueButton): | ||
pass | ||
|
||
|
||
@manager.register # type: ignore | ||
class VirtualRejectButton(QueueButton): | ||
pass | ||
|
||
|
||
@manager.register # type: ignore | ||
class QueueStopButton(QueueButton): | ||
pass | ||
|
||
|
||
@manager.register # type: ignore | ||
class QueueNextButton(QueueButton): | ||
pass | ||
|
||
|
||
@manager.register # type: ignore | ||
class QueuePreviousButton(QueueButton): | ||
pass | ||
|
||
|
||
core_mapping = { | ||
VirtualApproveButton: "virtual_approve_button", | ||
VirtualRejectButton: "virtual_reject_button", | ||
QueueStopButton: "stop_button", | ||
QueueNextButton: "next_button", | ||
QueuePreviousButton: "previous_button", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.