Compare commits

...

3 Commits

Author SHA1 Message Date
e15664e39a basic templating 2025-01-21 00:27:54 +00:00
b3974987a1 update nodejs 2025-01-16 22:46:03 +00:00
e98c36b270 remove python 2025-01-15 21:19:31 +00:00
18 changed files with 155 additions and 181 deletions

10
.gitignore vendored
View File

@ -1,7 +1,5 @@
__pycache__
*.pyc
venv/
.env
*.log
*.log.*
.vscode/
.vscode/
node_modules/
package-lock.json
config.json

View File

@ -1,25 +0,0 @@
import logging
from discord import Intents
from discord.ext import commands
log = logging.getLogger(__name__)
class DiscordBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix="@",
intents=Intents.all()
)
async def on_ready(self):
await self.wait_until_ready()
await self.tree.sync()
log.info("Bot is synced and ready")
async def load_cogs(self, cog_path: str):
log.info("Loading cogs")
for path in cog_path.iterdir():
if path.suffix == ".py":
await self.load_extension(f"cogs.{path.stem}")

View File

@ -1,51 +0,0 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(levelname)s %(message)s"
},
"detail": {
"format": "[%(asctime)s] [%(levelname)s] [%(name)s]: %(message)s"
},
"complex": {
"format": "[%(levelname)s|%(module)s|L%(lineno)d] %(asctime)s %(message)s",
"datefmt": "%Y-%m-%dT%H:%M:%S%z"
}
},
"handlers": {
"stdout": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "complex",
"filename": "logs/pyrss.log",
"maxBytes": 1048576,
"backupCount": 3
},
"queue_handler": {
"class": "logging.handlers.QueueHandler",
"handlers": [
"stdout",
"file"
],
"respect_handler_level": true
}
},
"loggers": {
"root": {
"level": "DEBUG",
"handlers": [
"queue_handler"
]
},
"discord": {
"level": "INFO"
}
}
}

53
main.py
View File

@ -1,53 +0,0 @@
import json
import atexit
import asyncio
import logging
import logging.config
from os import getenv
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(override=True)
from bot.bot import DiscordBot
from web.app import create_app
BASE_DIR = Path(__file__).parent
async def start_web():
app = create_app()
await app.run_task(host="0.0.0.0", port=5000)
async def start_bot(token: str):
async with DiscordBot() as bot:
await bot.load_cogs(BASE_DIR / "bot" / "cogs")
await bot.start(token, reconnect=True)
def setup_logging():
# load config from file
log_config_path = BASE_DIR / "logs" / "config.json"
if not log_config_path.exists():
raise FileNotFoundError("Logging config not found")
with open(log_config_path, "r") as file:
logging_config = json.load(file)
logging.config.dictConfig(logging_config)
# create queue handler for non-blocking logs
queue_handler = logging.getHandlerByName("queue_handler")
if queue_handler is not None:
queue_handler.listener.start()
atexit.register(queue_handler.listener.stop)
async def main():
bot_token = getenv("BOT_TOKEN")
if not bot_token:
raise ValueError("'BOT_TOKEN' is missing")
setup_logging()
await asyncio.gather(start_web(), start_bot(bot_token))
if __name__ == "__main__":
asyncio.run(main())

View File

@ -1,27 +0,0 @@
aiofiles==24.1.0
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiosignal==1.3.2
attrs==24.3.0
blinker==1.9.0
click==8.1.8
discord.py==2.4.0
Flask==3.1.0
frozenlist==1.5.0
h11==0.14.0
h2==4.1.0
hpack==4.0.0
Hypercorn==0.17.3
hyperframe==6.0.1
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.5
MarkupSafe==3.0.2
multidict==6.1.0
priority==2.0.0
propcache==0.2.1
python-dotenv==1.0.1
Quart==0.20.0
Werkzeug==3.1.3
wsproto==1.2.0
yarl==1.18.3

24
src/bot.js Normal file
View File

@ -0,0 +1,24 @@
const discord = require("discord.js");
const fileSystem = require("fs");
// const { GatewayIntentBits } = require("discord.js");
const client = new discord.Client({
intents: []
});
const config = require("./config/config.json");
client.config = config;
fileSystem.readdir("./events/", (error, files) => {
if (error) { return console.error(error); }
files.forEach(file => {
const event = require (`./events/${file}`);
const eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.login(config.token);
exports.client = client;

18
src/events/ready.js Normal file
View File

@ -0,0 +1,18 @@
const chalk = require("chalk");
const config = require("../config/config.json")
require("../bot");
module.exports = client => {
// console.clear();
console.log(chalk.bold.green("Launched Successfully...\n"));
console.log(chalk.magenta("Version:"), chalk.cyan("-"));
console.log(chalk.magenta("Made by"), chalk.cyan("Corbz"));
console.log(chalk.magenta("Prefix:"), chalk.cyan(`${config.prefix}\n`));
if (client.user) {
console.log(chalk.green(chalk.bold(client.user.username), "is online!"));
}
console.log(chalk.green("website:", chalk.underline(`http://localhost:${config.port}`)));
};

48
src/index.js Normal file
View File

@ -0,0 +1,48 @@
const discord = require("./bot");
const express = require("express");
const engine = require("ejs-blocks");
const session = require("express-session");
const flash = require("connect-flash");
const fileUpload = require("express-fileupload");
const config = require("./config/config.json");
const app = express();
const http = require("http").Server(app);
const io = require("socket.io")(http);
port = config.port;
app.use(express.static("./public"));
app.use(express.static("./themes"));
app.engine("ejs", engine);
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true, limit: "5mb" }));
app.use(fileUpload());
app.use(
session({
secret: "test",
resave: true,
saveUninitialized: true
})
)
app.use(flash());
app.use((req, res, next) => {
res.locals.success = req.flash("success"),
res.locals.error = req.flash("error");
next();
});
app.use("/", require("./routes/home.js"));
http.listen(port);
// io.sockets.on("connection", sockets => {
// });
app.use((req, res) => {
res.status(404).render("error_pages/404");
});

33
src/package.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "pyrss-ng",
"version": "0.0.0",
"description": "",
"repository": {
"type": "git",
"url": "https://gitea.cor.bz/corbz/pyrss-ng.git"
},
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
"dependencies": {
"connect-flash": "^0.1.1",
"discord.js": "^14.17.3",
"ejs": "^3.1.10",
"ejs-blocks": "^0.1.4",
"express": "^4.21.2",
"express-fileupload": "^1.5.1",
"express-session": "^1.18.1",
"lolcatjs": "^2.4.3",
"socket.io": "^4.8.1"
},
"devDependencies": {
"eslint": "^9.18.0",
"nodemon": "^3.1.9"
}
}

14
src/routes/home.js Normal file
View File

@ -0,0 +1,14 @@
const express = require("express");
const router = express.Router();
router.get("/", (request, response) => {
response.redirect("/home");
});
router.get("/home", (request, response) => {
response.render("home/home", {
title: "pyrss-ng · home",
});
});
module.exports = router;

2
src/views/home/home.ejs Normal file
View File

@ -0,0 +1,2 @@
<%- layout("../layout") %>
hello world

12
src/views/layout.ejs Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf=8">
<title><%- title %></title>
</head>
<body>
start
<%- body %>
end
</body>
</html>

View File

@ -1,12 +0,0 @@
import logging
from quart import Quart
from .routes.dashboard import dashboard
log = logging.getLogger(__name__)
def create_app():
log.info("Creating web app and registering blueprints")
app = Quart(__name__)
app.register_blueprint(dashboard, url_prefix="/dashboard")
return app

0
web/index.css Normal file
View File

0
web/index.html Normal file
View File

View File

@ -1,7 +0,0 @@
from quart import Blueprint
dashboard = Blueprint("dashboard", __name__)
@dashboard.route("/")
async def home():
return "Dashboard page"