[GENERAL] Refactoring for DB

This commit is contained in:
Alexis LEBEL
2023-03-31 16:11:03 +02:00
parent 64df09b248
commit ddbeea3ae6
5 changed files with 88 additions and 88 deletions

View File

@@ -1,6 +1,6 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from config import debug, c, max_uses, cp, conn, connp, webhook_url from config import debug, curs_data, max_uses, curs_premium, con_data, con_premium, webhook_url
import makeprompt as mp import makeprompt as mp
import aiohttp import aiohttp

View File

@@ -1,7 +1,7 @@
import discord import discord
import re import re
import os import os
from config import debug, c from config import debug, curs_data
class ManageChat(discord.Cog): class ManageChat(discord.Cog):
@@ -17,8 +17,8 @@ class ManageChat(discord.Cog):
f"The user {ctx.author} ran the cancel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the cancel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond( await ctx.respond(
"This server is not setup, please run /setup", ephemeral=True "This server is not setup, please run /setup", ephemeral=True
) )

View File

@@ -1,7 +1,7 @@
import discord import discord
from discord import default_permissions from discord import default_permissions
import os import os
from config import debug, c, conn from config import debug, curs_data, con_data
import openai import openai
import requests import requests
import toxicity as tox # this is a file called toxicity.py, which contains the toxicity function that allows you to check if a message is toxic or not (it uses the perspective api) import toxicity as tox # this is a file called toxicity.py, which contains the toxicity function that allows you to check if a message is toxic or not (it uses the perspective api)
@@ -81,8 +81,8 @@ class Moderation(discord.Cog):
ephemeral=True, ephemeral=True,
) )
if enable == False: if enable == False:
c.execute("DELETE FROM moderation WHERE guild_id = ?", (str(ctx.guild.id),)) curs_data.execute("DELETE FROM moderation WHERE guild_id = ?", (str(ctx.guild.id),))
conn.commit() con_data.commit()
await ctx.respond("Moderation disabled!", ephemeral=True) await ctx.respond("Moderation disabled!", ephemeral=True)
return return
@@ -91,12 +91,12 @@ class Moderation(discord.Cog):
if message.author == self.bot.user: if message.author == self.bot.user:
return return
try: try:
c.execute( curs_data.execute(
"SELECT * FROM moderation WHERE guild_id = ?", (str(message.guild.id),) "SELECT * FROM moderation WHERE guild_id = ?", (str(message.guild.id),)
) )
except: except:
return return
data = c.fetchone() data = curs_data.fetchone()
if data is None: if data is None:
return return
channel = self.bot.get_channel(int(data[1])) channel = self.bot.get_channel(int(data[1]))

View File

@@ -1,5 +1,5 @@
import discord import discord
from config import debug, conn, c, moderate from config import debug, con_data, curs_data, moderate
from discord import default_permissions from discord import default_permissions
import openai import openai
@@ -38,8 +38,8 @@ class Settings(discord.Cog):
f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# check if the user has entered at least one argument # check if the user has entered at least one argument
@@ -74,40 +74,40 @@ class Settings(discord.Cog):
return return
if max_tokens is None: if max_tokens is None:
if ( if (
c.execute( curs_data.execute(
"SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
is not None is not None
and max_tokens is None and max_tokens is None
): ):
max_tokens = c.execute( max_tokens = curs_data.execute(
"SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
else: else:
max_tokens = 64 max_tokens = 64
if temperature is None: if temperature is None:
if ( if (
c.execute( curs_data.execute(
"SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
is not None is not None
and temperature is None and temperature is None
): ):
temperature = c.execute( temperature = curs_data.execute(
"SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
else: else:
temperature = 0.9 temperature = 0.9
if frequency_penalty is None: if frequency_penalty is None:
if ( if (
c.execute( curs_data.execute(
"SELECT frequency_penalty FROM data WHERE guild_id = ?", "SELECT frequency_penalty FROM data WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
).fetchone()[0] ).fetchone()[0]
is not None is not None
and frequency_penalty is None and frequency_penalty is None
): ):
frequency_penalty = c.execute( frequency_penalty = curs_data.execute(
"SELECT frequency_penalty FROM data WHERE guild_id = ?", "SELECT frequency_penalty FROM data WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
).fetchone()[0] ).fetchone()[0]
@@ -115,14 +115,14 @@ class Settings(discord.Cog):
frequency_penalty = 0.0 frequency_penalty = 0.0
if presence_penalty is None: if presence_penalty is None:
if ( if (
c.execute( curs_data.execute(
"SELECT presence_penalty FROM data WHERE guild_id = ?", "SELECT presence_penalty FROM data WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
).fetchone()[0] ).fetchone()[0]
is not None is not None
and presence_penalty is None and presence_penalty is None
): ):
presence_penalty = c.execute( presence_penalty = curs_data.execute(
"SELECT presence_penalty FROM data WHERE guild_id = ?", "SELECT presence_penalty FROM data WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
).fetchone()[0] ).fetchone()[0]
@@ -130,19 +130,19 @@ class Settings(discord.Cog):
presence_penalty = 0.0 presence_penalty = 0.0
if prompt_size is None: if prompt_size is None:
if ( if (
c.execute( curs_data.execute(
"SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
is not None is not None
and prompt_size is None and prompt_size is None
): ):
prompt_size = c.execute( prompt_size = curs_data.execute(
"SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,) "SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)
).fetchone()[0] ).fetchone()[0]
else: else:
prompt_size = 1 prompt_size = 1
# update the database # update the database
c.execute( curs_data.execute(
"UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", "UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?",
( (
max_tokens, max_tokens,
@@ -153,7 +153,7 @@ class Settings(discord.Cog):
ctx.guild.id, ctx.guild.id,
), ),
) )
conn.commit() con_data.commit()
await ctx.respond("Advanced settings updated", ephemeral=True) await ctx.respond("Advanced settings updated", ephemeral=True)
# create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database # create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database
@@ -164,18 +164,18 @@ class Settings(discord.Cog):
f"The user {ctx.author} ran the default command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the default command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond( await ctx.respond(
"This server is not setup, please run /setup", ephemeral=True "This server is not setup, please run /setup", ephemeral=True
) )
return return
# set the advanced settings (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size) and also prompt_prefix to their default values # set the advanced settings (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size) and also prompt_prefix to their default values
c.execute( curs_data.execute(
"UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", "UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?",
(64, 0.9, 0.0, 0.0, 5, ctx.guild.id), (64, 0.9, 0.0, 0.0, 5, ctx.guild.id),
) )
conn.commit() con_data.commit()
await ctx.respond( await ctx.respond(
"The advanced settings have been set to their default values", "The advanced settings have been set to their default values",
ephemeral=True, ephemeral=True,
@@ -194,16 +194,16 @@ class Settings(discord.Cog):
# this command sends all the data about the guild, including the api key, the channel id, the advanced settings and the uses_count_today # this command sends all the data about the guild, including the api key, the channel id, the advanced settings and the uses_count_today
# check if the guild is in the database # check if the guild is in the database
try: try:
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone() data = curs_data.fetchone()
except: except:
data = None data = None
if data[2] is None: if data[2] is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
try: try:
c.execute("SELECT * FROM model WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM model WHERE guild_id = ?", (ctx.guild.id,))
model = c.fetchone()[1] model = curs_data.fetchone()[1]
except: except:
model = None model = None
if model is None: if model is None:
@@ -233,8 +233,8 @@ class Settings(discord.Cog):
f"The user {ctx.author.name} ran the prefix command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author.name} ran the prefix command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
try: try:
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone() data = curs_data.fetchone()
api_key = data[2] api_key = data[2]
except: except:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
@@ -251,11 +251,11 @@ class Settings(discord.Cog):
) )
return return
await ctx.respond("Prefix changed !", ephemeral=True, delete_after=5) await ctx.respond("Prefix changed !", ephemeral=True, delete_after=5)
c.execute( curs_data.execute(
"UPDATE data SET prompt_prefix = ? WHERE guild_id = ?", "UPDATE data SET prompt_prefix = ? WHERE guild_id = ?",
(prefix, ctx.guild.id), (prefix, ctx.guild.id),
) )
conn.commit() con_data.commit()
# when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention # when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention
@discord.slash_command( @discord.slash_command(
@@ -272,8 +272,8 @@ class Settings(discord.Cog):
) )
# check if the guild is in the database # check if the guild is in the database
try: try:
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone() data = curs_data.fetchone()
api_key = data[2] api_key = data[2]
except: except:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
@@ -291,28 +291,28 @@ class Settings(discord.Cog):
return return
if pretend_to_be == "": if pretend_to_be == "":
pretend_to_be = "" pretend_to_be = ""
c.execute( curs_data.execute(
"UPDATE data SET pretend_enabled = 0 WHERE guild_id = ?", "UPDATE data SET pretend_enabled = 0 WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
) )
conn.commit() con_data.commit()
await ctx.respond("Pretend mode disabled", ephemeral=True, delete_after=5) await ctx.respond("Pretend mode disabled", ephemeral=True, delete_after=5)
await ctx.guild.me.edit(nick=None) await ctx.guild.me.edit(nick=None)
return return
else: else:
c.execute( curs_data.execute(
"UPDATE data SET pretend_enabled = 1 WHERE guild_id = ?", "UPDATE data SET pretend_enabled = 1 WHERE guild_id = ?",
(ctx.guild.id,), (ctx.guild.id,),
) )
conn.commit() con_data.commit()
await ctx.respond("Pretend mode enabled", ephemeral=True, delete_after=5) await ctx.respond("Pretend mode enabled", ephemeral=True, delete_after=5)
# change the bots name on the server wit ctx.guild.me.edit(nick=pretend_to_be) # change the bots name on the server wit ctx.guild.me.edit(nick=pretend_to_be)
await ctx.guild.me.edit(nick=pretend_to_be) await ctx.guild.me.edit(nick=pretend_to_be)
c.execute( curs_data.execute(
"UPDATE data SET pretend_to_be = ? WHERE guild_id = ?", "UPDATE data SET pretend_to_be = ? WHERE guild_id = ?",
(pretend_to_be, ctx.guild.id), (pretend_to_be, ctx.guild.id),
) )
conn.commit() con_data.commit()
# if the usename is longer than 32 characters, shorten it # if the usename is longer than 32 characters, shorten it
if len(pretend_to_be) > 31: if len(pretend_to_be) > 31:
pretend_to_be = pretend_to_be[:32] pretend_to_be = pretend_to_be[:32]
@@ -325,8 +325,8 @@ class Settings(discord.Cog):
guild_id = ctx.guild.id guild_id = ctx.guild.id
# connect to the database # connect to the database
# update the tts value in the database # update the tts value in the database
c.execute("UPDATE data SET tts = 1 WHERE guild_id = ?", (guild_id,)) curs_data.execute("UPDATE data SET tts = 1 WHERE guild_id = ?", (guild_id,))
conn.commit() con_data.commit()
# send a message # send a message
await ctx.respond("TTS has been enabled", ephemeral=True) await ctx.respond("TTS has been enabled", ephemeral=True)
@@ -336,8 +336,8 @@ class Settings(discord.Cog):
guild_id = ctx.guild.id guild_id = ctx.guild.id
# connect to the database # connect to the database
# update the tts value in the database # update the tts value in the database
c.execute("UPDATE data SET tts = 0 WHERE guild_id = ?", (guild_id,)) curs_data.execute("UPDATE data SET tts = 0 WHERE guild_id = ?", (guild_id,))
conn.commit() con_data.commit()
# send a message # send a message
await ctx.respond("TTS has been disabled", ephemeral=True) await ctx.respond("TTS has been disabled", ephemeral=True)
@@ -355,18 +355,18 @@ class Settings(discord.Cog):
@default_permissions(administrator=True) @default_permissions(administrator=True)
async def model(self, ctx: discord.ApplicationContext, model: str = "davinci"): async def model(self, ctx: discord.ApplicationContext, model: str = "davinci"):
try: try:
c.execute("SELECT * FROM model WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM model WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone()[1] data = curs_data.fetchone()[1]
except: except:
data = None data = None
if data is None: if data is None:
c.execute("INSERT INTO model VALUES (?, ?)", (ctx.guild.id, model)) curs_data.execute("INSERT INTO model VALUES (?, ?)", (ctx.guild.id, model))
else: else:
c.execute( curs_data.execute(
"UPDATE model SET model_name = ? WHERE guild_id = ?", "UPDATE model SET model_name = ? WHERE guild_id = ?",
(model, ctx.guild.id), (model, ctx.guild.id),
) )
conn.commit() con_data.commit()
await ctx.respond("Model changed !", ephemeral=True) await ctx.respond("Model changed !", ephemeral=True)
async def images_recognition_autocomplete(ctx: discord.AutocompleteContext): async def images_recognition_autocomplete(ctx: discord.AutocompleteContext):
@@ -383,8 +383,8 @@ class Settings(discord.Cog):
@default_permissions(administrator=True) @default_permissions(administrator=True)
async def images(self, ctx: discord.ApplicationContext, enable_disable: str): async def images(self, ctx: discord.ApplicationContext, enable_disable: str):
try: try:
c.execute("SELECT * FROM images WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM images WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone() data = curs_data.fetchone()
except: except:
data = None data = None
if enable_disable == "enable": if enable_disable == "enable":
@@ -392,15 +392,15 @@ class Settings(discord.Cog):
elif enable_disable == "disable": elif enable_disable == "disable":
enable_disable = 0 enable_disable = 0
if data is None: if data is None:
c.execute( curs_data.execute(
"INSERT INTO images VALUES (?, ?, ?)", (ctx.guild.id, 0, enable_disable) "INSERT INTO images VALUES (?, ?, ?)", (ctx.guild.id, 0, enable_disable)
) )
else: else:
c.execute( curs_data.execute(
"UPDATE images SET is_enabled = ? WHERE guild_id = ?", "UPDATE images SET is_enabled = ? WHERE guild_id = ?",
(enable_disable, ctx.guild.id), (enable_disable, ctx.guild.id),
) )
conn.commit() con_data.commit()
await ctx.respond( await ctx.respond(
"Images recognition has been " "Images recognition has been "
+ ("enabled" if enable_disable == 1 else "disabled"), + ("enabled" if enable_disable == 1 else "disabled"),

View File

@@ -1,5 +1,5 @@
import discord import discord
from config import debug, conn, c, connp, cp from config import debug, con_data, curs_data, con_premium, curs_premium
class Setup(discord.Cog): class Setup(discord.Cog):
@@ -26,26 +26,26 @@ class Setup(discord.Cog):
return return
# check if the guild is already in the database bi checking if there is a key for the guild # check if the guild is already in the database bi checking if there is a key for the guild
try: try:
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
data = c.fetchone() data = curs_data.fetchone()
if data[3] == None: if data[3] == None:
data = None data = None
except: except:
data = None data = None
if data != None: if data != None:
c.execute( curs_data.execute(
"UPDATE data SET channel_id = ?, api_key = ? WHERE guild_id = ?", "UPDATE data SET channel_id = ?, api_key = ? WHERE guild_id = ?",
(channel.id, api_key, ctx.guild.id), (channel.id, api_key, ctx.guild.id),
) )
# c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 5, ctx.guild.id)) # c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 5, ctx.guild.id))
conn.commit() con_data.commit()
await ctx.respond( await ctx.respond(
"The channel id and the api key have been updated", ephemeral=True "The channel id and the api key have been updated", ephemeral=True
) )
else: else:
# in this case, the guild is not in the database, so we add it # in this case, the guild is not in the database, so we add it
c.execute( curs_data.execute(
"INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
( (
ctx.guild.id, ctx.guild.id,
@@ -64,7 +64,7 @@ class Setup(discord.Cog):
False, False,
), ),
) )
conn.commit() con_data.commit()
await ctx.respond( await ctx.respond(
"The channel id and the api key have been added", ephemeral=True "The channel id and the api key have been added", ephemeral=True
) )
@@ -78,16 +78,16 @@ class Setup(discord.Cog):
f"The user {ctx.author} ran the delete command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the delete command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# delete the guild from the database, except the guild id and the uses_count_today # delete the guild from the database, except the guild id and the uses_count_today
c.execute( curs_data.execute(
"UPDATE data SET api_key = ?, channel_id = ?, is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", "UPDATE data SET api_key = ?, channel_id = ?, is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?",
(None, None, False, 50, 0.9, 0.0, 0.0, 0, ctx.guild.id), (None, None, False, 50, 0.9, 0.0, 0.0, 0, ctx.guild.id),
) )
conn.commit() con_data.commit()
await ctx.respond("Deleted", ephemeral=True) await ctx.respond("Deleted", ephemeral=True)
# create a command called "enable" that only admins can use # create a command called "enable" that only admins can use
@@ -104,15 +104,15 @@ class Setup(discord.Cog):
debug( debug(
f"The user {ctx.author} ran the enable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the enable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# enable the guild # enable the guild
c.execute( curs_data.execute(
"UPDATE data SET is_active = ? WHERE guild_id = ?", (True, ctx.guild.id) "UPDATE data SET is_active = ? WHERE guild_id = ?", (True, ctx.guild.id)
) )
conn.commit() con_data.commit()
await ctx.respond("Enabled", ephemeral=True) await ctx.respond("Enabled", ephemeral=True)
# create a command called "disable" that only admins can use # create a command called "disable" that only admins can use
@@ -123,15 +123,15 @@ class Setup(discord.Cog):
f"The user {ctx.author} ran the disable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the disable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# disable the guild # disable the guild
c.execute( curs_data.execute(
"UPDATE data SET is_active = ? WHERE guild_id = ?", (False, ctx.guild.id) "UPDATE data SET is_active = ? WHERE guild_id = ?", (False, ctx.guild.id)
) )
conn.commit() con_data.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 # create a command calles "add channel" that can only be used in premium servers
@@ -152,8 +152,8 @@ class Setup(discord.Cog):
f"The user {ctx.author} ran the add_channel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" 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 # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# check if the guild is premium # check if the guild is premium
@@ -168,8 +168,8 @@ class Setup(discord.Cog):
if channel is None: if channel is None:
channel = ctx.channel channel = ctx.channel
# check if the channel is already in the list # check if the channel is already in the list
c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT channel_id FROM data WHERE guild_id = ?", (ctx.guild.id,))
if str(channel.id) == c.fetchone()[0]: if str(channel.id) == curs_data.fetchone()[0]:
await ctx.respond( await ctx.respond(
"This channel is already set as the main channel", ephemeral=True "This channel is already set as the main channel", ephemeral=True
) )
@@ -182,7 +182,7 @@ class Setup(discord.Cog):
"INSERT INTO channels VALUES (?, ?, ?, ?, ?, ?)", "INSERT INTO channels VALUES (?, ?, ?, ?, ?, ?)",
(ctx.guild.id, channel.id, None, None, None, None), (ctx.guild.id, channel.id, None, None, None, None),
) )
connp.commit() con_premium.commit()
await ctx.respond(f"Added channel **{channel.name}**", ephemeral=True) await ctx.respond(f"Added channel **{channel.name}**", ephemeral=True)
return return
channels = guild_channels[1:] channels = guild_channels[1:]
@@ -195,7 +195,7 @@ class Setup(discord.Cog):
f"UPDATE channels SET channel{i} = ? WHERE guild_id = ?", f"UPDATE channels SET channel{i} = ? WHERE guild_id = ?",
(channel.id, ctx.guild.id), (channel.id, ctx.guild.id),
) )
connp.commit() con_premium.commit()
await ctx.respond(f"Added channel **{channel.name}**", ephemeral=True) await ctx.respond(f"Added channel **{channel.name}**", ephemeral=True)
return return
await ctx.respond("You can only add 5 channels", ephemeral=True) await ctx.respond("You can only add 5 channels", ephemeral=True)
@@ -218,8 +218,8 @@ class Setup(discord.Cog):
f"The user {ctx.author} ran the remove_channel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}" f"The user {ctx.author} ran the remove_channel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}"
) )
# check if the guild is in the database # check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone() is None: if curs_data.fetchone() is None:
await ctx.respond("This server is not setup", ephemeral=True) await ctx.respond("This server is not setup", ephemeral=True)
return return
# check if the guild is premium # check if the guild is premium
@@ -236,8 +236,8 @@ class Setup(discord.Cog):
# check if the channel is in the list # check if the channel is in the list
cp.execute("SELECT * FROM channels WHERE guild_id = ?", (ctx.guild.id,)) cp.execute("SELECT * FROM channels WHERE guild_id = ?", (ctx.guild.id,))
guild_channels = cp.fetchone() guild_channels = cp.fetchone()
c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (ctx.guild.id,)) curs_data.execute("SELECT channel_id FROM data WHERE guild_id = ?", (ctx.guild.id,))
if str(channel.id) == c.fetchone()[0]: if str(channel.id) == curs_data.fetchone()[0]:
await ctx.respond( await ctx.respond(
"This channel is set as the main channel and therefore cannot be removed. Type /setup to change the main channel.", "This channel is set as the main channel and therefore cannot be removed. Type /setup to change the main channel.",
ephemeral=True, ephemeral=True,
@@ -261,6 +261,6 @@ class Setup(discord.Cog):
f"UPDATE channels SET channel{i} = ? WHERE guild_id = ?", f"UPDATE channels SET channel{i} = ? WHERE guild_id = ?",
(None, ctx.guild.id), (None, ctx.guild.id),
) )
connp.commit() con_premium.commit()
await ctx.respond(f"Removed channel **{channel.name}**", ephemeral=True) await ctx.respond(f"Removed channel **{channel.name}**", ephemeral=True)
return return