Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'rewrite' of https://github.com/RealistikDash/GDPyS into…
Browse files Browse the repository at this point in the history
… rewrite
  • Loading branch information
RealistikDash committed Oct 2, 2020
2 parents ec07f92 + e776fec commit e1db573
Show file tree
Hide file tree
Showing 8 changed files with 1,053 additions and 16 deletions.
1,005 changes: 1,005 additions & 0 deletions GDPyS.sql

Large diffs are not rendered by default.

Empty file added api/__init__.py
Empty file.
8 changes: 5 additions & 3 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from aiohttp import web
#from aiohttp import web
#from .routes import user_handler

api = web.Application()
# work on this later
#app = web.Application()

#app.router.add_post("/user/{userid}", user_handler)
7 changes: 7 additions & 0 deletions api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import aiohttp
#from helpers.userhelper import user_helper

#async def user_handler(request:aiohttp.web.Request):
# user = request.match_info["userid"]
# print(type(user))
# return user_helper.get_object(user)
12 changes: 10 additions & 2 deletions gdpys/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from aiohttp.payload_streamer import streamer
from helpers.userhelper import user_helper
from helpers.levelhelper import level_helper
from helpers.generalhelper import dict_keys
from helpers.generalhelper import dict_keys, deprecated
from helpers.timehelper import get_timestamp
from objects.comments import CommandContext, Comment, CommentBan
from constants import Permissions
from config import user_config
from exceptions import GDPySCommandError
from objects.levels import Level, Rating
from objects.levels import Level, Rating, DailyLevel

COMMANDS = {}

Expand Down Expand Up @@ -56,6 +56,14 @@ async def rate_level(self, rating: Rating):
"""Rates a level given a Rating object"""
return await level_helper.rate_level(rating)

async def get_daily_level(self) -> DailyLevel:
"""Get the current daily level"""
return await level_helper.get_daily_level()

#async def get_weekly_level(self) -> WeeklyLevel:
# """Get the current weekly level"""
# return await level_helper.get_weekly_level()

############################
# Commands #
############################
Expand Down
25 changes: 17 additions & 8 deletions gdpys/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ class Plugin:
def __init__(self):
"""Start main loop"""
depend_check = []
for p in self.dependencies:
for f in os.listdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/plugins"):
f = f.strip(".py")
if p == f:
depend_check.append(p)
if depend_check != self.dependencies:
print(f"Dependencies could not be found for \"{self.__class__}\".")
try:
for p in self.dependencies:
for f in os.listdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/plugins"):
f = f.strip(".py")
if p == f:
depend_check.append(p)
if depend_check != self.dependencies:
print(f"Dependencies could not be found for \"{self.__class__}\".")
except AttributeError:
print("Dependencies is disabled for " + str(self.__class__))
self.stopped = False
loop = asyncio.new_event_loop()
configpath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/plugins/config"
self.config = json.load(open(configpath + "/" + self.name + "/config.json", "r"))
try:
self.config = json.load(open(configpath + "/" + self.name + "/config.json", "r"))
except AttributeError:
print("Warning: Config is disabled for " + str(self.__class__))
except FileNotFoundError:
print("Warning: Config is disabled for " + str(self.__class__))
if self.metadata == False:
print(f"Warning: Plugin {self.__class__} has invalid metadata!")
while True:
Expand All @@ -30,6 +38,7 @@ def create_config(self, template):
return
if self.metadata == False:
print("Warning: Config could not be created due to insufficent metadata.")
return
if not os.path.exists(configpath):
os.mkdir(configpath)
if not os.path.exists(configpath + "/" + self.name):
Expand Down
8 changes: 7 additions & 1 deletion helpers/generalhelper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#simple misc functions thaat aim to replace
import asyncio
import aiohttp
import logging
from typing import Union

def dict_keys(dictioary: dict) -> tuple:
"""Returns a tuple of all the dictionary keys."""
Expand Down Expand Up @@ -70,10 +72,14 @@ def string_bool(str_bool : str) -> bool:
return True
return False

def deprecated(func):
"""Decorator for deprecation warning"""
raise DeprecationWarning("Function is deprecated!")

class UpdateQueryBuilder():
"""Makes it simple to work with long update queries."""
def __init__(self, target_db : str):
"""Prepares that builder and sets tthe db."""
"""Prepares that builder and sets the db."""
self.TARGET_DB = target_db
self.where_conditions = []
self.where_params = []
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from constants import ASCII_ART, Colours
from conn.mysql import create_connection
from os import path
from api.main import api
#from api.main import app as api
from tools.main import tools
import os
import importlib
Expand Down Expand Up @@ -51,7 +51,7 @@ def config_routes(app: web.Application) -> None:
app.router.add_post("/database/suggestGJStars20.php", rate_level_handler)
app.router.add_post("/database/requestUserAccess.php", mod_check_handler)
app.router.add_post("/database/getGJDailyLevel.php", get_daily_handler)
app.add_subapp("/api/", api)
#app.add_subapp("/api/", api)
app.add_subapp("/tools/", tools)

def welcome_sequence(no_ascii : bool = False):
Expand Down

0 comments on commit e1db573

Please sign in to comment.