mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
add "add_channel" command for premiums
This commit is contained in:
@@ -4,7 +4,7 @@ import discord # pip install pycord
|
||||
import asyncio # pip install asyncio
|
||||
import cogs # import the cogs
|
||||
import datetime # pip install datetime
|
||||
from config import debug, conn, c # import the debug function and the database connection
|
||||
from config import debug, connp, cp # import the debug function and the database connection
|
||||
import apsw # pip install apsw. ApSW is a Python interface to SQLite 3
|
||||
bot = discord.Bot(intents=discord.Intents.all(), help_command=None)
|
||||
|
||||
@@ -37,6 +37,8 @@ async def check_day_task():
|
||||
#add a task to the bot that runs check_day every 1 minute
|
||||
bot.loop.create_task(check_day_task())
|
||||
'''
|
||||
|
||||
|
||||
#run the bot
|
||||
# Replace the following with your bot's token
|
||||
with open("./key.txt") as f:
|
||||
|
||||
@@ -21,7 +21,7 @@ class Chat (discord.Cog) :
|
||||
debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
|
||||
await ctx.respond("Message sent !", ephemeral=True)
|
||||
await ctx.send(message)
|
||||
async def on_message_process(message, self):
|
||||
async def on_message_process(message: discord.Message, self):
|
||||
#my code
|
||||
#debug the thread id
|
||||
debug(f"Thread id: {threading.get_ident()}")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import discord
|
||||
from config import debug, conn, c
|
||||
from config import debug, conn, c, connp, cp
|
||||
|
||||
class Setup (discord.Cog) :
|
||||
def __init__(self, bot: discord.Bot):
|
||||
@@ -77,4 +77,48 @@ class Setup (discord.Cog) :
|
||||
#disable the guild
|
||||
c.execute("UPDATE data SET is_active = ? WHERE guild_id = ?", (False, ctx.guild.id))
|
||||
conn.commit()
|
||||
await ctx.respond("Disabled", ephemeral=True)
|
||||
await ctx.respond("Disabled", ephemeral=True)
|
||||
|
||||
#create a command calles "add channel" that can only be used in premium servers
|
||||
@discord.slash_command(name="add_channel", description="Add a channel to the list of channels")
|
||||
@discord.option(name="channel", description="The channel to add", type=discord.TextChannel, required=False)
|
||||
async def add_channel(self, ctx: discord.ApplicationContext, channel: discord.TextChannel = None):
|
||||
debug(f"The user {ctx.author} ran the add_channel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
|
||||
#check if the guild is in the database
|
||||
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
|
||||
if c.fetchone() is None:
|
||||
await ctx.respond("This server is not setup", ephemeral=True)
|
||||
return
|
||||
#check if the guild is premium
|
||||
try :
|
||||
cp.execute("SELECT premium FROM data WHERE guild_id = ?", (ctx.guild.id,))
|
||||
premium = cp.fetchone()[0]
|
||||
except :
|
||||
premium = 0
|
||||
if not premium:
|
||||
await ctx.respond("This server is not premium", ephemeral=True)
|
||||
return
|
||||
if channel is None:
|
||||
channel = ctx.channel
|
||||
#check if the channel is already in the list
|
||||
cp.execute("SELECT * FROM channels WHERE guild_id = ?", (ctx.guild.id,))
|
||||
guild_channels = cp.fetchone()
|
||||
if guild_channels is None:
|
||||
# if the channel is not in the list, add it
|
||||
cp.execute("INSERT INTO channels VALUES (?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, None, None, None, None))
|
||||
connp.commit()
|
||||
await ctx.respond("Added", ephemeral=True)
|
||||
return
|
||||
channels = guild_channels[1:]
|
||||
if str(channel.id) in channels:
|
||||
await ctx.respond("This channel is already added", ephemeral=True)
|
||||
return
|
||||
for i in range(5):
|
||||
if channels[i] == None:
|
||||
cp.execute(f"UPDATE channels SET channel{i+1} = ? WHERE guild_id = ?", (channel.id, ctx.guild.id))
|
||||
connp.commit()
|
||||
await ctx.respond("Added", ephemeral=True)
|
||||
return
|
||||
await ctx.respond("You can only add 5 channels", ephemeral=True)
|
||||
|
||||
|
||||
@@ -14,4 +14,9 @@ cp = connp.cursor()
|
||||
|
||||
# Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text, tts boolean, pretend_to_be text, pretend_enabled boolean)''')
|
||||
cp.execute('''CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)''')
|
||||
cp.execute('''CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)''')
|
||||
# create table called "channels" if it does not exist with the following columns: guild_id, channel1, channel2, channel3, channel4, channel5
|
||||
cp.execute('''CREATE TABLE IF NOT EXISTS channels (guild_id text, channel1 text, channel2 text, channel3 text, channel4 text, channel5 text)''')
|
||||
|
||||
cp.execute("DELETE FROM channels")
|
||||
connp.commit()
|
||||
Reference in New Issue
Block a user