mirror of
https://github.com/alterware/aw-bot.git
synced 2025-11-18 09:02:07 +00:00
feat: black list for memes
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Literal
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
|
|
||||||
from database import add_pattern
|
from database import add_pattern, add_user_to_blacklist
|
||||||
|
|
||||||
from bot.config import update_patterns
|
from bot.config import update_patterns
|
||||||
from bot.utils import compile_stats, fetch_game_stats, perform_search
|
from bot.utils import compile_stats, fetch_game_stats, perform_search
|
||||||
@@ -44,6 +44,21 @@ async def setup(bot):
|
|||||||
f"Pattern added!\n**Regex:** `{regex}`\n**Response:** `{response}`"
|
f"Pattern added!\n**Regex:** `{regex}`\n**Response:** `{response}`"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@bot.tree.command(
|
||||||
|
name="add_to_blacklist",
|
||||||
|
description="Add a user to the blacklist.",
|
||||||
|
guild=discord.Object(id=GUILD_ID),
|
||||||
|
)
|
||||||
|
@app_commands.checks.has_permissions(administrator=True)
|
||||||
|
async def add_to_blacklist_cmd(
|
||||||
|
interaction: discord.Interaction, user: discord.User, reason: str
|
||||||
|
):
|
||||||
|
"""Slash command to add a user to the blacklist."""
|
||||||
|
add_user_to_blacklist(user.id, reason)
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"User **{user.name}** has been added to the blacklist.\n**Reason:** `{reason}`"
|
||||||
|
)
|
||||||
|
|
||||||
@bot.tree.command(
|
@bot.tree.command(
|
||||||
name="search",
|
name="search",
|
||||||
description="Search for servers by hostname or IP.",
|
description="Search for servers by hostname or IP.",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import discord
|
|||||||
from bot.utils import timeout_member, aware_utcnow
|
from bot.utils import timeout_member, aware_utcnow
|
||||||
from bot.config import message_patterns
|
from bot.config import message_patterns
|
||||||
|
|
||||||
from database import add_user_to_role
|
from database import add_user_to_role, is_user_blacklisted
|
||||||
|
|
||||||
BOT_LOG = 1112049391482703873
|
BOT_LOG = 1112049391482703873
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ crazy_last_response_time = None
|
|||||||
|
|
||||||
ALLOWED_CHANNELS = [
|
ALLOWED_CHANNELS = [
|
||||||
1110531063744303138, # GENERAL_CHANNEL
|
1110531063744303138, # GENERAL_CHANNEL
|
||||||
|
1112048063448617142, # off-topic
|
||||||
1145458108190163014, # mw2 general
|
1145458108190163014, # mw2 general
|
||||||
1145456435518525611, # mw2 mp
|
1145456435518525611, # mw2 mp
|
||||||
1112016681880014928, # mw2 sp
|
1112016681880014928, # mw2 sp
|
||||||
@@ -327,6 +328,9 @@ async def handle_message(message, bot):
|
|||||||
if message.channel.id not in ALLOWED_CHANNELS:
|
if message.channel.id not in ALLOWED_CHANNELS:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if is_user_blacklisted(message.author.id):
|
||||||
|
return
|
||||||
|
|
||||||
# Check if any of the patterns match the message
|
# Check if any of the patterns match the message
|
||||||
# print('Checking for patterns...')
|
# print('Checking for patterns...')
|
||||||
for pattern in message_patterns:
|
for pattern in message_patterns:
|
||||||
|
|||||||
@@ -87,12 +87,39 @@ def add_user_to_role(user_id: int, role_id: int, user_name: str):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def user_has_role(user_id: int):
|
def user_has_role(user_id: int) -> bool:
|
||||||
"""Checks if a user is in the database."""
|
"""Checks if a user is in the database."""
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM user_roles WHERE user_id = ?", (user_id,))
|
cursor.execute("SELECT 1 FROM user_roles WHERE user_id = ?", (user_id,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return result is not None
|
||||||
|
|
||||||
|
|
||||||
|
def add_user_to_blacklist(user_id: int, reason: str):
|
||||||
|
"""Adds a user to the blacklist."""
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT OR IGNORE INTO black_list (user_id, date_assigned, reason) VALUES (?, ?, ?)",
|
||||||
|
(user_id, aware_utcnow().isoformat(), reason),
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def is_user_blacklisted(user_id: int) -> bool:
|
||||||
|
"""Checks if a user is on the blacklist."""
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("SELECT 1 FROM black_list WHERE user_id = ?", (user_id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
@@ -10,3 +10,9 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
|||||||
date_assigned TEXT,
|
date_assigned TEXT,
|
||||||
user_name TEXT
|
user_name TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS black_list (
|
||||||
|
user_id INTEGER PRIMARY KEY,
|
||||||
|
date_assigned TEXT,
|
||||||
|
reason TEXT
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user