mirror of
https://github.com/alterware/aw-bot.git
synced 2025-12-11 12:07:50 +00:00
feat: aka message slash command feature
This commit is contained in:
@@ -7,7 +7,13 @@ from discord import app_commands
|
|||||||
from bot.config import message_patterns, update_patterns
|
from bot.config import message_patterns, update_patterns
|
||||||
from bot.log import logger
|
from bot.log import logger
|
||||||
from bot.utils import compile_stats, fetch_game_stats, perform_search
|
from bot.utils import compile_stats, fetch_game_stats, perform_search
|
||||||
from database import add_pattern, add_user_to_blacklist, is_user_blacklisted
|
from database import (
|
||||||
|
add_aka_response,
|
||||||
|
search_aka,
|
||||||
|
add_pattern,
|
||||||
|
add_user_to_blacklist,
|
||||||
|
is_user_blacklisted,
|
||||||
|
)
|
||||||
|
|
||||||
GUILD_ID = 1110531063161299074
|
GUILD_ID = 1110531063161299074
|
||||||
|
|
||||||
@@ -32,6 +38,21 @@ async def setup(bot):
|
|||||||
|
|
||||||
bot.tree.on_error = on_tree_error
|
bot.tree.on_error = on_tree_error
|
||||||
|
|
||||||
|
@bot.tree.command(
|
||||||
|
name="add_aka_message",
|
||||||
|
description="Add a new aka message to the database.",
|
||||||
|
guild=discord.Object(id=GUILD_ID),
|
||||||
|
)
|
||||||
|
@app_commands.checks.has_permissions(administrator=True)
|
||||||
|
async def add_aka_message(
|
||||||
|
interaction: discord.Interaction, aka: str, response: str
|
||||||
|
):
|
||||||
|
"""Slash command to add a new aka pattern to the database."""
|
||||||
|
add_aka_response(aka, response)
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Pattern added!\n**AKA:** `{aka}`\n**Response:** `{response}`"
|
||||||
|
)
|
||||||
|
|
||||||
@bot.tree.command(
|
@bot.tree.command(
|
||||||
name="add_pattern",
|
name="add_pattern",
|
||||||
description="Add a new message pattern to the database.",
|
description="Add a new message pattern to the database.",
|
||||||
@@ -96,9 +117,35 @@ async def setup(bot):
|
|||||||
|
|
||||||
await interaction.response.send_message(stats_message, ephemeral=True)
|
await interaction.response.send_message(stats_message, ephemeral=True)
|
||||||
|
|
||||||
|
@bot.tree.command(
|
||||||
|
name="aka",
|
||||||
|
description="Check if the input matches any predefined aka patterns.",
|
||||||
|
guild=discord.Object(id=GUILD_ID),
|
||||||
|
)
|
||||||
|
async def aka(interaction: discord.Interaction, input: str):
|
||||||
|
"""
|
||||||
|
Slash command to check if the input matches any predefined aka patterns.
|
||||||
|
"""
|
||||||
|
# Check if the user is blacklisted
|
||||||
|
if is_user_blacklisted(interaction.user.id):
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"You are blacklisted from using this command.", ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Search the database for a match
|
||||||
|
response = search_aka(input)
|
||||||
|
|
||||||
|
if response:
|
||||||
|
await interaction.response.send_message(response, ephemeral=False)
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"No matching aka patterns found.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
@bot.tree.command(
|
@bot.tree.command(
|
||||||
name="meme",
|
name="meme",
|
||||||
description="Check if the input matches any predefined memess.",
|
description="Check if the input matches any predefined memes.",
|
||||||
guild=discord.Object(id=GUILD_ID),
|
guild=discord.Object(id=GUILD_ID),
|
||||||
)
|
)
|
||||||
async def meme(interaction: discord.Interaction, input: str):
|
async def meme(interaction: discord.Interaction, input: str):
|
||||||
|
|||||||
@@ -126,3 +126,33 @@ def is_user_blacklisted(user_id: int) -> bool:
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return result is not None
|
return result is not None
|
||||||
|
|
||||||
|
|
||||||
|
def add_aka_response(aka: str, response: str) -> None:
|
||||||
|
"""
|
||||||
|
Insert a new AKA/response pair into the database.
|
||||||
|
"""
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT INTO aka_list (aka, response) VALUES (?, ?)", (aka, response)
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def search_aka(keyword: str) -> str | None:
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Exact match (case-insensitive)
|
||||||
|
cursor.execute(
|
||||||
|
"SELECT response FROM aka_list WHERE LOWER(aka) = LOWER(?) LIMIT 1", (keyword,)
|
||||||
|
)
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return row[0] if row else None
|
||||||
|
|||||||
@@ -16,3 +16,9 @@ CREATE TABLE IF NOT EXISTS black_list (
|
|||||||
date_assigned TEXT,
|
date_assigned TEXT,
|
||||||
reason TEXT
|
reason TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS aka_list (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
aka TEXT NOT NULL,
|
||||||
|
response TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user