Skip to content

Commit

Permalink
/staffban
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimShadyIAm committed Apr 12, 2022
1 parent 7cdfc5a commit 6835c5f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created - for example installing curl.
"postCreateCommand": "echo \"alias gir='python sync_commands.py && nodemon --exec python ./main.py'\" >> ~/.bashrc",
"postCreateCommand": "echo \"alias gir='nodemon --exec python ./main.py'\" >> ~/.bashrc",

// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
Expand Down
49 changes: 49 additions & 0 deletions cogs/commands/mod/modactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from discord.utils import escape_markdown, escape_mentions
from utils import GIRContext, cfg, transform_context
from utils.framework import mod_and_up, ModsAndAboveMemberOrUser, Duration, ModsAndAboveMember, UserOnly
from utils.framework.checks import admin_and_up
from utils.mod import (add_ban_case, add_kick_case, notify_user,
prepare_editreason_log, prepare_liftwarn_log,
prepare_mute_log, prepare_removepoints_log,
prepare_unban_log, prepare_unmute_log,
submit_public_log, warn)
from utils.views import warn_autocomplete
from utils.views.confirm import SecondStaffConfirm


class ModActions(commands.Cog):
Expand Down Expand Up @@ -201,6 +203,53 @@ async def ban(self, ctx: GIRContext, user: ModsAndAboveMemberOrUser, reason: str
await ctx.respond_or_edit(embed=log, delete_after=10)
await submit_public_log(ctx, db_guild, user, log)

@admin_and_up()
@app_commands.guilds(cfg.guild_id)
@app_commands.command(description="Ban a user anonymously")
@app_commands.describe(user="User to ban")
@app_commands.describe(reason="Reason for banning")
@transform_context
async def staffban(self, ctx: GIRContext, user: ModsAndAboveMemberOrUser, reason: str):
reason = escape_markdown(reason)
reason = escape_mentions(reason)
db_guild = guild_service.get_guild()

member_is_external = isinstance(user, discord.User)

# if the ID given is of a user who isn't in the guild, try to fetch the profile
if member_is_external:
if self.bot.ban_cache.is_banned(user.id):
raise commands.BadArgument("That user is already banned!")

confirm_embed = discord.Embed(description=f"{ctx.author.mention} wants to staff ban {user.mention} with reason `{reason}`. Another mod needs to click Yes to submit this ban.", color=discord.Color.blurple)
view = SecondStaffConfirm(ctx, ctx.author)
await ctx.respond_or_edit(view=view, embed=confirm_embed)
await view.wait()

if not view.value:
await ctx.send_warning(f"Cancelled staff banning {user.mention}.")
return

self.bot.ban_cache.ban(user.id)
log = await add_ban_case(user, ctx.author, reason, db_guild)

log.set_field_at(1, name="Mod", value=f"{ctx.guild.name} Staff")
log.set_thumbnail(url=ctx.guild.icon.url)

if not member_is_external:
if cfg.ban_appeal_url is None:
await notify_user(user, f"You have been banned from {ctx.guild.name}", log)
else:
await notify_user(user, f"You have been banned from {ctx.guild.name}\n\nIf you would like to appeal your ban, please fill out this form: <{cfg.ban_appeal_url}>", log)
await user.ban(reason=reason)
else:
# hackban for user not currently in guild
await ctx.guild.ban(discord.Object(id=user.id))

await ctx.interaction.message.delete()
await ctx.respond_or_edit(embed=log, delete_after=10)
await submit_public_log(ctx, db_guild, user, log)

@mod_and_up()
@app_commands.guilds(cfg.guild_id)
@app_commands.command(description="Unban a user")
Expand Down
34 changes: 33 additions & 1 deletion utils/views/confirm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import discord
from discord import ui
from utils.context import GIRContext
from utils import GIRContext
from utils.framework import gatekeeper


class Confirm(ui.View):
Expand Down Expand Up @@ -35,3 +36,34 @@ async def cancel(self, interaction: discord.Interaction, _: ui.Button):
await self.ctx.send_warning(description=self.false_response)
self.value = False
self.stop()


class SecondStaffConfirm(ui.View):
def __init__(self, ctx: GIRContext, og_mod: discord.Member):
super().__init__(timeout=20)
self.ctx = ctx
self.value = None
self.og_mod = og_mod

async def on_timeout(self) -> None:
await self.ctx.send_warning("Timed out.")
return await super().on_timeout()

async def interaction_check(self, interaction: discord.Interaction) -> bool:
return interaction.user != self.ctx.author and gatekeeper.has(self.ctx.guild, interaction.user, 6)

# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@ui.button(label='Yes', style=discord.ButtonStyle.success)
async def confirm(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
self.value = True
self.stop()

# This one is similar to the confirmation button except sets the inner value to `False`
@ui.button(label='No', style=discord.ButtonStyle.grey)
async def cancel(self, interaction: discord.Interaction, _: ui.Button):
self.ctx.interaction = interaction
self.value = False
self.stop()

0 comments on commit 6835c5f

Please sign in to comment.