Initial commit

This commit is contained in:
Profitroll 2023-05-02 15:46:15 +02:00
parent 553d982224
commit 86de0dc6aa
8 changed files with 134 additions and 0 deletions

7
.gitignore vendored
View File

@ -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

20
.renovaterc Normal file
View File

@ -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
}
]
}

18
config_example.json Normal file
View File

@ -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"
}
}

41
main.py Normal file
View File

@ -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()

5
modules/client.py Normal file
View File

@ -0,0 +1,5 @@
from discord import Intents, Bot
intents = Intents().all()
intents.members = True
client = Bot(intents=intents)

3
modules/scheduled.py Normal file
View File

@ -0,0 +1,3 @@
from apscheduler.schedulers.asyncio import AsyncIOScheduler
scheduler = AsyncIOScheduler()

35
modules/utils.py Normal file
View File

@ -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

5
requirements.txt Normal file
View File

@ -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