Add /roleping {block,allow}, closes #6. Bump version to 0.9.9. Warn on mass mention/blocked role ping. Update modlog message delete. Update modlog command invoke
This commit is contained in:
parent
c9839b2a66
commit
3ca194e638
3 changed files with 177 additions and 6 deletions
|
@ -13,7 +13,9 @@ from psutil import Process
|
|||
|
||||
from jarvis import logo, utils
|
||||
from jarvis.config import get_config
|
||||
from jarvis.utils import build_embed
|
||||
from jarvis.utils.db import DBManager
|
||||
from jarvis.utils.field import Field
|
||||
|
||||
if asyncio.get_event_loop().is_closed():
|
||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||
|
@ -26,7 +28,7 @@ restart_ctx = None
|
|||
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
|
||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||
jarvis_self = Process()
|
||||
__version__ = "0.9.0"
|
||||
__version__ = "0.9.9"
|
||||
|
||||
|
||||
@jarvis.event
|
||||
|
@ -95,8 +97,68 @@ async def on_message(message: Message):
|
|||
and len(message.mentions) > massmention["value"]
|
||||
):
|
||||
await message.delete()
|
||||
# TODO: Implement warnings on massmention
|
||||
await message.channel.send("Please do not mass mention.")
|
||||
db.jarvis.warns.insert_one(
|
||||
{
|
||||
"user": message.author.id,
|
||||
"reason": "Mass Mention",
|
||||
"admin": get_config().client_id,
|
||||
"time": datetime.now(),
|
||||
"guild": message.guild.id,
|
||||
"duration": 24,
|
||||
"active": True,
|
||||
}
|
||||
)
|
||||
fields = [Field("Reason", "Mass Mention", False)]
|
||||
embed = build_embed(
|
||||
title="Warning",
|
||||
description=f"{message.author.mention} has been warned",
|
||||
fields=fields,
|
||||
)
|
||||
embed.set_author(
|
||||
name=message.author.nick
|
||||
if message.author.nick
|
||||
else message.author.name,
|
||||
icon_url=message.author.avatar_url,
|
||||
)
|
||||
embed.set_footer(
|
||||
text=f"{message.author.name}#{message.author.discriminator} "
|
||||
+ f"| {message.author.id}"
|
||||
)
|
||||
await message.channel.send(embed=embed)
|
||||
roleping = db.jarvis.settings.find_one(
|
||||
{"guild": message.guild.id, "setting": "roleping"}
|
||||
)
|
||||
if roleping and any(
|
||||
x.id in roleping["value"] for x in message.role_mentions
|
||||
):
|
||||
await message.delete()
|
||||
db.jarvis.warns.insert_one(
|
||||
{
|
||||
"user": message.author.id,
|
||||
"reason": "Pinged a blocked role",
|
||||
"admin": get_config().client_id,
|
||||
"time": datetime.now(),
|
||||
"guild": message.guild.id,
|
||||
"duration": 24,
|
||||
"active": True,
|
||||
}
|
||||
)
|
||||
fields = [Field("Reason", "Pinged a blocked role", False)]
|
||||
embed = build_embed(
|
||||
title="Warning",
|
||||
description=f"{message.author.mention} has been warned",
|
||||
fields=fields,
|
||||
)
|
||||
embed.set_author(
|
||||
name=message.author.nick
|
||||
if message.author.nick
|
||||
else message.author.name,
|
||||
icon_url=message.author.avatar_url,
|
||||
)
|
||||
embed.set_footer(
|
||||
text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}"
|
||||
)
|
||||
await message.channel.send(embed=embed)
|
||||
await jarvis.process_commands(message)
|
||||
|
||||
|
||||
|
|
|
@ -829,6 +829,111 @@ class AdminCog(commands.Cog):
|
|||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@cog_ext.cog_slash(
|
||||
name="warnings",
|
||||
description="Get count of user warnings",
|
||||
guild_ids=[418094694325813248, 578757004059738142, 862402786116763668],
|
||||
options=[
|
||||
create_option(
|
||||
name="user",
|
||||
description="User to view",
|
||||
option_type=6,
|
||||
required=True,
|
||||
),
|
||||
],
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _warnings(self, ctx: SlashContext, user: User):
|
||||
await ctx.defer()
|
||||
warnings = list(
|
||||
self.db.jarvis.warns.find(
|
||||
{
|
||||
"user": user.id,
|
||||
"guild": ctx.guild.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
active = len(list(filter(lambda x: x["active"], warnings)))
|
||||
total = len(warnings)
|
||||
fields = [Field("Active", active), Field("Total", total)]
|
||||
embed = build_embed(
|
||||
title="Warnings",
|
||||
description=f"{user.mention} active and total warnings",
|
||||
fields=fields,
|
||||
)
|
||||
embed.set_author(
|
||||
name=user.nick if user.nick else user.name,
|
||||
icon_url=user.avatar_url,
|
||||
)
|
||||
embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}")
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="roleping",
|
||||
name="block",
|
||||
description="Add a role to the roleping blocklist",
|
||||
guild_ids=[418094694325813248, 578757004059738142, 862402786116763668],
|
||||
options=[
|
||||
create_option(
|
||||
name="role",
|
||||
description="Role to add to blocklist",
|
||||
option_type=8,
|
||||
required=True,
|
||||
)
|
||||
],
|
||||
)
|
||||
async def _roleping_block(self, ctx: SlashContext, role: Role):
|
||||
roles = self.db.jarvis.settings.find_one(
|
||||
{"guild": ctx.guild.id, "setting": "roleping"}
|
||||
)
|
||||
if not roles:
|
||||
roles = {"guild": ctx.guild.id, "setting": "roleping", "value": []}
|
||||
|
||||
if role.id in roles["value"]:
|
||||
await ctx.send(f"Role `{role.name}` already in blocklist.")
|
||||
return
|
||||
roles["value"].append(role.id)
|
||||
self.db.jarvis.settings.update_one(
|
||||
{"guild": ctx.guild.id, "setting": "roleping"},
|
||||
{"$set": roles},
|
||||
upsert=True,
|
||||
)
|
||||
await ctx.send(f"Role `{role.name}` added to blocklist.")
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="roleping",
|
||||
name="allow",
|
||||
description="Remove a role from the roleping blocklist",
|
||||
guild_ids=[418094694325813248, 578757004059738142, 862402786116763668],
|
||||
options=[
|
||||
create_option(
|
||||
name="role",
|
||||
description="Role to remove from blocklist",
|
||||
option_type=8,
|
||||
required=True,
|
||||
)
|
||||
],
|
||||
)
|
||||
async def _roleping_allow(self, ctx: SlashContext, role: Role):
|
||||
roles = self.db.jarvis.settings.find_one(
|
||||
{"guild": ctx.guild.id, "setting": "roleping"}
|
||||
)
|
||||
if not roles:
|
||||
await ctx.send("No blocklist configured.")
|
||||
return
|
||||
|
||||
if role.id not in roles["value"]:
|
||||
await ctx.send(f"Role `{role.name}` not in blocklist.")
|
||||
return
|
||||
roles["value"].delete(role.id)
|
||||
self.db.jarvis.settings.update_one(
|
||||
{"guild": ctx.guild.id, "setting": "roleping"},
|
||||
{"$set": roles},
|
||||
upsert=True,
|
||||
)
|
||||
await ctx.send(f"Role `{role.name}` removed blocklist.")
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(AdminCog(bot))
|
||||
|
|
|
@ -396,11 +396,11 @@ class ModlogCog(commands.Cog):
|
|||
{"guild": message.guild.id, "setting": "modlog"}
|
||||
)
|
||||
if modlog:
|
||||
channel = message.guild.get_channel(modlog["value"])
|
||||
fields = [Field("Original Message", message.content, False)]
|
||||
channel = message.guild.get_channel(modlog["value"])
|
||||
embed = build_embed(
|
||||
title="Message Deleted",
|
||||
description=f"{message.author.mention} deleted a message",
|
||||
description=f"{message.author.mention}'s deleted a message",
|
||||
fields=fields,
|
||||
color="#fc9e3f",
|
||||
)
|
||||
|
@ -425,7 +425,11 @@ class ModlogCog(commands.Cog):
|
|||
channel = ctx.guild.get_channel(modlog["value"])
|
||||
fields = [
|
||||
Field("Command", ctx.name),
|
||||
Field("Args", ctx.args, False),
|
||||
Field(
|
||||
"Args",
|
||||
" ".join(ctx.args) if ctx.args else "N/A",
|
||||
False,
|
||||
),
|
||||
]
|
||||
if ctx.subcommand_name:
|
||||
fields.insert(1, Field("Subcommand", ctx.subcommand_name))
|
||||
|
|
Loading…
Add table
Reference in a new issue