Skip to content

Commit

Permalink
There
Browse files Browse the repository at this point in the history
  • Loading branch information
JDJGInc authored Apr 25, 2024
1 parent 3ef2639 commit 3b7718d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
26 changes: 4 additions & 22 deletions cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import io
import json
import tempfile
from typing import TYPE_CHECKING

import asqlite
import discord
from discord import app_commands
from discord.ext import commands
Expand Down Expand Up @@ -91,28 +89,12 @@ async def _data(self, interaction: discord.Interaction):
json_response = io.StringIO(json_string)
file = discord.File(json_response, filename="user_data.json")

with tempfile.NamedTemporaryFile(mode="w") as f:
# delete on close may be already used
# delete is necessary possibly but idk, I just know delete_on_close=True isn't in python 3.11
# is delete needed?
# appraently it's also autodeleted
# https://stackoverflow.com/questions/11043372/how-to-use-tempfile-namedtemporaryfile
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
oauth_db = await utils.make_oauth_database(data)

# does f even work with it?
sqlite_file = discord.File(oauth_db, filename="data.db")
# needs to use f.name for the location of the file.

async with asqlite.connect(f.name) as conn:
async with conn.cursor() as cursor:
print(conn)

# I am unsure about what tables in execute right now.

# unsure how to handle the json response right now will ask dpy for help for that.

sqlite_file = discord.File(f.name, filename="data.db")
# needs to use f.name for the location of the file.

files = [file, sqlite_file]
files = [file, sqlite_file]

await interaction.response.send_message(
"Here's your data(stats will be around in the future)",
Expand Down
21 changes: 2 additions & 19 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import json
import os
import secrets
import tempfile
from contextlib import asynccontextmanager
from typing import Dict, Optional, Union

import aiohttp
import asqlite
import asyncpg
import discord
from dotenv import load_dotenv
Expand Down Expand Up @@ -108,23 +106,8 @@ async def full_data(response: Response, code: Optional[str] = None, state: Optio
json_string = json.dumps(data, indent=4)
json_response = io.StringIO(json_string)

# also add support for the asqlite version in the future too.

with tempfile.NamedTemporaryFile(mode="w") as f:
# delete on close may be already used
# delete is necessary possibly but idk, I just know delete_on_close=True isn't in python 3.11
# is delete needed?
# appraently it's also autodeleted
# https://stackoverflow.com/questions/11043372/how-to-use-tempfile-namedtemporaryfile
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

# does f even work with it?

async with asqlite.connect(f.name) as conn:
async with conn.cursor() as cursor:
print(conn)

# unsure how to handle the json response right now will ask dpy for help for that.
oauth_db = await utils.make_oauth_database(data)
# can also be used for bot stuff and for later if this is moved.

# file support

Expand Down
24 changes: 24 additions & 0 deletions utils/extra.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import enum
import tempfile

import asqlite
import discord


Expand All @@ -25,3 +27,25 @@ def stats_builder(data: dict):
connections = data["connections"]
# unknown for connection stats.
nicknames = data["nicknames"]


async def make_oauth_database(oauth_data: dict):
# also add support for the asqlite version in the future too.

with tempfile.NamedTemporaryFile(mode="w") as f:
# delete on close may be already used
# delete is necessary possibly but idk, I just know delete_on_close=True isn't in python 3.11
# is delete needed?
# appraently it's also autodeleted
# https://stackoverflow.com/questions/11043372/how-to-use-tempfile-namedtemporaryfile
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

# does f even work with it?

async with asqlite.connect(f.name) as conn:
async with conn.cursor() as cursor:
print(conn)
# could get the names of the colonums and make them their own tables and make json be a text type?

return f.name
# all you need appreantly.

0 comments on commit 3b7718d

Please sign in to comment.