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