Initial commit
This commit is contained in:
commit
0dabb7c3c0
7 changed files with 924 additions and 0 deletions
25
src/features/discordBot.js
Normal file
25
src/features/discordBot.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { Client, GatewayIntentBits } from "discord.js";
|
||||
import { config } from "../static/config.js";
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
|
||||
});
|
||||
|
||||
async function initDiscordBot() {
|
||||
await client.login(config.token);
|
||||
console.log("✅ Discord bot connecté !");
|
||||
}
|
||||
|
||||
async function sendDiscordAlert(message) {
|
||||
try {
|
||||
const channel = await client.channels.fetch(config.textChannelId);
|
||||
await channel.send(message);
|
||||
} catch (err) {
|
||||
console.error("❌ Erreur envoi Discord :", err);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
initDiscordBot,
|
||||
sendDiscordAlert
|
||||
}
|
||||
63
src/features/membersChecker.js
Normal file
63
src/features/membersChecker.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import cron from "node-cron";
|
||||
import fetch from "node-fetch";
|
||||
import fs from "fs";
|
||||
import * as cheerio from "cheerio";
|
||||
import { config } from "../static/config.js";
|
||||
import { sendDiscordAlert } from "./discordBot.js"
|
||||
|
||||
const membersJSON = "./src/static/data/members.json";
|
||||
const scheduleTime = "30 9 * * *";
|
||||
const scheduleTimezone = "Europe/Paris";
|
||||
|
||||
async function initMembersChecker() {
|
||||
await checkGuildMembers();
|
||||
cron.schedule(scheduleTime, checkGuildMembers, { timezone: scheduleTimezone });
|
||||
}
|
||||
|
||||
async function getGuildMembers(guildUrl) {
|
||||
const res = await fetch(guildUrl);
|
||||
const html = await res.text();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const members = [];
|
||||
|
||||
$('.box_list_area .adventure_list_table li .guild_name .text a').each((i, el) => {
|
||||
members.push($(el).text().trim());
|
||||
});
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
async function checkGuildMembers() {
|
||||
try {
|
||||
const newMembers = await getGuildMembers(config.guild_url);
|
||||
|
||||
let oldMembers = [];
|
||||
if (fs.existsSync(membersJSON)) {
|
||||
oldMembers = JSON.parse(fs.readFileSync(membersJSON, "utf-8"));
|
||||
}
|
||||
|
||||
const added = newMembers.filter(m => !oldMembers.includes(m));
|
||||
const removed = oldMembers.filter(m => !newMembers.includes(m));
|
||||
|
||||
if (added.length || removed.length) {
|
||||
let message = "⚔️ **Changement dans la liste des membres :**\n";
|
||||
if (added.length) message += `➕ Nouveaux membres : ${added.join(", ")}\n`;
|
||||
if (removed.length) message += `➖ Membres partis : ${removed.join(", ")}`;
|
||||
await sendDiscordAlert(message);
|
||||
}
|
||||
|
||||
fs.mkdirSync("./src/static/data/", { recursive: true });
|
||||
fs.writeFileSync(membersJSON, JSON.stringify(newMembers, null, 2));
|
||||
console.log("✅ Vérification terminée", new Date().toLocaleString("fr-FR", { timeZone: scheduleTimezone }));
|
||||
} catch (err) {
|
||||
console.error("❌ Erreur checkGuildMembers:", err);
|
||||
try {
|
||||
await sendDiscordAlert(`⚠️ Erreur lors du check des membres: \`${err.message}\``);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
initMembersChecker
|
||||
}
|
||||
10
src/static/config.js
Normal file
10
src/static/config.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
const config = {
|
||||
token: "MTQyODI5MDE1Mjk4MzE3MTE2Mw.GFwDOo.-RPnn6meXQL3xAh1S0vCQ9N0H3PeXcxKGSIWAM",
|
||||
botOwner: "139829632764477440",
|
||||
applicationId: "1428290152983171163",
|
||||
guild_url: "https://www.naeu.playblackdesert.com/en-us/Adventure/Guild/GuildProfile?guildName=Abondance®ion=EU",
|
||||
discordGuildId: "1205611509305057410",
|
||||
textChannelId: "1428068401825321094",
|
||||
};
|
||||
|
||||
export { config };
|
||||
80
src/static/data/members.json
Normal file
80
src/static/data/members.json
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
[
|
||||
"AzGd",
|
||||
"Eriatilos",
|
||||
"Enerel",
|
||||
"Sombrerage",
|
||||
"Angelwhite",
|
||||
"Ayline",
|
||||
"Vil",
|
||||
"Midagril",
|
||||
"Sodom",
|
||||
"Kamekho",
|
||||
"Neuroxie",
|
||||
"CrowZy",
|
||||
"Siarys",
|
||||
"Netiks",
|
||||
"Muiiraa",
|
||||
"Brindepaille",
|
||||
"JaxTeller",
|
||||
"Kitsune_Yurei",
|
||||
"BeatCheese",
|
||||
"Labavure",
|
||||
"Ancom",
|
||||
"Calterson",
|
||||
"WarfuzFR",
|
||||
"Warpapou",
|
||||
"Dolypran50",
|
||||
"DocHollydays",
|
||||
"Shaoshin",
|
||||
"RNGabsente",
|
||||
"Akashann",
|
||||
"Neickrish",
|
||||
"HelIheim",
|
||||
"Itadoriz",
|
||||
"Elphro",
|
||||
"Istrya",
|
||||
"Padoll",
|
||||
"Prck",
|
||||
"Jbeybey",
|
||||
"Cyanea",
|
||||
"Dockyo",
|
||||
"Scarza",
|
||||
"Monitora",
|
||||
"FatalityBurning",
|
||||
"TheRealRose",
|
||||
"Picmiss",
|
||||
"WaiseiHochi",
|
||||
"Streameur",
|
||||
"Reeeg",
|
||||
"Tsukuya",
|
||||
"Mains",
|
||||
"Sunyy",
|
||||
"RisingGenji",
|
||||
"Korrigane",
|
||||
"SummerSky",
|
||||
"Bazot",
|
||||
"Anarielle",
|
||||
"Noune",
|
||||
"Bazooteam",
|
||||
"La_Magique",
|
||||
"Hoturu",
|
||||
"Konahriik",
|
||||
"Siamea",
|
||||
"Lesmechants",
|
||||
"EruKihn",
|
||||
"Dorelei",
|
||||
"Henshim",
|
||||
"Nouninette",
|
||||
"Lynode",
|
||||
"Canicasi",
|
||||
"Takasugii",
|
||||
"DeMernardin",
|
||||
"Lanuwa",
|
||||
"ClanUchiwa",
|
||||
"Sollak",
|
||||
"Lorenya_OG",
|
||||
"Sodominette",
|
||||
"Juliard",
|
||||
"Lacroixs",
|
||||
"OptimusDeZion"
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue