-
-
Notifications
You must be signed in to change notification settings - Fork 40
565 add poll ban #567
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
Merged
+249
−1
Merged
565 add poll ban #567
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3561765
add pollban command cog
basil-squared 06dfab4
update flags.py to include pollban/unban
basil-squared 1b5b8c5
update schema.prisma casetype
basil-squared 65466b5
Added the code, heavily derived off of the snippet ban code. gonna in…
basil-squared 7fe7b85
integrate poll banning into poll code, gonna see if this code is working
basil-squared ce65157
Finish up Pollban code and fix some bugs
basil-squared 7e1bb4f
make unbanning people possible.
basil-squared 6022a1d
add assertation to poll.py
basil-squared 6241e21
add assertation (another) to poll.py
basil-squared ddb12e5
Merge branch 'main' into 565-add-poll-ban
basil-squared fa21fb0
Merge branch 'main' into 565-add-poll-ban
basil-squared 887ad47
fix(poll.py) update poll banned message for consistency and professio…
electron271 83b028b
note(poll.py) address note (see commit desc)
electron271 afb9377
finish pollban
electron271 0b11407
Merge branch 'main' into 565-add-poll-ban
electron271 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -170,4 +170,6 @@ enum CaseType { | |
| UNJAIL | ||
| SNIPPETUNBAN | ||
| UNTEMPBAN | ||
| POLLBAN | ||
| POLLUNBAN | ||
| } | ||
This file contains hidden or 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 hidden or 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,71 @@ | ||
| import discord | ||
| from discord.ext import commands | ||
| from loguru import logger | ||
|
|
||
| from prisma.enums import CaseType | ||
| from tux.bot import Tux | ||
| from tux.database.controllers.case import CaseController | ||
| from tux.utils import checks | ||
| from tux.utils.flags import PollBanFlags, generate_usage | ||
|
|
||
| from . import ModerationCogBase | ||
|
|
||
|
|
||
| class PollBan(ModerationCogBase): | ||
| def __init__(self, bot: Tux) -> None: | ||
| super().__init__(bot) | ||
| self.case_controller = CaseController() | ||
| self.poll_ban.usage = generate_usage(self.poll_ban, PollBanFlags) | ||
|
|
||
| @commands.hybrid_command( | ||
| name="pollban", | ||
| aliases=["pb"], | ||
| ) | ||
| @commands.guild_only() | ||
| @checks.has_pl(3) | ||
| async def poll_ban( | ||
| self, | ||
| ctx: commands.Context[Tux], | ||
| member: discord.Member, | ||
| *, | ||
| flags: PollBanFlags, | ||
| ) -> None: | ||
| """ | ||
| Ban a user from creating polls using tux. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ctx : commands.Context[Tux] | ||
| The context object. | ||
| member : discord.Member | ||
| The member to poll ban. | ||
| flags : PollBanFlags | ||
| The flags for the command. (reason: str, silent: bool) | ||
| """ | ||
|
|
||
| assert ctx.guild | ||
|
|
||
| if await self.is_pollbanned(ctx.guild.id, member.id): | ||
| await ctx.send("User is already poll banned.", delete_after=30, ephemeral=True) | ||
| return | ||
|
|
||
| try: | ||
| case = await self.db.case.insert_case( | ||
| case_user_id=member.id, | ||
| case_moderator_id=ctx.author.id, | ||
| case_type=CaseType.POLLBAN, | ||
| case_reason=flags.reason, | ||
| guild_id=ctx.guild.id, | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Failed to ban {member}. {e}") | ||
| await ctx.send(f"Failed to ban {member}. {e}", delete_after=30) | ||
| return | ||
|
|
||
| dm_sent = await self.send_dm(ctx, flags.silent, member, flags.reason, "poll banned") | ||
| await self.handle_case_response(ctx, CaseType.POLLBAN, case.case_number, flags.reason, member, dm_sent) | ||
|
|
||
|
|
||
| async def setup(bot: Tux) -> None: | ||
| await bot.add_cog(PollBan(bot)) | ||
This file contains hidden or 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,71 @@ | ||
| import discord | ||
| from discord.ext import commands | ||
| from loguru import logger | ||
|
|
||
| from prisma.enums import CaseType | ||
| from tux.bot import Tux | ||
| from tux.database.controllers.case import CaseController | ||
| from tux.utils import checks | ||
| from tux.utils.flags import PollUnbanFlags, generate_usage | ||
|
|
||
| from . import ModerationCogBase | ||
|
|
||
|
|
||
| class PollUnban(ModerationCogBase): | ||
electron271 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __init__(self, bot: Tux) -> None: | ||
| super().__init__(bot) | ||
| self.case_controller = CaseController() | ||
| self.poll_unban.usage = generate_usage(self.poll_unban, PollUnbanFlags) | ||
|
|
||
| @commands.hybrid_command( | ||
| name="pollunban", | ||
| aliases=["pub"], | ||
| ) | ||
| @commands.guild_only() | ||
| @checks.has_pl(3) | ||
| async def poll_unban( | ||
| self, | ||
| ctx: commands.Context[Tux], | ||
| member: discord.Member, | ||
| *, | ||
| flags: PollUnbanFlags, | ||
| ): | ||
| """ | ||
| Unban a user from creating snippets. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ctx : commands.Context[Tux] | ||
| The context object. | ||
| member : discord.Member | ||
| The member to snippet unban. | ||
| flags : PollUnbanFlags | ||
| The flags for the command. (reason: str, silent: bool) | ||
| """ | ||
|
|
||
| assert ctx.guild | ||
|
|
||
| if not await self.is_pollbanned(ctx.guild.id, member.id): | ||
| await ctx.send("User is not poll banned.", delete_after=30, ephemeral=True) | ||
| return | ||
|
|
||
| try: | ||
| case = await self.db.case.insert_case( | ||
| case_user_id=member.id, | ||
| case_moderator_id=ctx.author.id, | ||
| case_type=CaseType.POLLUNBAN, | ||
| case_reason=flags.reason, | ||
| guild_id=ctx.guild.id, | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Failed to poll unban {member}. {e}") | ||
| await ctx.send(f"Failed to poll unban {member}. {e}", delete_after=30, ephemeral=True) | ||
| return | ||
|
|
||
| dm_sent = await self.send_dm(ctx, flags.silent, member, flags.reason, "poll unbanned") | ||
| await self.handle_case_response(ctx, CaseType.POLLUNBAN, case.case_number, flags.reason, member, dm_sent) | ||
|
|
||
|
|
||
| async def setup(bot: Tux) -> None: | ||
| await bot.add_cog(PollUnban(bot)) | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.