cadence_caster/commands.py
2024-12-15 11:40:06 -06:00

34 lines
1.2 KiB
Python

import sqlite3
from discord.ext import commands
from database import conn, cursor
def setup_commands(bot):
@bot.command()
async def addfeed(ctx, feed_url: str):
try:
cursor.execute("INSERT INTO feeds (url) VALUES (?)", (feed_url,))
conn.commit()
await ctx.send(f"Feed added: {feed_url}")
except sqlite3.IntegrityError:
await ctx.send(f"Feed already exists: {feed_url}")
except Exception as e:
await ctx.send(f"Error adding feed: {e}")
@bot.command()
async def removefeed(ctx, feed_url: str):
cursor.execute("DELETE FROM feeds WHERE url = ?", (feed_url,))
if cursor.rowcount > 0:
conn.commit()
await ctx.send(f"Feed removed: {feed_url}")
else:
await ctx.send(f"Feed not found: {feed_url}")
@bot.command()
async def listfeeds(ctx):
cursor.execute("SELECT url FROM feeds")
feeds = cursor.fetchall()
if feeds:
feed_list = "\n".join(feed[0] for feed in feeds)
await ctx.send(f"Current feeds:\n{feed_list}")
else:
await ctx.send("No feeds available.")