Integrate express server
This commit is contained in:
57
app.js
57
app.js
@@ -1,51 +1,18 @@
|
|||||||
import { Logger } from './wwwroot/core/logging/logger.js';
|
|
||||||
import JsonManager from './wwwroot/core/utils/jsonManager.js';
|
|
||||||
import { data } from "./wwwroot/core/appData.js";
|
import { data } from "./wwwroot/core/appData.js";
|
||||||
|
import express from "express";
|
||||||
|
|
||||||
try{
|
const app = express();
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
data.instagramTokenManager.startWatching();
|
app.get("/oauth/", async (req, res) => {
|
||||||
|
const code = req.query.code;
|
||||||
|
console.log("Received OAuth code:", code);
|
||||||
|
await data.instagramTokenManager.generate(code);
|
||||||
|
|
||||||
//data.tiktokTokenManager.startWatching();
|
});
|
||||||
|
|
||||||
data.instagramPoller.on("newPost", async ({permalink, userId}) => {
|
app.get("/api/health", (req, res) => {
|
||||||
const modified = JsonManager.upsertPost("./posts.json", {permalink, userId})
|
res.json({ status: "ok" });
|
||||||
if(!modified) return;
|
});
|
||||||
|
|
||||||
const message = `Behold ! Some new awesome content has been posted ! \n\n${permalink}`;
|
app.listen(5004, () => console.log("Node backend listening on port 5004"));
|
||||||
await data.sender.send(data.socialChannelID, message)
|
|
||||||
});
|
|
||||||
|
|
||||||
data.client.once('clientReady', async () => {
|
|
||||||
await data.sender.send(data.updateChannelID, "I'm now online ! ✅")
|
|
||||||
console.log(`✅ Logged in as ${data.client.user.tag}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
data.client.on('messageCreate', (message) => {
|
|
||||||
const isGuildOwner = message.guild && message.author.id === message.guild.ownerId;
|
|
||||||
if (message.content === '/login' && isGuildOwner) {
|
|
||||||
message.reply(data.instagramTokenManager.getOauthUrl());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
data.client.on('guildMemberAdd', member => {
|
|
||||||
const avatar = member.user.avatarURL();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('SIGINT', async () => {
|
|
||||||
try {
|
|
||||||
await data.sender.send(data.updateChannelID, "I'm shutting down, now. Bye! 👋")
|
|
||||||
} catch (error) {
|
|
||||||
await Logger.error("Error while shutting down", error);
|
|
||||||
} finally {
|
|
||||||
await data.client.destroy();
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await data.client.login(process.env.DISCORD_TOKEN);
|
|
||||||
data.instagramPoller.start(600000);
|
|
||||||
|
|
||||||
} catch(err){
|
|
||||||
await Logger.error("Unexpected error", err)
|
|
||||||
}
|
|
||||||
|
|||||||
51
bot.js
Normal file
51
bot.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import {data} from "./wwwroot/core/appData.js";
|
||||||
|
import JsonManager from "./wwwroot/core/utils/jsonManager.js";
|
||||||
|
import {Logger} from "./wwwroot/core/logging/logger.js";
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
data.instagramTokenManager.startWatching();
|
||||||
|
|
||||||
|
//data.tiktokTokenManager.startWatching();
|
||||||
|
|
||||||
|
data.instagramPoller.on("newPost", async ({permalink, userId}) => {
|
||||||
|
const modified = JsonManager.upsertPost("./posts.json", {permalink, userId})
|
||||||
|
if(!modified) return;
|
||||||
|
|
||||||
|
const message = `Behold ! Some new awesome content has been posted ! \n\n${permalink}`;
|
||||||
|
await data.sender.send(data.socialChannelID, message)
|
||||||
|
});
|
||||||
|
|
||||||
|
data.client.once('clientReady', async () => {
|
||||||
|
await data.sender.send(data.updateChannelID, "I'm now online ! ✅")
|
||||||
|
console.log(`✅ Logged in as ${data.client.user.tag}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
data.client.on('messageCreate', (message) => {
|
||||||
|
const isGuildOwner = message.guild && message.author.id === message.guild.ownerId;
|
||||||
|
if (message.content === '/login' && isGuildOwner) {
|
||||||
|
message.reply(data.instagramTokenManager.getOauthUrl());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
data.client.on('guildMemberAdd', member => {
|
||||||
|
const avatar = member.user.avatarURL();
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGINT', async () => {
|
||||||
|
try {
|
||||||
|
await data.sender.send(data.updateChannelID, "I'm shutting down, now. Bye! 👋")
|
||||||
|
} catch (error) {
|
||||||
|
await Logger.error("Error while shutting down", error);
|
||||||
|
} finally {
|
||||||
|
await data.client.destroy();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await data.client.login(process.env.DISCORD_TOKEN);
|
||||||
|
data.instagramPoller.start(600000);
|
||||||
|
|
||||||
|
} catch(err){
|
||||||
|
await Logger.error("Unexpected error", err)
|
||||||
|
}
|
||||||
@@ -12,18 +12,18 @@
|
|||||||
"start": "node app.js",
|
"start": "node app.js",
|
||||||
"register": "node commands.js",
|
"register": "node commands.js",
|
||||||
"dev": "nodemon app.js",
|
"dev": "nodemon app.js",
|
||||||
"publish-patch-note" : "node patchnote-publisher.js",
|
"publish-patch-note": "node patchnote-publisher.js",
|
||||||
"name-card-test": "node tests/name-card-test.js",
|
"name-card-test": "node tests/name-card-test.js",
|
||||||
"istg-token-test": "node tests/token-renew.js",
|
"istg-token-test": "node tests/token-renew.js",
|
||||||
"token-watch-test" : "node tests/token-watch.js",
|
"token-watch-test": "node tests/token-watch.js",
|
||||||
"polling-test" : "node tests/polling.js"
|
"polling-test": "node tests/polling.js"
|
||||||
},
|
},
|
||||||
"author": "Naaturel",
|
"author": "Naaturel",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.22.1",
|
"discord.js": "^14.22.1",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.21.2",
|
||||||
"prompt-sync": "^4.2.0",
|
"prompt-sync": "^4.2.0",
|
||||||
"sharp": "^0.34.5"
|
"sharp": "^0.34.5"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user