68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
# cmd_twitch.py
|
|
|
|
from twitchio.ext import commands
|
|
from cmd_common import common_commands as cc
|
|
from modules.permissions import has_permission
|
|
from modules.utility import handle_help_command
|
|
|
|
def setup(bot, db_conn=None, log=None):
|
|
"""
|
|
This function is called to load/attach commands to the `bot`.
|
|
We also attach the db_conn and log so the commands can use them.
|
|
"""
|
|
|
|
# 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)
|
|
|
|
@bot.command(name="greet")
|
|
async def cmd_greet(ctx):
|
|
result = cc.greet(ctx.author.display_name, "Twitch")
|
|
await ctx.send(result)
|
|
|
|
@bot.command(name="ping")
|
|
async def cmd_ping(ctx):
|
|
result = cc.ping()
|
|
await ctx.send(result)
|
|
|
|
@bot.command(name="howl")
|
|
async def cmd_howl(ctx):
|
|
result = cc.howl(ctx.author.display_name)
|
|
await ctx.send(result)
|
|
|
|
@bot.command(name="hi")
|
|
async def cmd_hi(ctx):
|
|
user_id = str(ctx.author.id) # Twitch user ID
|
|
user_roles = [role.lower() for role in ctx.author.badges.keys()] # "roles" from Twitch badges
|
|
|
|
if not has_permission("hi", user_id, user_roles, "twitch"):
|
|
return await ctx.send("You don't have permission to use this command.")
|
|
|
|
await ctx.send("Hello there!")
|
|
|
|
@bot.command(name="quote")
|
|
async def cmd_quote(ctx: commands.Context):
|
|
if not bot.db_conn:
|
|
return await ctx.send("Database is unavailable, sorry.")
|
|
|
|
parts = ctx.message.content.strip().split()
|
|
args = parts[1:] if len(parts) > 1 else []
|
|
|
|
def get_twitch_game_for_channel(chan_name):
|
|
# Placeholder for your actual logic to fetch the current game
|
|
return "SomeGame"
|
|
|
|
await cc.handle_quote_command(
|
|
db_conn=bot.db_conn,
|
|
log_func=bot.log,
|
|
is_discord=False,
|
|
ctx=ctx,
|
|
args=args,
|
|
get_twitch_game_for_channel=get_twitch_game_for_channel
|
|
)
|
|
|
|
@bot.command(name="help")
|
|
async def help_command(ctx):
|
|
parts = ctx.message.content.strip().split()
|
|
cmd_name = parts[1] if len(parts) > 1 else None
|
|
await handle_help_command(ctx, cmd_name, bot, is_discord=False, log_func=bot.log) |