Skip to content

Commit

Permalink
Merge pull request #99 from Exenifix/v1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Exenifix authored Feb 16, 2023
2 parents 5c8e064 + bc9261b commit 8eb4a99
Show file tree
Hide file tree
Showing 31 changed files with 1,295 additions and 1,461 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Reqest, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [ pull_request ]

Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/pylint.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Releaser

on:
push:
branches:
- master
workflow_dispatch:

jobs:
release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__
models
local
logs
.ruff_cache
32 changes: 28 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: check-ast
- id: check-json
- id: pretty-format-json
args:
- --autofix
- id: sort-simple-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
args:
- --markdown-linebreak-ext=md
- id: check-toml

- repo: https://github.com/psf/black
rev: 22.6.0
- repo: local
hooks:
- id: black
name: black
language: python
pass_filenames: false
entry: poetry run black .

- id: isort
name: isort
pass_filenames: false
language: python
entry: poetry run isort .

- id: ruff
name: ruff
language: python
pass_filenames: false
entry: poetry run ruff .
args:
- --fix
4 changes: 1 addition & 3 deletions ai/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ def analyse_sample(sample: str) -> analysis_data:
sample = extract_mentions(sample.lower())
nospace = sample.replace(" ", "")
splat = sample.split(" ")
return analysis_data(
len(nospace), len(set(nospace)), len(splat), len(set(splat)), sample
)
return analysis_data(len(nospace), len(set(nospace)), len(splat), len(set(splat)), sample)
55 changes: 31 additions & 24 deletions base_config.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,40 @@ CREATE TABLE IF NOT EXISTS data

CREATE TABLE IF NOT EXISTS guilds
(
id BIGINT UNIQUE NOT NULL,
warnings_threshold INT DEFAULT 3 CHECK (warnings_threshold > 0 AND warnings_threshold <= 10),
timeout_duration INT DEFAULT 15 CHECK (timeout_duration > 0 AND timeout_duration < 80000),
id BIGINT UNIQUE NOT NULL,
warnings_threshold INT DEFAULT 3 CHECK (warnings_threshold > 0 AND warnings_threshold <= 10),
timeout_duration INT DEFAULT 15 CHECK (timeout_duration > 0 AND timeout_duration < 80000),

antispam_enabled BOOLEAN DEFAULT TRUE,
antispam_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],
antispam_enabled BOOLEAN DEFAULT TRUE,
antispam_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],

blacklist_enabled BOOLEAN DEFAULT TRUE,
blacklist_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],
blacklist_common TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_common, 1) <= 50),
blacklist_wild TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_wild, 1) <= 50),
blacklist_super TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_super, 1) <= 50),
blacklist_filter_enabled BOOLEAN DEFAULT TRUE,
blacklist_enabled BOOLEAN DEFAULT TRUE,
blacklist_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],
blacklist_common TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_common, 1) <= 50),
blacklist_wild TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_wild, 1) <= 50),
blacklist_super TEXT[] DEFAULT ARRAY []::TEXT[] CHECK (ARRAY_LENGTH(blacklist_super, 1) <= 50),
blacklist_filter_enabled BOOLEAN DEFAULT TRUE,

whitelist_enabled BOOLEAN DEFAULT FALSE,
whitelist_characters VARCHAR(1024) DEFAULT 'abcdefghijklmnopqrstuvwxyz!@#$%^&*(){}[]<>-_=+?~`:;''"/\|<>.,1234567890',
whitelist_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],
whitelist_enabled BOOLEAN DEFAULT FALSE,
whitelist_characters VARCHAR(1024) DEFAULT 'abcdefghijklmnopqrstuvwxyz!@#$%^&*(){}[]<>-_=+?~`:;''"/\|<>.,1234567890',
whitelist_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],

nickfilter_enabled BOOLEAN DEFAULT TRUE,
nickfilter_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],
nickfilter_enabled BOOLEAN DEFAULT TRUE,
nickfilter_ignored BIGINT[] DEFAULT ARRAY []::BIGINT[],

antiraid_enabled BOOLEAN DEFAULT FALSE,
antiraid_join_interval INT DEFAULT 30,
antiraid_members_limit INT DEFAULT 5,
antiraid_punishment INT DEFAULT 1, -- decodification in utils.enums.AntiraidPunishment
antiraid_enabled BOOLEAN DEFAULT FALSE,
antiraid_join_interval INT DEFAULT 30,
antiraid_members_limit INT DEFAULT 5,
antiraid_punishment INT DEFAULT 1, -- decodification in utils.enums.AntiraidPunishment
antiraid_invite_pause_duration INT,

linkfilter_enabled BOOLEAN DEFAULT TRUE,
linkfilter_enabled BOOLEAN DEFAULT TRUE,

log_channel BIGINT,
log_channel BIGINT,

automod_managers BIGINT[] DEFAULT ARRAY []::BIGINT[],
automod_managers BIGINT[] DEFAULT ARRAY []::BIGINT[],

description TEXT -- used in site API
description TEXT -- used in site API
);

CREATE TABLE IF NOT EXISTS version_data
Expand Down Expand Up @@ -84,3 +85,9 @@ CREATE TABLE IF NOT EXISTS autoslowmode
id BIGINT PRIMARY KEY,
guild_id BIGINT NOT NULL
);

CREATE TABLE IF NOT EXISTS invite_pauses
(
guild_id BIGINT PRIMARY KEY,
paused_till TIMESTAMP NOT NULL
);
80 changes: 17 additions & 63 deletions ext/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class Administration(commands.Cog):
def __init__(self, bot: Bot):
self.bot = bot

async def cog_slash_command_check(
self, inter: disnake.ApplicationCommandInteraction
):
async def cog_slash_command_check(self, inter: disnake.ApplicationCommandInteraction):
if inter.author.guild_permissions.manage_guild:
return True

Expand All @@ -25,85 +23,41 @@ async def admin_group(self, *_):
name="addmanagerrole",
description="Adds a manager role. Managers have permissions to modify filters.",
)
async def admin_addmanagerrole(
self, inter: disnake.ApplicationCommandInteraction, role: disnake.Role
):
async def admin_addmanagerrole(self, inter: disnake.ApplicationCommandInteraction, role: disnake.Role):
await self.bot.db.get_guild(inter.guild.id).add_automod_manager(role.id)
await inter.send(
embed=SuccessEmbed(
inter, f"Successfully added {role.mention} to the manager roles."
)
)
await inter.send(embed=SuccessEmbed(inter, f"Successfully added {role.mention} to the manager roles."))

@admin_group.sub_command(
name="addmanagermember",
description="Adds a manager member. Managers have permissions to modify filters.",
)
async def admin_addmanagermember(
self, inter: disnake.ApplicationCommandInteraction, member: disnake.Member
):
async def admin_addmanagermember(self, inter: disnake.ApplicationCommandInteraction, member: disnake.Member):
await self.bot.db.get_guild(inter.guild.id).add_automod_manager(member.id)
await inter.send(
embed=SuccessEmbed(
inter, f"Successfully added {member.mention} to the managers."
)
)
await inter.send(embed=SuccessEmbed(inter, f"Successfully added {member.mention} to the managers."))

@admin_group.sub_command(
name="removemanagerrole", description="Removes a role from managers."
)
async def admin_removemanagerrole(
self, inter: disnake.ApplicationCommandInteraction, role: disnake.Role
):
@admin_group.sub_command(name="removemanagerrole", description="Removes a role from managers.")
async def admin_removemanagerrole(self, inter: disnake.ApplicationCommandInteraction, role: disnake.Role):
await self.bot.db.get_guild(inter.guild.id).remove_automod_manager(role.id)
await inter.send(
embed=SuccessEmbed(
inter, f"Successfully removed {role.mention} from the manager roles."
)
)
await inter.send(embed=SuccessEmbed(inter, f"Successfully removed {role.mention} from the manager roles."))

@admin_group.sub_command(
name="removemanagermember", description="Removes a member from managers."
)
async def admin_removemanagermember(
self, inter: disnake.ApplicationCommandInteraction, member: disnake.Member
):
@admin_group.sub_command(name="removemanagermember", description="Removes a member from managers.")
async def admin_removemanagermember(self, inter: disnake.ApplicationCommandInteraction, member: disnake.Member):
await self.bot.db.get_guild(inter.guild.id).remove_automod_manager(member.id)
await inter.send(
embed=SuccessEmbed(
inter, f"Successfully removed {member.mention} from the managers."
)
)
await inter.send(embed=SuccessEmbed(inter, f"Successfully removed {member.mention} from the managers."))

@admin_group.sub_command(
name="setlogchannel", description="Sets a channel for logs."
)
async def setlogchannel(
self, inter: disnake.ApplicationCommandInteraction, channel: disnake.TextChannel
):
@admin_group.sub_command(name="setlogchannel", description="Sets a channel for logs.")
async def setlogchannel(self, inter: disnake.ApplicationCommandInteraction, channel: disnake.TextChannel):
if not channel.permissions_for(inter.me).send_messages:
await inter.send(
embed=ErrorEmbed(
inter, "I am not able to send messages in that channel."
)
)
await inter.send(embed=ErrorEmbed(inter, "I am not able to send messages in that channel."))
return

await self.bot.db.get_guild(inter.guild.id).set_log_channel_id(channel.id)
await inter.send(
embed=SuccessEmbed(
inter, f"Successfully set the log channel to {channel.mention}."
)
)
await inter.send(embed=SuccessEmbed(inter, f"Successfully set the log channel to {channel.mention}."))

@admin_group.sub_command(
name="disablelog", description="Disables the logging for this guild."
)
@admin_group.sub_command(name="disablelog", description="Disables the logging for this guild.")
async def disablelog(self, inter: disnake.ApplicationCommandInteraction):
await self.bot.db.get_guild(inter.guild.id).set_log_channel_id(None)
await inter.send(
embed=SuccessEmbed(inter, "Successfully disabled logging in this server.")
)
await inter.send(embed=SuccessEmbed(inter, "Successfully disabled logging in this server."))


def setup(bot: Bot):
Expand Down
26 changes: 17 additions & 9 deletions ext/automod.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from datetime import datetime

import disnake
from disnake.ext import commands
from disnake.ext import commands, tasks

from utils.bot import Bot
from utils.embeds import WarningEmbed
from utils.enums import Stat
from utils.enums import FetchMode, Stat
from utils.filters.blacklist import is_blacklisted
from utils.nicknames import generate_random_nick
from utils.processors.antiraid import AntiraidProcessor
from utils.processors.messages import (
AntiSpamProcessor,
BlacklistProcessor,
WhitelistProcessor,
)
from utils.processors.messages import AntiSpamProcessor, BlacklistProcessor, WhitelistProcessor
from utils.utils import try_send


Expand All @@ -27,6 +23,19 @@ def __init__(self, bot: Bot):
self.permission_warnings: dict[int, datetime] = {}
# structure {guild_id: {member1_id: Queue[Message], member2_id: Queue[Message]}}

self.invite_enabler.start()

@tasks.loop(minutes=1)
async def invite_enabler(self):
guilds = await self.bot.db.execute(
"SELECT guild_id FROM invite_pauses WHERE paused_till < CURRENT_TIMESTAMP", fetch_mode=FetchMode.ALL
)
await self.bot.db.execute("DELETE FROM invite_pauses WHERE paused_till < CURRENT_TIMESTAMP")
for g in guilds:
guild = self.bot.get_guild(g["id"])
if guild is not None:
await guild.edit(invites_disabled=False)

@commands.Cog.listener()
async def on_message_edit(self, before: disnake.Message, after: disnake.Message):
if before.content != after.content:
Expand Down Expand Up @@ -76,8 +85,7 @@ async def _process_message(self, message: disnake.Message):
except disnake.Forbidden:
if (
message.guild.id not in self.permission_warnings
or (datetime.now() - self.permission_warnings[message.guild.id]).seconds
>= 120
or (datetime.now() - self.permission_warnings[message.guild.id]).seconds >= 120
):
self.permission_warnings[message.guild.id] = datetime.now()
try:
Expand Down
Loading

0 comments on commit 8eb4a99

Please sign in to comment.