This commit is contained in:
2024-09-03 18:09:44 +02:00
parent a74a278fa8
commit 86539ff62f
6 changed files with 21 additions and 24 deletions
+13 -15
View File
@@ -1,4 +1,6 @@
from json import dump, load
from json import dumps, loads
import redis
from config import REDIS_URL
class User:
def __init__(self, balance: int) -> None:
@@ -20,31 +22,27 @@ class User:
class Aura:
data: dict[str, User] = {}
file = ''
def __init__(self, file: str) -> None:
with open(file, 'r')as f:
self.file = file
data = load(f)
for k in data:
self.data[k] = User(data[k]['balance'])
def __init__(self) -> None:
redis_host = REDIS_URL.split(':')
self.r = redis.Redis(host=redis_host[0], port=int(redis_host[1]), decode_responses=True)
self.load()
def load(self) -> None:
with open(self.file, 'r')as f:
data = load(f)
for k in data:
self.data[k] = User(data[k]['balance'])
data = loads(self.r.get('data'))
for k in data:
self.data[k] = User(data[k]['balance'])
def get(self, user_id) -> User | None:
if user_id in self.data:
return self.data[user_id]
return self.r.get(str(user_id))
def add(self, user_id) -> User:
self.data[user_id] = User(100)
self.r.set
return self.data[user_id]
def save(self):
data = {}
for k in self.data:
data[k] = self.data[k].to_dict()
with open(self.file, 'w')as f:
dump(data, f, indent=2)
self.r.set('data', dumps(data, indent=2))
+1 -1
View File
@@ -4,7 +4,7 @@ import discord
from discord import app_commands
from discord.ext import commands
aura = Aura('aura.json')
aura = Aura()
client = discord.Client(intents=discord.Intents.all())
# bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
tree = app_commands.CommandTree(client)
+2
View File
@@ -2,5 +2,7 @@ import os
BOT_TOKEN=os.environ['BOT_TOKEN']
USE_INVITE_SERVER=os.environ['USE_INVITE']=='true'
INVITE_SERVER_URL='127.0.0.1'
INVITE_SERVER_PORT=os.environ['PORT']
INVITE=os.environ['INVITE']
PUNISH_ROLES=(1279588925257683014,)
REDIS_URL=os.environ['REDIS_URL']
+1 -1
View File
@@ -15,4 +15,4 @@ def root(id):
aura.save()
return redirect(INVITE, code=302)
app.run('127.0.0.1', environ['PORT'])
app.run('127.0.0.1', INVITE_SERVER_PORT)
-4
View File
@@ -1,6 +1,5 @@
import os
env = os.environ.copy()
# import install
from config import *
from subprocess import run as run_start
from threading import Thread
@@ -15,6 +14,3 @@ if USE_INVITE_SERVER:t1.start()
t2.start()
while 1:
time.sleep(.5)
# # if input() == 'q':
# if USE_INVITE_SERVER:t1.join(0)
# t2.join(0)
+1
View File
@@ -1,2 +1,3 @@
Flask
discord.py
redis