Merge pull request #48 from SowinskiBraeden/refactor/use-webhooks
Refactor/use webhooks from #25 & #38
This commit is contained in:
10 files changed
+165
-66
No files matched your search
+1
-3
@@ -4,12 +4,10 @@ node_modules/*
|
|||||||
# Testing/dev related
|
# Testing/dev related
|
||||||
*_test.js
|
*_test.js
|
||||||
dev-*.js
|
dev-*.js
|
||||||
|
commands/debug.js
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs/*
|
logs/*
|
||||||
|
|
||||||
# env
|
# env
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# Admin Script backups
|
|
||||||
admin/backup/*
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: "debug",
|
|
||||||
debug: true,
|
|
||||||
global: false,
|
|
||||||
description: "debugging...",
|
|
||||||
usage: "",
|
|
||||||
permissions: {
|
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
||||||
member: [],
|
|
||||||
},
|
|
||||||
options: [],
|
|
||||||
SlashCommand: {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {require("../structures/QuarksBot")} client
|
|
||||||
* @param {import("discord.js").Message} message
|
|
||||||
* @param {string[]} args
|
|
||||||
* @param {*} param3
|
|
||||||
*/
|
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
|
||||||
if (!client.config.Admins.includes(interaction.member.user.id)) return interaction.send({ content: 'Only developers can access this command.', flags: (1 << 6) })
|
|
||||||
|
|
||||||
return interaction.send({ content: `Hello ${interaction.member.user.id}, you are my creator!!` })
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Interactions: {}
|
|
||||||
}
|
|
||||||
+2
-1
File diff suppressed because one or more lines are too long.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "13.3.12",
|
"version": "13.3.21",
|
||||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
|
|||||||
+25
-8
@@ -11,6 +11,7 @@ const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandl
|
|||||||
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
||||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
||||||
const { decrypt } = require('../util/Cryptic');
|
const { decrypt } = require('../util/Cryptic');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
// Data structures imports
|
// Data structures imports
|
||||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||||
@@ -66,12 +67,15 @@ class DayzRBot extends Client {
|
|||||||
|
|
||||||
this.db;
|
this.db;
|
||||||
this.dbo;
|
this.dbo;
|
||||||
|
|
||||||
this.databaseConnected = false;
|
this.databaseConnected = false;
|
||||||
this.arInterval = arInterval;
|
this.arInterval = arInterval;
|
||||||
this.arIntervalIds = new Map();
|
this.arIntervalIds = new Map();
|
||||||
this.playerSessions = new Map();
|
this.playerSessions = new Map();
|
||||||
this.logHistory = new Map();
|
this.logHistory = new Map();
|
||||||
this.alarmPingQueue = new Map();
|
this.alarmPingQueue = new Map();
|
||||||
|
this.playerListMsgIds = new Map();
|
||||||
|
|
||||||
this.initialize();
|
this.initialize();
|
||||||
this.LoadCommandsAndInteractionHandlers();
|
this.LoadCommandsAndInteractionHandlers();
|
||||||
this.LoadEvents();
|
this.LoadEvents();
|
||||||
@@ -99,15 +103,15 @@ class DayzRBot extends Client {
|
|||||||
// Free unused armbands for related commands
|
// Free unused armbands for related commands
|
||||||
if (['armbands', 'claim', 'factions'].includes(command)) {
|
if (['armbands', 'claim', 'factions'].includes(command)) {
|
||||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||||
const guild = client.guilds.cache.get(GuildDB.serverID);
|
const guild = this.guilds.cache.get(GuildDB.serverID);
|
||||||
const role = guild.roles.cache.find(role => role.id == factionID);
|
const role = guild.roles.cache.find(role => role.id == factionID);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
let query = {
|
let query = {
|
||||||
$pull: { 'server.usedArmbands': data.armband },
|
$pull: { 'server.usedArmbands': data.armband },
|
||||||
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
||||||
};
|
};
|
||||||
await client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
this.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return this.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,17 +217,25 @@ class DayzRBot extends Client {
|
|||||||
const maxEmbed = 10;
|
const maxEmbed = 10;
|
||||||
|
|
||||||
this.alarmPingQueue.forEach(queue => {
|
this.alarmPingQueue.forEach(queue => {
|
||||||
queue.forEach((data, channel_id) => {
|
queue.forEach(async (data, channel_id) => {
|
||||||
const channel = this.GetChannel(channel_id);
|
const channel = this.GetChannel(channel_id);
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
data.forEach((embeds, role) => {
|
|
||||||
|
const NAME = "DayZ.R Zone Alert";
|
||||||
|
const webhook = await GetWebhook(this, NAME, channel_id);
|
||||||
|
|
||||||
|
data.forEach(async (embeds, role) => {
|
||||||
let embedArrays = [];
|
let embedArrays = [];
|
||||||
while (embeds.length > 0);
|
while (embeds.length > 0);
|
||||||
embedArrays.push(embeds.splice(0, maxEmbed));
|
embedArrays.push(embeds.splice(0, maxEmbed));
|
||||||
|
|
||||||
for (let i = 0; i < embedArrays.length; i++) {
|
for (let i = 0; i < embedArrays.length; i++) {
|
||||||
if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
let content = { embeds: embedArrays[i] };
|
||||||
else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
if (role != '-no-role-ping-') content.content = `<@&${role}>`;
|
||||||
|
WebhookSend(this, webhook, content);
|
||||||
|
|
||||||
|
// if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
||||||
|
// else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -385,7 +397,9 @@ class DayzRBot extends Client {
|
|||||||
this.databaseConnected = true;
|
this.databaseConnected = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
databaselogs.attempts++;
|
databaselogs.attempts++;
|
||||||
let db = (mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]).endsWith("/") ? mongoURI.slice(0, -1) : mongoURI;
|
databaselogs.connected = false;
|
||||||
|
let db = mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1];
|
||||||
|
db = db.includes("/") ? db.split("/")[0] : db;
|
||||||
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
@@ -400,6 +414,7 @@ class DayzRBot extends Client {
|
|||||||
// Wait for MongoDB to connect
|
// Wait for MongoDB to connect
|
||||||
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||||
|
|
||||||
|
if (!this.databaseConnected) return;
|
||||||
let guilds = await this.dbo.collection("guilds").find({}).toArray();
|
let guilds = await this.dbo.collection("guilds").find({}).toArray();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -424,6 +439,8 @@ class DayzRBot extends Client {
|
|||||||
}
|
}
|
||||||
this.logHistory.set(guilds[i].Nitrado.ServerID, guilds[i].server.lastLog); // Using Nitrado Server ID over guild ID in case of future support for multiple nitrado servers in a single guild
|
this.logHistory.set(guilds[i].Nitrado.ServerID, guilds[i].server.lastLog); // Using Nitrado Server ID over guild ID in case of future support for multiple nitrado servers in a single guild
|
||||||
this.playerSessions.set(guilds[i].Nitrado.ServerID, new Map()); // Same reason here as named above.
|
this.playerSessions.set(guilds[i].Nitrado.ServerID, new Map()); // Same reason here as named above.
|
||||||
|
this.alarmPingQueue.set(guilds[i].serverID, new Map()); // Initialize alarm queue to be empty
|
||||||
|
this.playerListMsgIds.set(guilds[i].serverID, ""); // Initialize player list message ids
|
||||||
this.log(`[${guilds[i].server.serverID}] Initialized existing Nitrado`);
|
this.log(`[${guilds[i].server.serverID}] Initialized existing Nitrado`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { nearest } = require('../database/destinations');
|
const { nearest } = require('../database/destinations');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
SendConnectionLogs: async (client, guild, data) => {
|
SendConnectionLogs: async (client, guild, data) => {
|
||||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||||
@@ -14,6 +16,9 @@ module.exports = {
|
|||||||
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
||||||
.setDescription(`**${data.connected ? 'Connect' : 'Disconnect'} Event - <t:${unixTime}>\n${data.player} ${data.connected ? 'Connected' : 'Disconnected'}**`);
|
.setDescription(`**${data.connected ? 'Connect' : 'Disconnect'} Event - <t:${unixTime}>\n${data.player} ${data.connected ? 'Connected' : 'Disconnected'}**`);
|
||||||
|
|
||||||
|
const NAME = "DayZ.R Admin Logs";
|
||||||
|
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||||
|
|
||||||
if (!data.connected) {
|
if (!data.connected) {
|
||||||
if (data.lastConnectionDate != null) {
|
if (data.lastConnectionDate != null) {
|
||||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
||||||
@@ -22,17 +27,20 @@ module.exports = {
|
|||||||
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
// if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
||||||
|
await WebhookSend(client, webhook, {embeds: [connectionLog]});
|
||||||
},
|
},
|
||||||
|
|
||||||
DetectCombatLog: async (client, guild, data) => {
|
DetectCombatLog: async (client, guild, data) => {
|
||||||
if (!client.exists(data.lastDamageDate)) return;
|
if (!client.exists(data.lastDamageDate)) return;
|
||||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||||
|
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||||
|
if (!channel) return; // Ensure channel exists
|
||||||
|
|
||||||
const newDt = await client.getDateEST(data.time);
|
const newDt = await client.getDateEST(data.time);
|
||||||
const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
||||||
|
|
||||||
// If diff is greater than 5 minutes, not a combat log
|
// If diff is greater than configured time in minutes, not a combat log
|
||||||
// or if death after last combat
|
// or if death after last combat
|
||||||
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
||||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||||
@@ -42,9 +50,6 @@ module.exports = {
|
|||||||
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
||||||
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
||||||
|
|
||||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||||
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
||||||
|
|
||||||
@@ -52,8 +57,12 @@ module.exports = {
|
|||||||
.setColor(client.config.Colors.Red)
|
.setColor(client.config.Colors.Red)
|
||||||
.setDescription(`**NOTICE:**\n**${data.player}** has combat logged at <t:${unixTime}> when fighting **${data.lastHitBy}\nLocation [${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**\n${destination}`);
|
.setDescription(`**NOTICE:**\n**${data.player}** has combat logged at <t:${unixTime}> when fighting **${data.lastHitBy}\nLocation [${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**\n${destination}`);
|
||||||
|
|
||||||
if (client.exists(guild.adminRole)) channel.send({ content: `<@&${guild.adminRole}>` });
|
const NAME = "DayZ.R Admin Logs";
|
||||||
|
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||||
|
|
||||||
return channel.send({ embeds: [combatLog] });
|
let content = { embeds: [combatLog] };
|
||||||
|
if (client.exists(guild.adminRole)) content.content = `<@&${guild.adminRole}>`;
|
||||||
|
WebhookSend(client, webhook, content);
|
||||||
|
// return channel.send({ embeds: [combatLog] });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+30
-6
@@ -2,6 +2,7 @@ const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { nearest } = require('../database/destinations');
|
const { nearest } = require('../database/destinations');
|
||||||
const { GetGuild } = require('../database/guild');
|
const { GetGuild } = require('../database/guild');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
// Private functions (only called locally)
|
// Private functions (only called locally)
|
||||||
|
|
||||||
@@ -20,6 +21,10 @@ const ExpireEvent = async(client, guild, e) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const HandlePlayerTrackEvent = async (client, guild, e) => {
|
const HandlePlayerTrackEvent = async (client, guild, e) => {
|
||||||
|
if (!client.exists(e.channel)) return ExpireEvent(client, guild, e); // Expire event since it has invalid channel.
|
||||||
|
const channel = client.GetChannel(e.channel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
let player = await client.dbo.collection("players").findOne({"gamertag": e.gamertag});
|
let player = await client.dbo.collection("players").findOne({"gamertag": e.gamertag});
|
||||||
|
|
||||||
let newDt = await client.getDateEST(player.time);
|
let newDt = await client.getDateEST(player.time);
|
||||||
@@ -31,10 +36,15 @@ const HandlePlayerTrackEvent = async (client, guild, e) => {
|
|||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**${e.name} Event**\n${e.gamertag} was located at **[${player.pos[0]}, ${player.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${player.pos[0]};${player.pos[1]})** at <t:${unixTime}>\n${destination}`);
|
.setDescription(`**${e.name} Event**\n${e.gamertag} was located at **[${player.pos[0]}, ${player.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${player.pos[0]};${player.pos[1]})** at <t:${unixTime}>\n${destination}`);
|
||||||
|
|
||||||
if (!client.exists(e.channel)) return ExpireEvent(client, guild, e); // Expire event since it has invalid channel.
|
const NAME = "DayZ.R Player Tracker";
|
||||||
const channel = client.GetChannel(e.channel);
|
const webhook = await GetWebhook(client, NAME, e.channel);
|
||||||
if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] });
|
|
||||||
else channel.send({ embeds: [trackEvent] });
|
let content = { embeds: [trackEvent] };
|
||||||
|
if (client.exists(guild.adminRole)) content.content = `<@&${e.role}>`;
|
||||||
|
WebhookSend(client, webhook, content);
|
||||||
|
|
||||||
|
// if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] });
|
||||||
|
// else channel.send({ embeds: [trackEvent] });
|
||||||
|
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let diff = ((now - e.creationDate) / 1000) / 60;
|
let diff = ((now - e.creationDate) / 1000) / 60;
|
||||||
@@ -157,6 +167,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (distance < alarm.radius) {
|
if (distance < alarm.radius) {
|
||||||
const channel = client.GetChannel(alarm.channel);
|
const channel = client.GetChannel(alarm.channel);
|
||||||
|
if (!channel) continue;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
@@ -166,7 +177,13 @@ module.exports = {
|
|||||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.killer}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for killing **${data.victim}**.__`)
|
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.killer}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for killing **${data.victim}**.__`)
|
||||||
.addFields({ name: '**Location**', value: `**[${data.killerPOS[0]}, ${data.killerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.killerPOS[0]};${data.killerPOS[1]})**`, inline: false })
|
.addFields({ name: '**Location**', value: `**[${data.killerPOS[0]}, ${data.killerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.killerPOS[0]};${data.killerPOS[1]})**`, inline: false })
|
||||||
|
|
||||||
channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
const NAME = "DayZ.R Zone Alert";
|
||||||
|
const webhook = await GetWebhook(client, NAME, alarm.channel);
|
||||||
|
|
||||||
|
let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] };
|
||||||
|
WebhookSend(client, webhook, content);
|
||||||
|
|
||||||
|
// channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||||
|
|
||||||
BanPlayer(client, data.killer);
|
BanPlayer(client, data.killer);
|
||||||
break;
|
break;
|
||||||
@@ -198,6 +215,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (distance < alarm.radius) {
|
if (distance < alarm.radius) {
|
||||||
const channel = client.GetChannel(alarm.channel);
|
const channel = client.GetChannel(alarm.channel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(info.time);
|
let newDt = await client.getDateEST(info.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
@@ -207,7 +225,13 @@ module.exports = {
|
|||||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${info.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for **placing a fireplace**.__`)
|
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${info.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for **placing a fireplace**.__`)
|
||||||
.addFields({ name: '**Location**', value: `**[${info.playerPOS[0]}, ${info.playerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.playerPOS[0]};${info.playerPOS[1]})**`, inline: false })
|
.addFields({ name: '**Location**', value: `**[${info.playerPOS[0]}, ${info.playerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.playerPOS[0]};${info.playerPOS[1]})**`, inline: false })
|
||||||
|
|
||||||
channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
const NAME = "DayZ.R Zone Alert";
|
||||||
|
const webhook = await GetWebhook(client, NAME, alarm.channel);
|
||||||
|
|
||||||
|
let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] };
|
||||||
|
WebhookSend(client, webhook, content);
|
||||||
|
|
||||||
|
// channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||||
|
|
||||||
BanPlayer(client, info.player);
|
BanPlayer(client, info.player);
|
||||||
break;
|
break;
|
||||||
|
|||||||
+23
-4
@@ -5,6 +5,7 @@ const { nearest } = require('../database/destinations');
|
|||||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||||
const { calculateNewCombatRating } = require('./CombatRatingHandler');
|
const { calculateNewCombatRating } = require('./CombatRatingHandler');
|
||||||
const { weapons, weaponClassOf } = require('../database/weapons');
|
const { weapons, weaponClassOf } = require('../database/weapons');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
const Templates = {
|
const Templates = {
|
||||||
Killed: 1,
|
Killed: 1,
|
||||||
@@ -80,6 +81,7 @@ module.exports = {
|
|||||||
|
|
||||||
HandleKillfeed: async (NitradoServerID, client, guild, line) => {
|
HandleKillfeed: async (NitradoServerID, client, guild, line) => {
|
||||||
|
|
||||||
|
const NAME = "DayZ.R Killfeed";
|
||||||
const channel = client.GetChannel(guild.killfeedChannel);
|
const channel = client.GetChannel(guild.killfeedChannel);
|
||||||
|
|
||||||
const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
||||||
@@ -133,6 +135,11 @@ module.exports = {
|
|||||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, NitradoServerID);
|
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, NitradoServerID);
|
||||||
|
victimStat.deaths++;
|
||||||
|
victimStat.deathStreak++;
|
||||||
|
victimStat.worstDeathStreak = victimStat.deathStreak > victimStat.worstDeathStreak ? victimStat.deathStreak : victimStat.worstDeathStreak;
|
||||||
|
victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0
|
||||||
|
victimStat.killStreak = 0;
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
|
|
||||||
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
||||||
@@ -144,9 +151,14 @@ module.exports = {
|
|||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Death Event** - <t:${unixTime}>\n**${info.victim}** ${killMessage} a **${cod}.**${coord}`);
|
.setDescription(`**Death Event** - <t:${unixTime}>\n**${info.victim}** ${killMessage} a **${cod}.**${coord}`);
|
||||||
|
|
||||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
|
||||||
await UpdatePlayer(client, victimStat);
|
await UpdatePlayer(client, victimStat);
|
||||||
return
|
|
||||||
|
if (!channel) return;
|
||||||
|
const webhook = await GetWebhook(this, NAME, guild.killfeedChannel);
|
||||||
|
WebhookSend(client, webhook, { embeds: [killEvent]});
|
||||||
|
|
||||||
|
// if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KillInAlarm(client, guild.serverID, info); // check if kill happened in a no kill zone
|
KillInAlarm(client, guild.serverID, info); // check if kill happened in a no kill zone
|
||||||
@@ -263,8 +275,15 @@ module.exports = {
|
|||||||
killEvent.setThumbnail(weapons[weaponClass][weapon])
|
killEvent.setThumbnail(weapons[weaponClass][weapon])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
if (!channel) return;
|
||||||
if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
|
||||||
|
const webhook = await GetWebhook(this, NAME, guild.killfeedChannel);
|
||||||
|
|
||||||
|
WebhookSend(client, webhook, { embeds: [killEvent] });
|
||||||
|
if (client.exists(receivedBounty) && client.exists(channel)) WebhookSend(client, webhook, { content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||||
|
|
||||||
|
// if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||||
|
// if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-6
@@ -5,8 +5,7 @@ const { getDefaultPlayer } = require('../database/player');
|
|||||||
const { FetchServerSettings } = require('../util/NitradoAPI');
|
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||||
const { UpdatePlayer, insertPVPstats, createWeaponStats } = require('../database/player')
|
const { UpdatePlayer, insertPVPstats, createWeaponStats } = require('../database/player')
|
||||||
const { Missions } = require('../database/destinations');
|
const { Missions } = require('../database/destinations');
|
||||||
|
const { GetWebhook, WebhookSend, WebhookMessageEdit } = require("../util/WebhookHandler");
|
||||||
let lastSendMessage;
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
@@ -208,6 +207,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!client.exists(guild.activePlayersChannel)) return;
|
if (!client.exists(guild.activePlayersChannel)) return;
|
||||||
const channel = client.GetChannel(guild.activePlayersChannel);
|
const channel = client.GetChannel(guild.activePlayersChannel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
const data = await FetchServerSettings(nitrado_cred, client, 'HandleActivePlayersList'); // Fetch server status
|
const data = await FetchServerSettings(nitrado_cred, client, 'HandleActivePlayersList'); // Fetch server status
|
||||||
const e = data && data !== 1; // Check if data exists
|
const e = data && data !== 1; // Check if data exists
|
||||||
@@ -251,10 +251,15 @@ module.exports = {
|
|||||||
.setTitle(`Players Online:`)
|
.setTitle(`Players Online:`)
|
||||||
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
||||||
|
|
||||||
if (lastSendMessage) lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous message before reprinting
|
const NAME = "DayZ.R Admin Logs";
|
||||||
|
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||||
|
|
||||||
return channel.send({ embeds: [serverEmbed, activePlayersEmbed] }).then(sentMessage =>
|
let id = client.playerListMsgIds.get(guild.serverID);
|
||||||
lastSendMessage = sentMessage
|
if (id == "") {
|
||||||
);
|
id = await WebhookSend(client, webhook, { embeds: [serverEmbed, activePlayersEmbed] }).id;
|
||||||
|
client.playerListMsgIds.set(guild.serverID, id);
|
||||||
|
} else {
|
||||||
|
WebhookMessageEdit(client, webhook, id, { embeds: [serverEmbed, activePlayersEmbed] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const { Routes } = require('discord.js');
|
||||||
|
|
||||||
|
const createWebhook = async (client, channel_id, name, avatar) => {
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
return await rest.post(Routes.channelWebhooks(channel_id), {
|
||||||
|
body: {
|
||||||
|
name: name,
|
||||||
|
avatar: avatar
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
GetWebhook: async (client, webhookName, channel_id) => {
|
||||||
|
// Get all webhooks from configured channel
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
const webhooks = await rest.get(Routes.channelWebhooks(channel_id));
|
||||||
|
|
||||||
|
let webhook = null;
|
||||||
|
if (webhooks.length == 0) {
|
||||||
|
// If no webhook exists, create new webhook with given name for this channel
|
||||||
|
webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData);
|
||||||
|
} else {
|
||||||
|
// Check existing webhooks for one with given name
|
||||||
|
let exists = false;
|
||||||
|
for (let i = 0; i < webhooks.length; i++) {
|
||||||
|
if (webhooks[i].name == webhookName) {
|
||||||
|
webhook = webhooks[i];
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return webhook;
|
||||||
|
},
|
||||||
|
|
||||||
|
WebhookSend: async (client, webhook, content) => {
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
return await rest.post(Routes.webhook(webhook.id, webhook.token), {
|
||||||
|
body: content,
|
||||||
|
query: makeURLSearchParams({ wait: true })
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
WebhookMessageEdit: async (client, webhook, message_id, content) => {
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
return rest.patch(Routes.webhookMessage(webhook.id, webhook.token, message_id), {
|
||||||
|
body: content
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user