Compare commits
3 Commits
main
...
444a57b5da
Author | SHA1 | Date |
---|---|---|
fanyx | 444a57b5da | |
fanyx | 1351fab963 | |
fanyx | c3b32462e4 |
|
@ -1,4 +1,2 @@
|
||||||
venv/
|
venv
|
||||||
env/
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
bot.db
|
|
12
main.py
12
main.py
|
@ -1,16 +1,10 @@
|
||||||
|
import sys
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from discord.ext.commands import Bot
|
from discord.ext.commands import Bot
|
||||||
from configparser import ConfigParser
|
from src.utils.config import build_config
|
||||||
from peewee import SqliteDatabase
|
|
||||||
|
|
||||||
# read config at configured location \\ default to 'config.ini'
|
# read config at configured location \\ default to 'config.ini'
|
||||||
config = ConfigParser()
|
config = build_config()
|
||||||
with open('config.ini', 'r') as configfile:
|
|
||||||
config.read_file(configfile)
|
|
||||||
|
|
||||||
# init db
|
|
||||||
db = SqliteDatabase(config['DATABASE']['path'])
|
|
||||||
db.connect()
|
|
||||||
|
|
||||||
# spawn discord bot instance
|
# spawn discord bot instance
|
||||||
# init token from config
|
# init token from config
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
from src.database.models import Role, User, UserRole
|
|
||||||
from main import db
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger('database')
|
|
||||||
|
|
||||||
def create_tables():
|
|
||||||
logger.info('Creating core database tables if necessary.')
|
|
||||||
db.create_tables([User, Role, UserRole])
|
|
|
@ -1,17 +0,0 @@
|
||||||
from peewee import Model, CharField, ForeignKeyField
|
|
||||||
from main import config, db
|
|
||||||
|
|
||||||
class BaseModel(Model):
|
|
||||||
class Meta:
|
|
||||||
database = db
|
|
||||||
|
|
||||||
class User(BaseModel):
|
|
||||||
uuid = CharField(unique=True)
|
|
||||||
|
|
||||||
class Role(BaseModel):
|
|
||||||
name = CharField()
|
|
||||||
|
|
||||||
class UserRole(BaseModel):
|
|
||||||
user = ForeignKeyField(User, User.uuid)
|
|
||||||
role = ForeignKeyField(Role, Role.name)
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
from .database import BaseModel
|
||||||
|
from .models import *
|
|
@ -0,0 +1,15 @@
|
||||||
|
from peewee import Model, SqliteDatabase
|
||||||
|
from main import config
|
||||||
|
|
||||||
|
DB_PATH = 'app.db'
|
||||||
|
|
||||||
|
database = SqliteDatabase(DB_PATH, pragmas={
|
||||||
|
'journal_mode': 'wal',
|
||||||
|
'cache_size': 10000,
|
||||||
|
'foreign_keys': 1
|
||||||
|
})
|
||||||
|
|
||||||
|
class BaseModel(Model):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = database
|
|
@ -0,0 +1,14 @@
|
||||||
|
from .collectible import Collectible
|
||||||
|
from .inventory import Inventory
|
||||||
|
from .item import Item
|
||||||
|
from .recipe import ItemRecipe, ItemRecipeShard
|
||||||
|
from .user import User
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
Collectible
|
||||||
|
, Inventory
|
||||||
|
, Item
|
||||||
|
, ItemRecipe
|
||||||
|
, ItemRecipeShard
|
||||||
|
, User
|
||||||
|
]
|
|
@ -0,0 +1,6 @@
|
||||||
|
from peewee import CharField
|
||||||
|
from src.db import BaseModel
|
||||||
|
|
||||||
|
class Collectible(BaseModel):
|
||||||
|
name = CharField()
|
||||||
|
picture = CharField()
|
|
@ -0,0 +1,7 @@
|
||||||
|
from peewee import CharField, ForeignKeyField, IntegerField
|
||||||
|
from src.db import BaseModel
|
||||||
|
|
||||||
|
class Inventory(BaseModel):
|
||||||
|
user_id = CharField()
|
||||||
|
item_id = ForeignKeyField(Item)
|
||||||
|
amount = IntegerField(default=0)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from peewee import CharField
|
||||||
|
from src.db.database import BaseModel
|
||||||
|
|
||||||
|
class Item(BaseModel):
|
||||||
|
name = CharField()
|
||||||
|
picture = CharField()
|
|
@ -0,0 +1,10 @@
|
||||||
|
from peewee import ForeignKeyField, IntegerField
|
||||||
|
from . import Collectible, Item
|
||||||
|
|
||||||
|
class ItemRecipe(BaseModel):
|
||||||
|
output_item_id = ForeignKeyField(Item)
|
||||||
|
|
||||||
|
class ItemRecipeShard(BaseModel):
|
||||||
|
recipe_id = ForeignKeyField(ItemRecipe)
|
||||||
|
collectible_id = ForeignKeyField(Collectible)
|
||||||
|
amount = IntegerField()
|
|
@ -0,0 +1,8 @@
|
||||||
|
from peewee import CharField, IntegerField
|
||||||
|
from src.db import BaseModel
|
||||||
|
|
||||||
|
class User(BaseModel):
|
||||||
|
user_id = CharField()
|
||||||
|
xp = IntegerField(default=0) # Total xp accumulated
|
||||||
|
xp_mod = IntegerField(default=100) # XP Modifier in Percent // Can be 0 for XP-Lock, but not negative
|
||||||
|
level = IntegerField(default=1)
|
|
@ -1,2 +0,0 @@
|
||||||
def setup(_):
|
|
||||||
pass
|
|
|
@ -1,11 +1,6 @@
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import logging
|
from peewee import *
|
||||||
|
|
||||||
import src.database.migrations.core
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
class Events(commands.Cog):
|
class Events(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -20,9 +15,7 @@ class Events(commands.Cog):
|
||||||
- activity
|
- activity
|
||||||
- presence
|
- presence
|
||||||
"""
|
"""
|
||||||
logger.info("Running database startup migrations.")
|
print(f"[INFO]: Startup complete | {self.bot.user}")
|
||||||
src.database.migrations.core.create_tables()
|
|
||||||
logger.info(f"Startup complete | {self.bot.user}")
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Events(bot))
|
bot.add_cog(Events(bot))
|
|
@ -1,10 +1,11 @@
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from main import config
|
from src.utils.config import build_config
|
||||||
|
|
||||||
|
|
||||||
class Inventory(commands.Cog):
|
class Inventory(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
# self.config = config
|
self.config = build_config()
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@ -30,7 +31,7 @@ class Inventory(commands.Cog):
|
||||||
|
|
||||||
@inventory.command(name="use")
|
@inventory.command(name="use")
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def inventory_use(self, ctx, **kwargs):
|
async def inventory_use(self, ctx, *, ):
|
||||||
"""
|
"""
|
||||||
Use an item in user's inventory
|
Use an item in user's inventory
|
||||||
|
|
||||||
|
@ -39,5 +40,4 @@ class Inventory(commands.Cog):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
bot.add_cog(Inventory(bot))
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
from os import getenv
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
def build_config():
|
||||||
|
if (config_path := getenv("CONFIG_PATH")) is None:
|
||||||
|
config_path = "config.ini"
|
||||||
|
|
||||||
|
config = ConfigParser()
|
||||||
|
try:
|
||||||
|
config.read_file(open(config_path))
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Unable to locate config file. Exiting...")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
return config
|
Loading…
Reference in New Issue