Skip to content
Snippets Groups Projects
Commit 5eadbc2d authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

aled

parent b6594eb8
No related branches found
No related tags found
No related merge requests found
......@@ -281,7 +281,7 @@ const { verify } = require('crypto');
// create a new Discord client
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES", "GUILD_MEMBERS"] });
var mcChatWebhook;
var mcChatWebhook, devMcChatWebhook;
client.on("ready", async function () {
console.log('\n' + "SL-Projects Bot".brightCyan);
......@@ -625,15 +625,41 @@ async function createMcChatWebhook() {
console.log("[" + 'INFO'.yellow + "] Le Webhook du serveur MC a été configuré avec succès.");
})
.catch(console.error);
// Dev
client.channels.cache.get(config.get("CANAL_CHAT_MC_DEV")).createWebhook('Chat Serveur Minecraft Dev', {
avatar: 'https://sl-craft.fr/data/images/logo/short-color.png',
})
.then(webhook => {
botSettings.create({
name: "devMcChatWebhookId",
value: webhook.id
});
botSettings.create({
name: "devMcChatWebhookToken",
value: webhook.token
});
devMcChatWebhook = new WebhookClient({ id: devMcChatWebhookId.value, token: devMcChatWebhookToken.value });
console.log("[" + 'INFO'.yellow + "] Le Webhook du serveur MC Dev a été configuré avec succès.");
})
.catch(console.error);
}
function sendMessageFromMcChat(username, message) {
function sendMessageFromMcChat(username, message, serverType) {
if(username == "SL-Craft"){
if(serverType == "dev"){
devMcChatWebhook.send({
content: message,
username: username,
avatarURL: 'https://sl-craft.fr/data/images/logo/favicon-color.png',
});
}else{
mcChatWebhook.send({
content: message,
username: username,
avatarURL: 'https://sl-craft.fr/data/images/logo/favicon-color.png',
});
}
}else{
// On va vérifier que le joueur ne fait pas de @everyone ou de @here
message = message.replace("<@everyone>", "**everyone**");
......@@ -655,12 +681,21 @@ function sendMessageFromMcChat(username, message) {
}
}
if(serverType == "dev"){
devMcChatWebhook.send({
content: message,
username: username,
avatarURL: 'https://live.mc.sl-projects.com/tiles/faces/32x32/' + username + '.png',
});
}else{
mcChatWebhook.send({
content: message,
username: username,
avatarURL: 'https://live.mc.sl-projects.com/tiles/faces/32x32/' + username + '.png',
});
}
}
}
......@@ -688,7 +723,7 @@ app.get('/channels/:id', (req, res) => {
})
app.get('/mc/chat/:detail', (req, res) => {
var detail = JSON.parse(decodeURI(req.params.detail));
sendMessageFromMcChat(detail.username, detail.message);
sendMessageFromMcChat(detail.username, detail.message, req.headers.serverType);
res.send("Envoyé!")
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment