Add ability to have activity log ignore channels, closes #173
This commit is contained in:
parent
f3974d172f
commit
1bc99520db
3 changed files with 71 additions and 9 deletions
|
@ -110,12 +110,13 @@ class Jarvis(StatsClient):
|
|||
|
||||
async def _prerun(self, ctx: Context, *args, **kwargs) -> None:
|
||||
name = ctx.invoke_target
|
||||
cargs = ""
|
||||
if isinstance(ctx, InteractionContext) and ctx.target_id:
|
||||
kwargs["context target"] = ctx.target
|
||||
args = " ".join(f"{k}:{v}" for k, v in kwargs.items())
|
||||
cargs = " ".join(f"{k}:{v}" for k, v in kwargs.items())
|
||||
elif isinstance(ctx, PrefixedContext):
|
||||
args = " ".join(args)
|
||||
self.logger.debug(f"Running command `{name}` with args: {args or 'None'}")
|
||||
cargs = " ".join(args)
|
||||
self.logger.debug(f"Running command `{name}` with args: {cargs or 'None'}")
|
||||
|
||||
async def _sync_domains(self) -> None:
|
||||
self.logger.debug("Loading phishing domains")
|
||||
|
@ -232,7 +233,8 @@ class Jarvis(StatsClient):
|
|||
name = ctx.invoke_target
|
||||
if not isinstance(ctx.channel, DMChannel) and name not in ["pw"]:
|
||||
modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="activitylog"))
|
||||
if modlog:
|
||||
ignore = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore"))
|
||||
if modlog and (ignore and ctx.channel.id not in ignore.value):
|
||||
channel = await ctx.guild.fetch_channel(modlog.value)
|
||||
args = []
|
||||
if isinstance(ctx, InteractionContext) and ctx.target_id:
|
||||
|
@ -702,7 +704,8 @@ class Jarvis(StatsClient):
|
|||
after = event.after
|
||||
if not after.author.bot:
|
||||
modlog = await Setting.find_one(q(guild=after.guild.id, setting="activitylog"))
|
||||
if modlog:
|
||||
ignore = await Setting.find_one(q(guild=after.guild.id, setting="log_ignore"))
|
||||
if modlog and (ignore and after.channel.id not in ignore.value):
|
||||
if not before or before.content == after.content or before.content is None:
|
||||
return
|
||||
try:
|
||||
|
@ -754,7 +757,8 @@ class Jarvis(StatsClient):
|
|||
"""Process on_message_delete events."""
|
||||
message = event.message
|
||||
modlog = await Setting.find_one(q(guild=message.guild.id, setting="activitylog"))
|
||||
if modlog:
|
||||
ignore = await Setting.find_one(q(guild=message.guild.id, setting="log_ignore"))
|
||||
if modlog and (ignore and message.channel.id not in ignore.value):
|
||||
try:
|
||||
content = message.content or "N/A"
|
||||
except AttributeError:
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
from jarvis_core.db import q
|
||||
from jarvis_core.db.models import Setting
|
||||
from naff import Client, Extension, InteractionContext
|
||||
from naff import AutocompleteContext, Client, Extension, InteractionContext
|
||||
from naff.models.discord.channel import GuildText
|
||||
from naff.models.discord.components import ActionRow, Button, ButtonStyles
|
||||
from naff.models.discord.embed import EmbedField
|
||||
|
@ -17,6 +17,7 @@ from naff.models.naff.application_commands import (
|
|||
slash_option,
|
||||
)
|
||||
from naff.models.naff.command import check
|
||||
from thefuzz import process
|
||||
|
||||
from jarvis.utils import build_embed
|
||||
from jarvis.utils.permissions import admin_or_permissions
|
||||
|
@ -152,6 +153,29 @@ class SettingsCog(Extension):
|
|||
await self.update_settings("notify", active, ctx.guild.id)
|
||||
await ctx.send(f"Settings applied. Notifications active: {active}")
|
||||
|
||||
@set_.subcommand(
|
||||
sub_cmd_name="log_ignore", sub_cmd_description="Ignore a channel for ActivityLog"
|
||||
)
|
||||
@slash_option(
|
||||
name="channel", description="Channel to ignore", opt_type=OptionTypes.CHANNEL, required=True
|
||||
)
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _add_log_ignore(self, ctx: InteractionContext, channel: GuildText) -> None:
|
||||
if not isinstance(channel, GuildText):
|
||||
await ctx.send("Channel must be a GuildText", ephemeral=True)
|
||||
return
|
||||
setting = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore"))
|
||||
if not setting:
|
||||
setting = Setting(guild=ctx.guild.id, setting="log_ignore", value=[])
|
||||
if not setting.value:
|
||||
setting.value = []
|
||||
if channel in setting.value:
|
||||
await ctx.send("Channel already ignored", ephemeral=True)
|
||||
return
|
||||
setting.value.append(channel.id)
|
||||
await setting.commit()
|
||||
await ctx.send("Channel added to ActivityLog ignore list")
|
||||
|
||||
# Unset
|
||||
@unset.subcommand(
|
||||
sub_cmd_name="modlog",
|
||||
|
@ -210,6 +234,37 @@ class SettingsCog(Extension):
|
|||
await self.delete_settings("notify", ctx.guild.id)
|
||||
await ctx.send("Setting `notify` unset")
|
||||
|
||||
@unset.subcommand(
|
||||
sub_cmd_name="log_ignore", sub_cmd_description="Add a channel for ActivityLog"
|
||||
)
|
||||
@slash_option(
|
||||
name="channel",
|
||||
description="Channel to stop ignoring",
|
||||
opt_type=OptionTypes.STRING,
|
||||
required=True,
|
||||
autocomplete=True,
|
||||
)
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _remove_log_ignore(self, ctx: InteractionContext, channel: str) -> None:
|
||||
channel = int(channel)
|
||||
setting = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore"))
|
||||
if not setting or channel not in setting.value:
|
||||
await ctx.send("Channel not being ignored", ephemeral=True)
|
||||
return
|
||||
setting.value.remove(channel)
|
||||
await setting.commit(replace=True)
|
||||
await ctx.send("Channel no longer being ignored")
|
||||
|
||||
@_remove_log_ignore.autocomplete(option_name="channel")
|
||||
async def _channel_search(self, ctx: AutocompleteContext, channel: str) -> None:
|
||||
setting = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore"))
|
||||
if not setting:
|
||||
return {}
|
||||
channels = [ctx.guild.get_channel(x) for x in setting.value]
|
||||
channels = {c.name: c.id for c in channels}
|
||||
options = process.extract(channel, list(channels.keys()), limit=25)
|
||||
await ctx.send(choices=[{"name": c[0], "value": str(channels[c[0]])} for c in options])
|
||||
|
||||
@settings.subcommand(sub_cmd_name="view", sub_cmd_description="View settings")
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _view(self, ctx: InteractionContext) -> None:
|
||||
|
|
7
poetry.lock
generated
7
poetry.lock
generated
|
@ -514,7 +514,7 @@ python-versions = "*"
|
|||
|
||||
[[package]]
|
||||
name = "naff"
|
||||
version = "1.7.1"
|
||||
version = "1.8.0"
|
||||
description = "Not another freaking fork"
|
||||
category = "main"
|
||||
optional = false
|
||||
|
@ -1564,7 +1564,10 @@ mypy-extensions = [
|
|||
{file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
|
||||
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
|
||||
]
|
||||
naff = []
|
||||
naff = [
|
||||
{file = "naff-1.8.0-py3-none-any.whl", hash = "sha256:96284f17841a782bdf4cb1e0b767b75e93a0afb9c0cd852a448e9a475b38efb6"},
|
||||
{file = "naff-1.8.0.tar.gz", hash = "sha256:0fada9174642d6daa5b76f2e52c992722ffc8219ba9067b101d018380df1ad24"},
|
||||
]
|
||||
nafftrack = []
|
||||
nanoid = [
|
||||
{file = "nanoid-2.0.0-py3-none-any.whl", hash = "sha256:90aefa650e328cffb0893bbd4c236cfd44c48bc1f2d0b525ecc53c3187b653bb"},
|
||||
|
|
Loading…
Add table
Reference in a new issue