77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
# cmd_discord.py
|
|
from discord.ext import commands
|
|
from cmd_common import common_commands as cc
|
|
from modules.permissions import has_permission
|
|
|
|
|
|
def setup(bot, db_conn=None, log=None):
|
|
"""
|
|
Attach commands to the Discord bot, store references to db/log.
|
|
"""
|
|
|
|
# auto-create the quotes table if it doesn't exist
|
|
if bot.db_conn and bot.log:
|
|
cc.create_quotes_table(bot.db_conn, bot.log)
|
|
|
|
# Auto-create the quotes table if desired
|
|
if db_conn and log:
|
|
cc.create_quotes_table(db_conn, log)
|
|
@bot.command()
|
|
async def greet(ctx):
|
|
result = cc.greet(ctx.author.display_name, "Discord")
|
|
await ctx.send(result)
|
|
|
|
@bot.command()
|
|
async def ping(ctx):
|
|
result = cc.ping()
|
|
await ctx.send(result)
|
|
|
|
@bot.command()
|
|
async def howl(ctx):
|
|
"""Calls the shared !howl logic."""
|
|
result = cc.howl(ctx.author.display_name)
|
|
await ctx.send(result)
|
|
|
|
@bot.command()
|
|
async def reload(ctx):
|
|
""" Dynamically reloads Discord commands. """
|
|
try:
|
|
import cmd_discord
|
|
import importlib
|
|
importlib.reload(cmd_discord)
|
|
cmd_discord.setup(bot)
|
|
await ctx.send("Commands reloaded!")
|
|
except Exception as e:
|
|
await ctx.send(f"Error reloading commands: {e}")
|
|
|
|
@bot.command()
|
|
async def hi(ctx):
|
|
user_id = str(ctx.author.id)
|
|
user_roles = [role.name.lower() for role in ctx.author.roles] # Normalize to lowercase
|
|
|
|
if not has_permission("hi", user_id, user_roles, "discord"):
|
|
await ctx.send("You don't have permission to use this command.")
|
|
return
|
|
|
|
await ctx.send("Hello there!")
|
|
|
|
@bot.command(name="quote")
|
|
async def quote_command(ctx, *args):
|
|
"""
|
|
!quote
|
|
!quote add <text>
|
|
!quote remove <id>
|
|
!quote <id>
|
|
"""
|
|
if not bot.db_conn:
|
|
return await ctx.send("Database is unavailable, sorry.")
|
|
|
|
# Send to our shared logic
|
|
await cc.handle_quote_command(
|
|
db_conn=bot.db_conn,
|
|
log_func=bot.log,
|
|
is_discord=True,
|
|
ctx=ctx,
|
|
args=list(args),
|
|
get_twitch_game_for_channel=None # None for Discord
|
|
) |