update/configure killfeed to show weapon thumbnail
This commit is contained in:
5 files changed
+115
-32
No files matched your search
+87
-25
@@ -14,6 +14,53 @@ module.exports = {
|
||||
member: ["MANAGE_GUILD"],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "killfeed",
|
||||
descripion: "Configure the killfeed",
|
||||
value: "killfeed",
|
||||
type: CommandOptions.SubCommandGroup,
|
||||
options: [
|
||||
{
|
||||
name: "channel",
|
||||
description: "Configure the killfeed channel",
|
||||
value: "channel",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "channel",
|
||||
description: "The channel to configure",
|
||||
value: "channel",
|
||||
type: CommandOptions.Channel,
|
||||
required: true
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "show_coords",
|
||||
description: "Show the coordinates of the victim in the killfeed channel.",
|
||||
value: "show_coords",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "configuration",
|
||||
description: "True or False",
|
||||
value: false,
|
||||
type: CommandOptions.Boolean,
|
||||
required: true,
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "show_weapon",
|
||||
description: "Show the image of the weapon in the killfeed",
|
||||
value: "show_weapon",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "configuration",
|
||||
description: "True or False",
|
||||
value: false,
|
||||
type: CommandOptions.Boolean,
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "allowed_channels",
|
||||
description: "Set channels you're allowed to use the bot in",
|
||||
@@ -278,18 +325,6 @@ module.exports = {
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "show_killfeed_coords",
|
||||
description: "Show the coordinates of the killer or victim in the killfeed channel.",
|
||||
value: "show_killfeed_coords",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "configuration",
|
||||
description: "True or False",
|
||||
value: false,
|
||||
type: CommandOptions.Boolean,
|
||||
required: true,
|
||||
}]
|
||||
}, {
|
||||
name: "combat-log-timer",
|
||||
description: "Adjust log timeout for combat prevention. (0 disables combat log)",
|
||||
value: "combat-log-timer",
|
||||
@@ -532,19 +567,6 @@ module.exports = {
|
||||
|
||||
return interaction.send({ embeds: [successSetChannelEmbed] });
|
||||
|
||||
case 'show_killfeed_coords':
|
||||
const showKillfeedCoordsConfiguration = args[0].options[0].value ? 1 : 0;
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedCoords": showKillfeedCoordsConfiguration}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
||||
.setDescription(`Successfully configured the killfeed to ${showKillfeedCoordsConfiguration ? 'show' : 'not show'} coordinates.`)
|
||||
.setColor(client.config.Colors.Green);
|
||||
|
||||
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
||||
|
||||
case 'linked_gt_role':
|
||||
const linked_gt_role = args[0].options[0].value;
|
||||
|
||||
@@ -724,6 +746,46 @@ module.exports = {
|
||||
|
||||
return interaction.send({ embeds: [successToggleEMPpurchaseEmbed] });
|
||||
|
||||
case 'killfeed':
|
||||
const killfeed_configuration = args[0].options[0].name;
|
||||
|
||||
if (killfeed_configuration == 'channel') {
|
||||
|
||||
const channel = args[0].options[0].options[0].value;
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID},{$set: {'server.killfeedChannel': channel}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
} else if ('show_coords') {
|
||||
const showKillfeedCoordsConfiguration = args[0].options[0].options[0].value ? 1 : 0;
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedCoords": showKillfeedCoordsConfiguration}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
||||
.setDescription(`Successfully configured the killfeed to ${showKillfeedCoordsConfiguration ? 'show' : 'not show'} coordinates.`)
|
||||
.setColor(client.config.Colors.Green);
|
||||
|
||||
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
||||
|
||||
} else if ('show_weapon') {
|
||||
|
||||
const showKillfeedWeaponConfiguration = args[0].options[0].options[0].value ? 1 : 0;
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedWeapon": showKillfeedWeaponConfiguration}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
||||
.setDescription(`Successfully configured the killfeed to ${showKillfeedWeaponConfiguration ? 'show' : 'not show'} weapon icons.`)
|
||||
.setColor(client.config.Colors.Green);
|
||||
|
||||
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
return client.sendInternalError(interaction, 'There was an error parsing the config command');
|
||||
}
|
||||
|
||||
+4
-2
@@ -18,6 +18,7 @@ module.exports = {
|
||||
serverID: GuildId,
|
||||
autoRestart: guild.server.autoRestart,
|
||||
showKillfeedCoords: guild.server.showKillfeedCoords,
|
||||
showKillfeedWeapon: guild.server.showKillfeedWeapon,
|
||||
purchaseUAV: guild.server.purchaseUAV,
|
||||
purchaseEMP: guild.server.purchaseEMP,
|
||||
allowedChannels: guild.server.allowedChannels,
|
||||
@@ -56,8 +57,9 @@ module.exports = {
|
||||
getDefaultSettings(GuildId) {
|
||||
return {
|
||||
serverID: GuildId,
|
||||
autoRestart: 0, //
|
||||
showKillfeedCoords: 0,
|
||||
autoRestart: 0,
|
||||
showKillfeedCoords: 0,
|
||||
showKillfeedWeapon: 0,
|
||||
purchaseUAV: 1, // Allow/Disallow purchase of UAVs
|
||||
purchaseEMP: 1, // Allow/Disallow purchase of EMPs
|
||||
allowedChannels: [],
|
||||
|
||||
+3
-1
@@ -69,4 +69,6 @@ module.exports = {
|
||||
"M79": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b7/M79.png/revision/latest/scale-to-width-down/256?cb=20220521184052",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
weaponClassOf: (weapon) => Object.keys(module.exports.weapons).filter(v => module.exports.weapons[v].hasOwnProperty(weapon))[0],
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "12.4.9",
|
||||
"version": "12.5.0",
|
||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
+20
-3
@@ -5,6 +5,7 @@ const { destinations } = require('../database/destinations');
|
||||
const { calculateVector } = require('./vector');
|
||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||
const { calculateNewCombatRating } = require('./combatRatingHandler');
|
||||
const { weapons, weaponClassOf } = require('../database/weapons');
|
||||
|
||||
const Templates = {
|
||||
Killed: 1,
|
||||
@@ -129,6 +130,7 @@ module.exports = {
|
||||
const unixTime = Math.floor(newDt.getTime()/1000);
|
||||
|
||||
const showCoords = client.exists(guild.showKillfeedCoords) ? guild.showKillfeedCoords : false; // default to false if no record of configuration.
|
||||
const showWeapon = client.exists(guild.showKillfeedWeapon) ? guild.showKillfeedWeapon : false; // default to false if no record of configuration.
|
||||
let tempDest;
|
||||
let lastDist = 1000000;
|
||||
let destination_dir;
|
||||
@@ -171,34 +173,44 @@ module.exports = {
|
||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, client.config.Nitrado.ServerID);
|
||||
if (!client.exists(killerStat)) killerStat = getDefaultPlayer(info.killer, info.killerID, client.config.Nitrado.ServerID);
|
||||
|
||||
// Update killer stats
|
||||
killerStat.kills++;
|
||||
killerStat.killStreak++;
|
||||
killerStat.bestKillStreak = killerStat.killStreak > killerStat.bestKillStreak ? killerStat.killStreak : killerStat.bestKillStreak;
|
||||
killerStat.KDR = killerStat.kills / (killerStat.deaths == 0 ? 1 : killerStat.deaths); // prevent division by 0
|
||||
killerStat.longestKill = info.distance > killerStat.longestKill ? info.distance : killerStat.longestKill;
|
||||
killerStat.deathStreak = 0;
|
||||
|
||||
// Update victim stats
|
||||
victimStat.deaths++;
|
||||
victimStat.deathStreak++;
|
||||
victimStat.worstDeathStreak = victimStat.deathStreak > victimStat.worstDeathStreak ? victimStat.deathStreak : victimStat.worstDeathStreak;
|
||||
killerStat.KDR = killerStat.kills / (killerStat.deaths == 0 ? 1 : killerStat.deaths); // prevent division by 0
|
||||
victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0
|
||||
victimStat.killStreak = 0;
|
||||
victimStat.lastDeathDate = newDt;
|
||||
killerStat.deathStreak = 0;
|
||||
|
||||
// Create defaults for non-existing ratings
|
||||
if (!client.exists(killerStat.combatRating)) killerStat.combatRating = 800;
|
||||
if (!client.exists(victimStat.combatRating)) victimStat.combatRating = 800;
|
||||
if (!client.exists(killerStat.combatRatingHistory)) killerStat.combatRatingHistory = [800];
|
||||
if (!client.exists(victimStat.combatRatingHistory)) victimStat.combatRatingHistory = [800];
|
||||
if (!client.exists(killerStat.highestCombatRating)) killerStat.highestCombatRating = Math.max(...killerStat.combatRatingHistory);
|
||||
if (!client.exists(victimStat.lowestCombatRating)) victimStat.lowestCombatRating = Math.min(...victimStat.combatRatingHistory);
|
||||
|
||||
// Calculate new ratings
|
||||
let killerOldRating = killerStat.combatRating;
|
||||
let victimOldRating = victimStat.combatRating;
|
||||
killerStat.combatRating = calculateNewCombatRating(killerStat.combatRating, victimStat.combatRating, client.exists(info.bodyPart) && info.bodyPart.includes('Head') ? 1.25 : 1);
|
||||
victimStat.combatRating = calculateNewCombatRating(victimStat.combatRating, killerStat.combatRating, 0);
|
||||
|
||||
// Update combat rating records
|
||||
if (killerStat.combatRating > killerStat.highestCombatRating) killerStat.highestCombatRating = killerStat.combatRating;
|
||||
if (victimStat.combatRating < victimStat.lowestCombatRating) victimStat.lowestCombatRating = victimStat.combatRating;
|
||||
if (killerStat.combatRatingHistory.length >= 12) killerStat.combatRatingHistory = killerStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 12)
|
||||
if (victimStat.combatRatingHistory.length >= 12) victimStat.combatRatingHistory = victimStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 12)
|
||||
killerStat.combatRatingHistory.push(killerStat.combatRating);
|
||||
victimStat.combatRatingHistory.push(victimStat.combatRating);
|
||||
|
||||
let kdiff = killerStat.combatRating - killerOldRating;
|
||||
let vdiff = victimStat.combatRating - victimOldRating;
|
||||
|
||||
@@ -249,10 +261,15 @@ module.exports = {
|
||||
const victimStatsView = `\n**Victim Rating** (${vdiff >= 0 ? '+' : ''}${vdiff}) ${victimStat.combatRating}\n${victimStat.KDR.toFixed(2)} K/D - ${victimStat.deaths} Death${victimStat.deaths == 0 || victimStat.deaths>1?'s':''} - Deathstreak: ${victimStat.deathStreak}`;
|
||||
const coord = showCoords ? `\n***Location [${info.victimPOS[0]}, ${info.victimPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.victimPOS[0]};${info.victimPOS[1]})***\n${destination}` : '';
|
||||
|
||||
const killEvent = new EmbedBuilder()
|
||||
let killEvent = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setDescription(`${header}${killData}${killerStatsView}${victimStatsView}${coord}`);
|
||||
|
||||
if (showWeapon) {
|
||||
let weaponClass = weaponClassOf(weapon);
|
||||
killEvent.setThumbnail(weapons[weaponClass][weapon])
|
||||
}
|
||||
|
||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||
if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||
|
||||
|
||||
Reference in new issue
Block a user