Converted to use dbutil
parent
838600c369
commit
fcc409dd37
31
bot.py
31
bot.py
|
@ -4,10 +4,10 @@ import asyncio
|
|||
import discord
|
||||
import os
|
||||
import json
|
||||
import sqlite3
|
||||
from dotenv import load_dotenv
|
||||
from discord.ui import Modal, InputText
|
||||
from discord.utils import get
|
||||
from dbutil import MessageDB
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
@ -74,11 +74,7 @@ async def apply(ctx):
|
|||
|
||||
print(msg.id)
|
||||
|
||||
data = (msg.id, ctx.author.id, ctx.guild.id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"INSERT INTO app_msg_db VALUES (?, ?, ?)", data)
|
||||
con.commit()
|
||||
MessageDB.add_application_msg(msg.id, ctx.author.id, ctx.guild.id)
|
||||
|
||||
await user.send('Thank you for applying!')
|
||||
|
||||
|
@ -93,10 +89,8 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
)
|
||||
async def accept(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT user_id, guild_id FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
user_id, guild_id = cur.fetchone()
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
|
||||
modal = ApplicationModal(title=f"Accepting: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("acc")
|
||||
|
@ -110,10 +104,8 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
)
|
||||
async def decline(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT user_id, guild_id FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
user_id, guild_id = cur.fetchone()
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
|
||||
modal = ApplicationModal(title=f"Declining: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("dec")
|
||||
|
@ -127,10 +119,7 @@ class ApplicationModal(discord.ui.Modal):
|
|||
async def callback(self, interaction: discord.Interaction):
|
||||
reason = self.children[0].value
|
||||
msg_id = str(interaction.message.id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT user_id, guild_id FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
user_id, guild_id = cur.fetchone()
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
if self.action == "acc":
|
||||
user = await bot.get_user(user_id).create_dm()
|
||||
await user.send(f"You have been accepted to the CreatTopia Minecraft server!")
|
||||
|
@ -232,11 +221,7 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
|
||||
print(msg.id)
|
||||
|
||||
data = (msg.id, interaction.user.id, interaction.guild.id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"INSERT INTO app_msg_db VALUES (?, ?, ?)", data)
|
||||
con.commit()
|
||||
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id)
|
||||
|
||||
await user.send('Thank you for applying!')
|
||||
|
||||
|
|
Loading…
Reference in New Issue