diff --git a/.gitignore b/.gitignore index 5d381cc..c10f532 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,10 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +# Project +.vscode +venv +venv_linux +venv_windows + +config.json \ No newline at end of file diff --git a/.renovaterc b/.renovaterc new file mode 100644 index 0000000..c416352 --- /dev/null +++ b/.renovaterc @@ -0,0 +1,20 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ], + "baseBranches": [ + "dev" + ], + "packageRules": [ + { + "matchUpdateTypes": [ + "minor", + "patch", + "pin", + "digest" + ], + "automerge": true + } + ] +} \ No newline at end of file diff --git a/config_example.json b/config_example.json new file mode 100644 index 0000000..69a3c4d --- /dev/null +++ b/config_example.json @@ -0,0 +1,18 @@ +{ + "token": "", + "owner": 0, + "guild": 0, + "admins": [], + "status": "crying clowns", + "database": { + "user": null, + "password": null, + "host": "127.0.0.1", + "port": 27017, + "name": "holo_discord" + }, + "logging": { + "size": 512, + "location": "logs" + } +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..673aff9 --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +import asyncio +import logging + +from discord import Activity, ActivityType + +from modules.scheduled import scheduler +from modules.client import client +from modules.utils import config_get + +logging.basicConfig( + level=logging.INFO, + format="%(name)s.%(funcName)s | %(levelname)s | %(message)s", + datefmt="[%X]", +) + +logger = logging.getLogger(__name__) + +try: + import uvloop # type: ignore + + uvloop.install() +except ImportError: + pass + + +@client.event +async def on_ready(): + + logger.info(f"Logged in as {client.user}") + await client.change_presence(activity=Activity(type=ActivityType.listening, name=await config_get("status"))) + +def main(): + try: + scheduler.start() + client.run(asyncio.run(config_get("token"))) + except KeyboardInterrupt: + scheduler.shutdown() + exit() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/modules/client.py b/modules/client.py new file mode 100644 index 0000000..8b973b7 --- /dev/null +++ b/modules/client.py @@ -0,0 +1,5 @@ +from discord import Intents, Bot + +intents = Intents().all() +intents.members = True +client = Bot(intents=intents) \ No newline at end of file diff --git a/modules/scheduled.py b/modules/scheduled.py new file mode 100644 index 0000000..a5eb79d --- /dev/null +++ b/modules/scheduled.py @@ -0,0 +1,3 @@ +from apscheduler.schedulers.asyncio import AsyncIOScheduler + +scheduler = AsyncIOScheduler() diff --git a/modules/utils.py b/modules/utils.py new file mode 100644 index 0000000..d28a6d2 --- /dev/null +++ b/modules/utils.py @@ -0,0 +1,35 @@ +from typing import Any +import aiofiles +from ujson import loads, dumps + + +async def json_read(path: str) -> Any: + async with aiofiles.open(path, mode="r", encoding="utf-8") as f: + data = await f.read() + return loads(data) + + +async def json_write(data: Any, path: str) -> None: + async with aiofiles.open(path, mode="w", encoding="utf-8") as f: + await f.write(dumps(data, ensure_ascii=False, escape_forward_slashes=False)) + + +async def config_get(key: str, *path: str) -> Any: + this_key = await json_read("config.json") + for dict_key in path: + this_key = this_key[dict_key] + return this_key[key] + + +async def config_set(key: str, value: Any, *path: str) -> None: + this_dict = await json_read("config.json") + string = "this_dict" + for arg in path: + string += f'["{arg}"]' + if type(value) in [str]: + string += f'["{key}"] = "{value}"' + else: + string += f'["{key}"] = {value}' + exec(string) + await json_write(this_dict, "config.json") + return \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c3bf8cf --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +aiofiles==23.1.0 +apscheduler==3.10.1 +py-cord[speed]==2.4.1 +pymongo==4.3.3 +ujson==5.7.0 \ No newline at end of file