up db test
This commit is contained in:
BIN
audio/375664768087752714/bear2_enemy_scav3.wav
Normal file
BIN
audio/375664768087752714/bear2_enemy_scav3.wav
Normal file
Binary file not shown.
BIN
audio/scav1_enemy_contact_07_l.wav
Normal file
BIN
audio/scav1_enemy_contact_07_l.wav
Normal file
Binary file not shown.
BIN
audio/scav1_enemy_contact_08_l.wav
Normal file
BIN
audio/scav1_enemy_contact_08_l.wav
Normal file
Binary file not shown.
BIN
audio/scav1_enemy_contact_15_l.wav
Normal file
BIN
audio/scav1_enemy_contact_15_l.wav
Normal file
Binary file not shown.
BIN
audio/scav2_attention_01_bl.wav
Normal file
BIN
audio/scav2_attention_01_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_contact_01_l.wav
Normal file
BIN
audio/scav2_enemy_contact_01_l.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_contact_07_l.wav
Normal file
BIN
audio/scav2_enemy_contact_07_l.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_contact_15_l.wav
Normal file
BIN
audio/scav2_enemy_contact_15_l.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_contact_22_bl.wav
Normal file
BIN
audio/scav2_enemy_contact_22_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_contact_26_bl.wav
Normal file
BIN
audio/scav2_enemy_contact_26_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_usec_10_bl.wav
Normal file
BIN
audio/scav2_enemy_usec_10_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_usec_11_bl.wav
Normal file
BIN
audio/scav2_enemy_usec_11_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_usec_14_bl.wav
Normal file
BIN
audio/scav2_enemy_usec_14_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_usec_15_bl.wav
Normal file
BIN
audio/scav2_enemy_usec_15_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_enemy_usec_16_bl.wav
Normal file
BIN
audio/scav2_enemy_usec_16_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav2_mutter_06.wav
Normal file
BIN
audio/scav2_mutter_06.wav
Normal file
Binary file not shown.
BIN
audio/scav2_mutter_27_bl.wav
Normal file
BIN
audio/scav2_mutter_27_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_bear_03.wav
Normal file
BIN
audio/scav3_enemy_bear_03.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_bear_04.wav
Normal file
BIN
audio/scav3_enemy_bear_04.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_bear_06_bl.wav
Normal file
BIN
audio/scav3_enemy_bear_06_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_contact_01_l.wav
Normal file
BIN
audio/scav3_enemy_contact_01_l.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_contact_07_l.wav
Normal file
BIN
audio/scav3_enemy_contact_07_l.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_usec_01.wav
Normal file
BIN
audio/scav3_enemy_usec_01.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_usec_03.wav
Normal file
BIN
audio/scav3_enemy_usec_03.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_usec_08.wav
Normal file
BIN
audio/scav3_enemy_usec_08.wav
Normal file
Binary file not shown.
BIN
audio/scav3_enemy_usec_16_bl.wav
Normal file
BIN
audio/scav3_enemy_usec_16_bl.wav
Normal file
Binary file not shown.
BIN
audio/scav3_mutter_30.wav
Normal file
BIN
audio/scav3_mutter_30.wav
Normal file
Binary file not shown.
BIN
audio/scav3_mutter_34_bl.wav
Normal file
BIN
audio/scav3_mutter_34_bl.wav
Normal file
Binary file not shown.
122
test.py
Normal file
122
test.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import sys
|
||||
import threading
|
||||
import logging
|
||||
import discord
|
||||
import sqlite3
|
||||
|
||||
from discord.ext import commands
|
||||
from dislash import InteractionClient, Option, OptionType
|
||||
from discord import app_commands
|
||||
|
||||
|
||||
def insert_varible_into_table(name, userid, isbot, nick, guild):
|
||||
try:
|
||||
sqlite_connection = sqlite3.connect('user.db')
|
||||
cursor = sqlite_connection.cursor()
|
||||
cursor.execute(f'''CREATE TABLE IF NOT EXISTS "{str(guild)}"
|
||||
([userid] INTEGER PRIMARY KEY, [username] TEXT, [nick] TEXT, [isbot] BOOL, [track] TEXT)
|
||||
''')
|
||||
|
||||
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO "{str(guild)}"
|
||||
(username, userid, nick, isbot)
|
||||
VALUES (?, ?, ?, ?)""")
|
||||
|
||||
data_tuple = (name, userid, nick, isbot)
|
||||
cursor.execute(sqlite_insert_with_param, data_tuple)
|
||||
sqlite_connection.commit()
|
||||
|
||||
cursor.close()
|
||||
|
||||
except sqlite3.Error as error:
|
||||
logging.error("Failed to insert Python variable into sqlite table", error)
|
||||
|
||||
|
||||
def _add_audio(guildid, user, audio):
|
||||
try:
|
||||
sql_conn = sqlite3.connect('user.db')
|
||||
cursor = sql_conn.cursor()
|
||||
sql_update_query = f"""UPDATE "{str(guildid)}" set track = ? where userid = ?"""
|
||||
data_tuple = (audio, user.removesuffix('>').removeprefix('<@'))
|
||||
cursor.execute(sql_update_query, data_tuple)
|
||||
sql_conn.commit()
|
||||
|
||||
cursor.close()
|
||||
|
||||
except sqlite3.Error as error:
|
||||
logging.error("Failed to insert Python variable into sqlite table", error)
|
||||
|
||||
|
||||
def _read_db(guildid, user):
|
||||
try:
|
||||
sql_con = sqlite3.connect("user.db")
|
||||
cursor = sql_con.cursor()
|
||||
sql_read = f"""SELECT * FROM "{guildid}" where userid = {user.removesuffix('>').removeprefix('<@')}"""
|
||||
cursor.execute(sql_read)
|
||||
record = cursor.fetchone()
|
||||
if record[4] is None:
|
||||
return "None"
|
||||
else:
|
||||
return record[4]
|
||||
|
||||
except sqlite3.Error as error:
|
||||
logging.error("Failed to read sqlite table", error)
|
||||
finally:
|
||||
if sql_con:
|
||||
sql_con.close()
|
||||
|
||||
|
||||
threading.current_thread().name = "main"
|
||||
logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO',
|
||||
format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s')
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
bot = commands.Bot(command_prefix='$', guild_subscriptions=True, intents=intents)
|
||||
inter_client = InteractionClient(bot)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
for g in bot.get_all_members():
|
||||
insert_varible_into_table(g.name, g.id, g.bot, g.nick, g.guild.id)
|
||||
logging.info(f'Bot started')
|
||||
logging.info('We have logged in as {0.user}'.format(bot))
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_guild_join(guild):
|
||||
for g in guild.members:
|
||||
insert_varible_into_table(g.name, g.id, g.bot, g.nick, guild.id)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_member_join(member):
|
||||
insert_varible_into_table(member.name, member.id, member.bot, member.nick, member.guild.id)
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def add_audio(ctx, user, audio):
|
||||
_add_audio(ctx.guild.id, user, audio)
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def test(ctx, user):
|
||||
await ctx.send(_read_db(ctx.guild.id, user))
|
||||
|
||||
|
||||
@inter_client.slash_command(
|
||||
name="read-audio",
|
||||
description="Shows user's profile",
|
||||
options=[
|
||||
Option("user", "Specify any user", OptionType.USER),
|
||||
]
|
||||
)
|
||||
async def hello(ctx, user, interaction: discord.Interaction):
|
||||
await interaction.deferReply()
|
||||
result = await _read_db(ctx.guild.id, user)
|
||||
await ctx.send(result)
|
||||
|
||||
# await ctx.send(_read_db(ctx.guild.id, user))
|
||||
|
||||
|
||||
bot.run('OTQ3OTUzOTAxNzgzNjIxNjYy.GTXbMv.KrztaTO7-ivsPEAVjsyikSQ-GP-ANwULmDraig')
|
||||
Reference in New Issue
Block a user