-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add psychopass and dominator slash commandds
- Loading branch information
Showing
12 changed files
with
398 additions
and
79 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
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,151 @@ | ||
from typing import Union | ||
from loguru import logger as log | ||
from discord import ( | ||
ApplicationContext, | ||
Bot, | ||
Cog, | ||
SlashCommandGroup, | ||
option, | ||
SlashCommandOptionType, | ||
OptionChoice, | ||
) | ||
|
||
from clients.backend.dominator.member_dominators import MemberDominators | ||
from clients.backend.dominator.message_dominators import MessageDominators | ||
from clients.constants import ACTION, ATTR_PRETTY, ATTRIBUTE | ||
from embeds.dominator import embed_dominator | ||
|
||
|
||
class Dominator(Cog): | ||
|
||
base_dominator = SlashCommandGroup( | ||
"dominator", description="configure sibyl's automod capabilities" | ||
) | ||
|
||
def __init__(self, bot: Bot) -> None: | ||
self.bot = bot | ||
|
||
@base_dominator.command(description="configure message dominator") | ||
@option( | ||
"attribute", | ||
type=SlashCommandOptionType.string, | ||
description="attribute to set", | ||
choices=list( | ||
map( | ||
lambda attr: OptionChoice(name=ATTR_PRETTY[attr.value], value=attr), | ||
ATTRIBUTE.__members__.values(), | ||
), | ||
), | ||
) | ||
@option( | ||
"action", | ||
type=ACTION, | ||
description="action to take upon exceeding threshold", | ||
required=False, | ||
) | ||
@option( | ||
"threshold", | ||
type=SlashCommandOptionType.number, | ||
description="threshold for attribute score", | ||
required=False, | ||
min_value=0, | ||
max_value=1, | ||
) | ||
async def message( | ||
self, | ||
ctx: ApplicationContext, | ||
attribute: str, | ||
action: ACTION, | ||
threshold: float, | ||
) -> None: | ||
if not ctx.author.guild_permissions.administrator: | ||
await ctx.followup.send( | ||
"you do not have permissions to configure notification settings" | ||
) | ||
return | ||
await ctx.defer() | ||
|
||
await self.configure_dominator( | ||
ctx, MessageDominators, attribute, action, threshold | ||
) | ||
|
||
@base_dominator.command(description="configure member dominator") | ||
@option( | ||
"attribute", | ||
type=SlashCommandOptionType.string, | ||
description="attribute to set", | ||
choices=list( | ||
map( | ||
lambda attr: OptionChoice(name=ATTR_PRETTY[attr], value=attr), | ||
ATTR_PRETTY.keys(), | ||
) | ||
), | ||
) | ||
@option( | ||
"action", | ||
type=ACTION, | ||
description="action to take upon exceeding threshold", | ||
required=False, | ||
) | ||
@option( | ||
"threshold", | ||
type=SlashCommandOptionType.number, | ||
description="threshold for attribute score", | ||
required=False, | ||
min_value=0, | ||
max_value=1, | ||
) | ||
async def member( | ||
self, | ||
ctx: ApplicationContext, | ||
attribute: str, | ||
action: ACTION, | ||
threshold: float, | ||
) -> None: | ||
if not ctx.author.guild_permissions.administrator: | ||
await ctx.followup.send( | ||
"you do not have permissions to configure notification settings" | ||
) | ||
return | ||
await ctx.defer() | ||
|
||
await self.configure_dominator( | ||
ctx, MemberDominators, attribute, action, threshold | ||
) | ||
|
||
async def configure_dominator( | ||
self, | ||
ctx: ApplicationContext, | ||
dominator: Union[MessageDominators, MemberDominators], | ||
attribute: str, | ||
action: ACTION, | ||
threshold: float, | ||
) -> None: | ||
if attribute == "crime_coefficient_100" and action is not None: | ||
dominator.update( | ||
{"communityID": ctx.guild_id, "crime_coefficient_100_action": action} | ||
) | ||
elif attribute == "crime_coefficient_300" and action is not None: | ||
dominator.update( | ||
{"communityID": ctx.guild_id, "crime_coefficient_300_action": action} | ||
) | ||
else: | ||
trigger_data = {"communityID": ctx.guild_id} | ||
if action is not None: | ||
trigger_data[f"{attribute}_action"] = action | ||
if threshold is not None: | ||
trigger_data[f"{attribute}_threshold"] = threshold | ||
|
||
dominator.update(trigger_data) | ||
|
||
await ctx.edit( | ||
embed=embed_dominator(dominator.read(ctx.guild_id), attribute, ctx.guild) | ||
) | ||
|
||
log.info( | ||
"{} trigger has been successfully updated for {} in server: {} ({})", | ||
attribute, | ||
dominator.__class__.__name__, | ||
ctx.guild.name, | ||
ctx.guild_id, | ||
) |
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,53 @@ | ||
from loguru import logger as log | ||
from discord import ( | ||
ApplicationContext, | ||
Bot, | ||
Cog, | ||
slash_command, | ||
User, | ||
SlashCommandOptionType, | ||
option, | ||
) | ||
|
||
from clients.backend.psychopass.community_psycho_passes import CommmunityPsychoPasses | ||
from clients.backend.psychopass.psycho_passes import PsychoPasses | ||
from embeds.psycho_pass import embed_community_psycho_pass, embed_psycho_pass | ||
|
||
|
||
class PsychoPass(Cog): | ||
|
||
def __init__(self, bot: Bot) -> None: | ||
self.bot = bot | ||
|
||
@slash_command(description="get the psycho-pass of a user or server") | ||
@option( | ||
"user", | ||
type=SlashCommandOptionType.user, | ||
description="gets this user's psycho-pass", | ||
required=False, | ||
) | ||
async def psychopass(self, ctx: ApplicationContext, user: User) -> None: | ||
log.debug("{} /psychopass user: @{}", ctx.guild_id, user) | ||
await ctx.defer() | ||
if user is not None: | ||
log.info( | ||
"@{} ({}) has requested the psycho-pass of @{} ({})", | ||
ctx.user.name, | ||
ctx.user.id, | ||
user.name, | ||
user.id, | ||
) | ||
psycho_pass = PsychoPasses.read(user.id) | ||
await ctx.edit(embed=embed_psycho_pass(psycho_pass, ctx.user, user)) | ||
else: | ||
log.info( | ||
"@{} ({}) has requested the area stress level of {} ({})", | ||
ctx.user.name, | ||
ctx.user.id, | ||
ctx.guild.name, | ||
ctx.guild_id, | ||
) | ||
psycho_pass = CommmunityPsychoPasses.read(ctx.guild_id) | ||
await ctx.edit( | ||
embed=embed_community_psycho_pass(psycho_pass, ctx.user, ctx.guild) | ||
) |
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,35 @@ | ||
from discord import Embed, EmbedAuthor, Guild | ||
|
||
from clients.constants import ATTR_PRETTY, ATTRIBUTE, ACTION | ||
|
||
|
||
def embed_dominator(dominator: dict, attribute: str, server: Guild) -> Embed: | ||
embed = Embed( | ||
description=f"{ATTR_PRETTY[attribute]} updated", | ||
author=EmbedAuthor(name="sibylmod"), | ||
thumbnail=server.icon.url, | ||
) | ||
|
||
if ( | ||
"crime_coefficient_100_action" in dominator.keys() | ||
and "crime_coefficient_300_action" in dominator.keys() | ||
): | ||
embed.title = f"member dominator settings for server: {server.name}" | ||
embed.add_field( | ||
name=f"{ATTR_PRETTY['crime_coefficient_100']} action", | ||
value=ACTION(dominator["crime_coefficient_100_action"]).name, | ||
) | ||
embed.add_field( | ||
name=f"{ATTR_PRETTY['crime_coefficient_300']} action", | ||
value=ACTION(dominator["crime_coefficient_300_action"]).name, | ||
) | ||
else: | ||
embed.title = f"message dominator settings for server: {server.name}" | ||
|
||
for attribute in ATTRIBUTE.__members__.values(): | ||
embed.add_field( | ||
name=f"{ATTR_PRETTY[attribute]} action / threshold", | ||
value=f"{ACTION(dominator[f'{attribute}_action']).name} / {dominator[f'{attribute}_threshold']}", | ||
) | ||
|
||
return embed |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from datetime import datetime, UTC | ||
from discord import Embed, EmbedAuthor, EmbedFooter, Message, Member | ||
from clients.constants import ACTION, ATTR_PRETTY | ||
|
||
|
||
def embed_message_moderation( | ||
message: Message, action: ACTION, reasons: list[tuple] | ||
) -> Embed: | ||
embed = Embed( | ||
title=f"flagged message from {message.author.name}", | ||
url=message.jump_url, | ||
author=EmbedAuthor(name="sibylmod", icon_url=message.author.avatar.url), | ||
timestamp=datetime.now(UTC), | ||
footer=EmbedFooter(text=message.id), | ||
) | ||
|
||
if action is ACTION.BAN: | ||
embed.description = f"banned {message.author.mention}" | ||
elif action is ACTION.KICK: | ||
embed.description = f"kicked {message.author.mention}" | ||
elif action is ACTION.MUTE: | ||
embed.description = f"muted {message.author.mention}" | ||
elif action is ACTION.REMOVE: | ||
embed.description = "removed message" | ||
elif action is ACTION.NOTIFY: | ||
embed.description = "notified moderators" | ||
|
||
for reason in reasons: | ||
attribute, score, threshold = reason | ||
embed.add_field( | ||
name=f"{ATTR_PRETTY[attribute]} / threshold", value=f"{score} / {threshold}" | ||
) | ||
|
||
return embed | ||
|
||
|
||
def embed_member_moderation( | ||
member: Member, action: ACTION, reasons: list[tuple] | ||
) -> Embed: | ||
embed = Embed( | ||
title=f"flagged psycho-pass of {member.name}", | ||
author=EmbedAuthor(name="sibylmod", icon_url=member.avatar.url), | ||
timestamp=datetime.now(UTC), | ||
footer=EmbedFooter(text=member.id), | ||
) | ||
|
||
if action is ACTION.BAN: | ||
embed.description = f"banned {member.mention}" | ||
elif action is ACTION.KICK: | ||
embed.description = f"kicked {member.mention}" | ||
elif action is ACTION.MUTE: | ||
embed.description = f"muted {member.mention}" | ||
elif action >= ACTION.NOTIFY: | ||
embed.description = "notified moderators" | ||
|
||
for reason in reasons: | ||
attribute, score, threshold = reason | ||
embed.add_field( | ||
name=f"{ATTR_PRETTY[attribute]} / threshold", value=f"{score} / {threshold}" | ||
) | ||
|
||
return embed |
Oops, something went wrong.