Compare commits
No commits in common. "fcc409dd37682391085699f81bdc632de3dfd955" and "a7d187a6459c8e674553ee16cf387618e79a42ea" have entirely different histories.
fcc409dd37
...
a7d187a645
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,7 +74,11 @@ async def apply(ctx):
|
|||
|
||||
print(msg.id)
|
||||
|
||||
MessageDB.add_application_msg(msg.id, ctx.author.id, ctx.guild.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()
|
||||
|
||||
await user.send('Thank you for applying!')
|
||||
|
||||
|
@ -89,8 +93,10 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
)
|
||||
async def accept(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_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()
|
||||
|
||||
modal = ApplicationModal(title=f"Accepting: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("acc")
|
||||
|
@ -104,8 +110,10 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
)
|
||||
async def decline(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_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()
|
||||
|
||||
modal = ApplicationModal(title=f"Declining: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("dec")
|
||||
|
@ -119,7 +127,10 @@ class ApplicationModal(discord.ui.Modal):
|
|||
async def callback(self, interaction: discord.Interaction):
|
||||
reason = self.children[0].value
|
||||
msg_id = str(interaction.message.id)
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_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()
|
||||
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!")
|
||||
|
@ -221,7 +232,11 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
|
||||
print(msg.id)
|
||||
|
||||
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.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()
|
||||
|
||||
await user.send('Thank you for applying!')
|
||||
|
||||
|
|
25
dbutil.py
25
dbutil.py
|
@ -1,25 +0,0 @@
|
|||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
|
||||
class MessageDB():
|
||||
def add_application_msg(msg_id: str, author_id: str, guild_id: str) -> None:
|
||||
data = (msg_id, author_id, guild_id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("INSERT INTO app_msg_db VALUES (?, ?, ?)", data)
|
||||
con.commit()
|
||||
|
||||
def get_application_msg(msg_id: str) -> tuple[str, str]:
|
||||
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()
|
||||
return user_id, guild_id
|
||||
|
||||
def remove_application_msg(msg_id: str) -> None:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"DELETE FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
con.commit()
|
Loading…
Reference in New Issue