Merge branch 'dev'

This commit is contained in:
Zeva Rose 2022-08-16 12:51:43 -06:00
commit e297480104
9 changed files with 92 additions and 17 deletions

37
jarvis/branding.py Normal file
View file

@ -0,0 +1,37 @@
"""JARVIS brandings."""
PRIMARY_COLOR = "#3498db"
HARD_ACTION = "#ff0000"
MODERATE_ACTION = "#ff9900"
SOFT_ACTION = "#ffff00"
GOOD_ACTION = "#00ff00"
COMMAND_TYPES = {
"HARD": ["ban", "lockdown"],
"MODERATE": ["kick", "mute", "lock"],
"SOFT": ["warning"],
"GOOD": ["unban", "unmute"],
}
CUSTOM_COMMANDS = {}
def get_command_color(command: str) -> str:
"""
Get a command's color.
Args:
command: Command name
Returns:
Hex color string
"""
if command in COMMAND_TYPES["HARD"]:
return HARD_ACTION
elif command in COMMAND_TYPES["MODERATE"]:
return MODERATE_ACTION
elif command in COMMAND_TYPES["SOFT"]:
return SOFT_ACTION
elif command in COMMAND_TYPES["GOOD"]:
return GOOD_ACTION
else:
return CUSTOM_COMMANDS.get(command, PRIMARY_COLOR)

View file

@ -336,7 +336,6 @@ class Jarvis(StatsClient):
title="User Verified",
description=f"{after.mention} was verified",
fields=fields,
color="#fc9e3f",
)
embed.set_author(name=after.display_name, icon_url=after.display_avatar.url)
embed.set_footer(text=f"{after.username}#{after.discriminator} | {after.id}")
@ -368,7 +367,6 @@ class Jarvis(StatsClient):
title="User Roles Changed",
description=f"{after.mention} had roles changed",
fields=fields,
color="#fc9e3f",
)
embed.set_author(name=after.display_name, icon_url=after.display_avatar.url)
embed.set_footer(text=f"{after.username}#{after.discriminator} | {after.id}")
@ -511,7 +509,10 @@ class Jarvis(StatsClient):
)
tracker.inc()
embed = warning_embed(message.author, "Sent an invite link")
await message.channel.send(embeds=embed)
try:
await message.channel.send(embeds=embed)
except Exception:
self.logger.warn("Failed to send warning embed")
async def massmention(self, message: Message) -> None:
"""Handle massmention events."""
@ -547,7 +548,10 @@ class Jarvis(StatsClient):
)
tracker.inc()
embed = warning_embed(message.author, "Mass Mention")
await message.channel.send(embeds=embed)
try:
await message.channel.send(embeds=embed)
except Exception:
self.logger.warn("Failed to send warning embed")
async def roleping(self, message: Message) -> None:
"""Handle roleping events."""
@ -612,7 +616,10 @@ class Jarvis(StatsClient):
)
tracker.inc()
embed = warning_embed(message.author, "Pinged a blocked role/user with a blocked role")
await message.channel.send(embeds=embed)
try:
await message.channel.send(embeds=embed)
except Exception:
self.logger.warn("Failed to send warning embed")
async def phishing(self, message: Message) -> None:
"""Check if the message contains any known phishing domains."""
@ -636,7 +643,10 @@ class Jarvis(StatsClient):
)
tracker.inc()
embed = warning_embed(message.author, "Phishing URL")
await message.channel.send(embeds=embed)
try:
await message.channel.send(embeds=embed)
except Exception:
self.logger.warn("Failed to send warning embed")
try:
await message.delete()
except Exception:
@ -679,7 +689,10 @@ class Jarvis(StatsClient):
tracker.inc()
reasons = ", ".join(item["not_safe_reasons"])
embed = warning_embed(message.author, reasons)
await message.channel.send(embeds=embed)
try:
await message.channel.send(embeds=embed)
except Exception:
self.logger.warn("Failed to send warning embed")
try:
await message.delete()
except Exception:

View file

@ -17,6 +17,7 @@ from naff.models.naff.application_commands import (
)
from naff.models.naff.command import check
from jarvis.branding import get_command_color
from jarvis.utils import build_embed
from jarvis.utils.cogs import ModcaseCog
from jarvis.utils.permissions import admin_or_permissions
@ -54,6 +55,7 @@ class BanCog(ModcaseCog):
title="User Banned",
description=f"Reason: {reason}",
fields=fields,
color=get_command_color("ban"),
)
embed.set_author(
@ -82,6 +84,7 @@ class BanCog(ModcaseCog):
title="User Unbanned",
description=f"<@{user.id}> was unbanned",
fields=[EmbedField(name="Reason", value=reason)],
color=get_command_color("unban"),
)
embed.set_author(
name=user.username,
@ -158,6 +161,7 @@ class BanCog(ModcaseCog):
title=f"You have been banned from {ctx.guild.name}",
description=f"Reason: {reason}",
fields=fields,
color=get_command_color("ban"),
)
user_embed.set_author(
@ -366,6 +370,7 @@ class BanCog(ModcaseCog):
title=title,
description=f"No {'in' if not active else ''}active bans",
fields=[],
color=get_command_color("bans_list"),
)
embed.set_thumbnail(url=ctx.guild.icon.url)
pages.append(embed)

View file

@ -10,6 +10,7 @@ from naff.models.naff.application_commands import (
)
from naff.models.naff.command import check
from jarvis.branding import get_command_color
from jarvis.utils import build_embed
from jarvis.utils.cogs import ModcaseCog
from jarvis.utils.permissions import admin_or_permissions
@ -43,6 +44,7 @@ class KickCog(ModcaseCog):
title=f"You have been kicked from {guild_name}",
description=f"Reason: {reason}",
fields=[],
color=get_command_color("kick"),
)
embed.set_author(

View file

@ -20,6 +20,7 @@ from naff.models.naff.application_commands import (
)
from naff.models.naff.command import check
from jarvis.branding import get_command_color
from jarvis.utils import build_embed
from jarvis.utils.cogs import ModcaseCog
from jarvis.utils.permissions import admin_or_permissions
@ -50,6 +51,7 @@ class MuteCog(ModcaseCog):
EmbedField(name="Reason", value=reason),
EmbedField(name="Until", value=f"<t:{ts}:F> <t:{ts}:R>"),
],
color=get_command_color("mute"),
)
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
embed.set_thumbnail(url=user.display_avatar.url)
@ -211,6 +213,7 @@ class MuteCog(ModcaseCog):
title="User Unmuted",
description=f"{user.mention} has been unmuted",
fields=[],
color=get_command_color("unmute"),
)
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
embed.set_thumbnail(url=user.display_avatar.url)

View file

@ -312,6 +312,13 @@ class TagCog(Extension):
await ctx.send(embeds=embed)
@tag.subcommand(sub_cmd_name="list", sub_cmd_description="List tag names")
async def _list(self, ctx: InteractionContext) -> None:
tags = await Tag.find(q(guild=ctx.guild.id)).to_list(None)
names = "\n".join(f"`{t.name}`" for t in tags)
embed = build_embed(title="All Tags", description=names, fields=[])
await ctx.send(embeds=embed)
@_get.autocomplete("name")
@_edit.autocomplete("name")
@_delete.autocomplete("name")

View file

@ -8,13 +8,6 @@ from io import BytesIO
import numpy as np
from dateparser import parse
from PIL import Image
from tzlocal import get_localzone
from jarvis import const as jconst
from jarvis.data import pigpen
from jarvis.data.robotcamo import emotes, hk, names
from jarvis.utils import build_embed, get_repo_hash
from naff import Client, Extension, InteractionContext, const
from naff.models.discord.channel import GuildCategory, GuildText, GuildVoice
from naff.models.discord.embed import EmbedField
@ -32,6 +25,13 @@ from naff.models.naff.application_commands import (
)
from naff.models.naff.command import cooldown
from naff.models.naff.cooldowns import Buckets
from PIL import Image
from tzlocal import get_localzone
from jarvis import const as jconst
from jarvis.data import pigpen
from jarvis.data.robotcamo import emotes, hk, names
from jarvis.utils import build_embed, get_repo_hash
JARVIS_LOGO = Image.open("jarvis_small.png").convert("RGBA")
@ -187,6 +187,8 @@ class UtilCog(Extension):
if not await ctx.guild.fetch_member(user.id):
await ctx.send("That user isn't in this guild.", ephemeral=True)
return
muted = user.communication_disabled_until is not None
user_roles = user.roles
if user_roles:
user_roles = sorted(user.roles, key=lambda x: -x.position)
@ -215,7 +217,8 @@ class UtilCog(Extension):
)
embed.set_author(
name=f"{user.display_name}#{user.discriminator}", icon_url=user.display_avatar.url
name=f"{'🔇 ' if muted else ''}{user.display_name}#{user.discriminator}",
icon_url=user.display_avatar.url,
)
embed.set_thumbnail(url=user.display_avatar.url)
embed.set_footer(text=f"ID: {user.id}")

View file

@ -7,6 +7,7 @@ from naff.models.discord.embed import Embed, EmbedField
from naff.models.discord.guild import AuditLogEntry
from naff.models.discord.user import Member
from jarvis.branding import PRIMARY_COLOR
from jarvis.config import JarvisConfig
@ -14,7 +15,7 @@ def build_embed(
title: str,
description: str,
fields: list,
color: str = "#FF0000",
color: str = PRIMARY_COLOR,
timestamp: datetime = None,
**kwargs: dict,
) -> Embed:

View file

@ -2,6 +2,7 @@
from naff.models.discord.embed import Embed, EmbedField
from naff.models.discord.user import Member
from jarvis.branding import get_command_color
from jarvis.utils import build_embed
@ -15,7 +16,10 @@ def warning_embed(user: Member, reason: str) -> Embed:
"""
fields = (EmbedField(name="Reason", value=reason, inline=False),)
embed = build_embed(
title="Warning", description=f"{user.mention} has been warned", fields=fields
title="Warning",
description=f"{user.mention} has been warned",
fields=fields,
color=get_command_color("warning"),
)
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")