refactor/remove mongoose + quality of life
This commit is contained in:
26 files changed
+231
-325
No files matched your search
+6
-19
@@ -2,8 +2,8 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelect
|
|||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||||
const { BanPlayer, UnbanPlayer, RestartServer, CheckServerStatus, DisableBaseDamage } = require('../util/NitradoAPI');
|
const { BanPlayer, UnbanPlayer, RestartServer, CheckServerStatus, DisableBaseDamage } = require('../util/NitradoAPI');
|
||||||
const { Armbands } = require('../config/armbandsdb.js');
|
const { Armbands } = require('../database/armbands.js');
|
||||||
const { User, addUser } = require('../structures/user');
|
const { createUser, addUser } = require('../database/user')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "admin",
|
name: "admin",
|
||||||
@@ -404,23 +404,10 @@ module.exports = {
|
|||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: targetUserID,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { StringSelectMenuBuilder, EmbedBuilder, ActionRowBuilder } = require('discord.js');
|
const { StringSelectMenuBuilder, EmbedBuilder, ActionRowBuilder } = require('discord.js');
|
||||||
const { Armbands } = require('../config/armbandsdb.js');
|
const { Armbands } = require('../database/armbands.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "armbands",
|
name: "armbands",
|
||||||
|
|||||||
+20
-53
@@ -1,6 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const { User, addUser } = require('../structures/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "bank",
|
name: "bank",
|
||||||
@@ -66,23 +66,10 @@ module.exports = {
|
|||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: interaction.member.user.id,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
@@ -97,29 +84,16 @@ module.exports = {
|
|||||||
// Show target users balance
|
// Show target users balance
|
||||||
|
|
||||||
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||||
let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(targetUserBanking => targetUserBanking);
|
||||||
|
|
||||||
if (!targetUserBanking) {
|
if (!targetUserBanking) {
|
||||||
targetUserBanking = {
|
targetUserBanking = await createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: targetUserID,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
targetUserBanking = targetUserBanking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else targetUserBanking = targetUserBanking.user;
|
|
||||||
|
|
||||||
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
|
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(targetUserBanking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,25 +134,18 @@ module.exports = {
|
|||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(targetUserBanking => targetUserBanking);
|
||||||
|
|
||||||
if (!targetUserBanking) {
|
if (!targetUserBanking) {
|
||||||
targetUserBanking = {
|
targetUserBanking = await createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: targetUserID,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
targetUserBanking = targetUserBanking.user;
|
||||||
balance: (GuildDB.startingBalance + args[0].options[1].value),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
|
||||||
let newBank = new User();
|
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||||
newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
newBank.save().catch(err => {
|
}
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
} else targetUserBanking = targetUserBanking.user;
|
|
||||||
|
|
||||||
const newTargetBalance = targetUserBanking.guilds[GuildDB.serverID].balance + args[0].options[1].value;
|
const newTargetBalance = targetUserBanking.guilds[GuildDB.serverID].balance + args[0].options[1].value;
|
||||||
|
|
||||||
|
|||||||
+5
-17
@@ -1,5 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
const { createUser, addUser } = require('../database/user');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "bounty",
|
name: "bounty",
|
||||||
@@ -62,23 +63,10 @@ module.exports = {
|
|||||||
banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: interaction.member.user.id,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
const { ActionRowBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
|
const { ActionRowBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const { Armbands } = require('../config/armbandsdb.js');
|
const { Armbands } = require('../database/armbands.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "claim",
|
name: "claim",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { EmbedBuilder, } = require('discord.js');
|
const { EmbedBuilder, } = require('discord.js');
|
||||||
const { User, addUser } = require('../structures/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "collect-income",
|
name: "collect-income",
|
||||||
@@ -41,25 +41,12 @@ module.exports = {
|
|||||||
|
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: interaction.member.user.id,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
lastIncome: new Date('2000-01-01T00:00:00'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||||
|
const { getDefaultSettings } = require('../database/guildSettings');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "config",
|
name: "config",
|
||||||
@@ -832,7 +833,7 @@ module.exports = {
|
|||||||
let action = '';
|
let action = '';
|
||||||
if (interaction.customId.split('-')[1]=='yes') {
|
if (interaction.customId.split('-')[1]=='yes') {
|
||||||
action = 'reset';
|
action = 'reset';
|
||||||
const defaultGuildConfig = client.getDefaultSettings(GuildDB.serverID);
|
const defaultGuildConfig = getDefaultSettings(GuildDB.serverID);
|
||||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, (err, res) => {
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const { Armbands } = require('../config/armbandsdb.js');
|
const { Armbands } = require('../database/armbands.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "factions",
|
name: "factions",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "location",
|
name: "location",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
|
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
|
||||||
const { User, addUser } = require('../structures/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "purchase-emp",
|
name: "purchase-emp",
|
||||||
@@ -24,24 +24,12 @@ module.exports = {
|
|||||||
|
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: interaction.member.user.id,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const { User, addUser } = require('../structures/user')
|
const { createUser, addUser } = require('../database/user')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "purchase-uav",
|
name: "purchase-uav",
|
||||||
@@ -42,24 +42,12 @@ module.exports = {
|
|||||||
|
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: interaction.member.user.id,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[GuildDB.serverID]: {
|
banking = banking.user;
|
||||||
balance: GuildDB.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
|
||||||
let newBank = new User();
|
|
||||||
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0);
|
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const { addUser } = require('../structures/user');
|
const { addUser } = require('../database/user');
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,39 @@
|
|||||||
|
module.exports = {
|
||||||
|
getDefaultSettings(GuildId) {
|
||||||
|
return {
|
||||||
|
serverID: GuildId,
|
||||||
|
autoRestart: 0,
|
||||||
|
showKillfeedCoords: 0,
|
||||||
|
allowedChannels: [],
|
||||||
|
|
||||||
|
killfeedChannel: "",
|
||||||
|
connectionLogsChannel: "",
|
||||||
|
activePlayersChannel: "",
|
||||||
|
welcomeChannel: "",
|
||||||
|
|
||||||
|
factionArmbands: {},
|
||||||
|
usedArmbands: [],
|
||||||
|
excludedRoles: [],
|
||||||
|
botAdminRoles: [],
|
||||||
|
|
||||||
|
playerstats: [], // to be removed
|
||||||
|
|
||||||
|
alarms: [],
|
||||||
|
events: [],
|
||||||
|
uavs: [],
|
||||||
|
|
||||||
|
incomeRoles: [],
|
||||||
|
incomeLimiter: 168, // # of hours in 7 days
|
||||||
|
|
||||||
|
startingBalance: 500,
|
||||||
|
uavPrice: 50000,
|
||||||
|
empPrice: 500000,
|
||||||
|
|
||||||
|
linkedGamertagRole: "",
|
||||||
|
memberRole: "",
|
||||||
|
adminRole: "",
|
||||||
|
|
||||||
|
combatLogTimer: 5, // minutes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
module.exports = {
|
||||||
|
getDefaultPlayerStats(gt, pID) {
|
||||||
|
return {
|
||||||
|
gamertag: gt,
|
||||||
|
playerID: pID,
|
||||||
|
discordID: "",
|
||||||
|
|
||||||
|
KDR: 0.00,
|
||||||
|
kills: 0,
|
||||||
|
deaths: 0,
|
||||||
|
killStreak: 0,
|
||||||
|
bestKillStreak: 0,
|
||||||
|
longestKill: 0,
|
||||||
|
deathStreak: 0,
|
||||||
|
worstDeathStreak: 0,
|
||||||
|
|
||||||
|
pos: [],
|
||||||
|
lastPos: [],
|
||||||
|
time: null,
|
||||||
|
lastTime: null,
|
||||||
|
|
||||||
|
lastConnectionDate: null,
|
||||||
|
lastDisconnectionDate: null,
|
||||||
|
lastDamageDate: null,
|
||||||
|
lastDeathDate: null,
|
||||||
|
lastHitBy: null,
|
||||||
|
connected: false,
|
||||||
|
|
||||||
|
totalSessionTime: 0,
|
||||||
|
lastSessionTime: 0,
|
||||||
|
longestSessionTime: 0,
|
||||||
|
|
||||||
|
bounties: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
module.exports = {
|
||||||
|
createUser: async (userID, initialGuildID, startingBalance, client) => {
|
||||||
|
let User = {
|
||||||
|
user: {
|
||||||
|
userID: userID,
|
||||||
|
guilds: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
User.user.guilds[initialGuildID] = {
|
||||||
|
balance: startingBalance,
|
||||||
|
lastIncome: new Date('2000-01-01T00:00:00'),
|
||||||
|
};
|
||||||
|
|
||||||
|
await client.dbo.collection("users").insertOne(User, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
client.error(`Failed to create user - ${err}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return User;
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
This function is to add a new guild specific user to an already existing
|
||||||
|
user document
|
||||||
|
or
|
||||||
|
can be used to reset a data back to default
|
||||||
|
*/
|
||||||
|
addUser: async (guilds, newGuildID, userID, client, startingBalance) => {
|
||||||
|
let updatedGuilds = guilds;
|
||||||
|
updatedGuilds[newGuildID] = {
|
||||||
|
balance: startingBalance,
|
||||||
|
lastIncome: new Date('2000-01-01T00:00:00')
|
||||||
|
}
|
||||||
|
|
||||||
|
await client.dbo.collection("users").updateOne({"user.userID":userID}, {$set: {"user.guilds": updatedGuilds}}, (err, res) => {
|
||||||
|
if (err) return false
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const DayzR = require('./structures/DayzRBot');
|
const DayzR = require('./src/DayzRBot');
|
||||||
const config = require('./config/config');
|
const config = require('./config/config');
|
||||||
const { GatewayIntentBits } = require('discord.js');
|
const { GatewayIntentBits } = require('discord.js');
|
||||||
|
|
||||||
@@ -8,24 +8,24 @@ const { HandleActivePlayersList } = require('./util/LogsHandler');
|
|||||||
|
|
||||||
// Log all uncaught exceptions before killing process.
|
// Log all uncaught exceptions before killing process.
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
// Asynchronously write the error message to a log file using Promises
|
// Asynchronously write the error message to a log file using Promises
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
||||||
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
||||||
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
||||||
if (logErr) {
|
if (logErr) {
|
||||||
console.error('Error writing uncaughtException to log file:', logErr);
|
console.error('Error writing uncaughtException to log file:', logErr);
|
||||||
reject(logErr);
|
reject(logErr);
|
||||||
process.exit()
|
process.exit()
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now gracefully close the program
|
// Now gracefully close the program
|
||||||
process.exit()
|
process.exit()
|
||||||
});
|
});
|
||||||
|
|
||||||
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "10.4.4",
|
"version": "11.0.0",
|
||||||
"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,7 +25,6 @@
|
|||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"mongodb": "^4.12.1",
|
"mongodb": "^4.12.1",
|
||||||
"mongoose": "^7.0.1",
|
|
||||||
"winston": "^3.8.1"
|
"winston": "^3.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
|
|||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const { REST } = require('@discordjs/rest');
|
const { REST } = require('@discordjs/rest');
|
||||||
const Logger = require("../util/Logger");
|
const Logger = require("../util/Logger");
|
||||||
const mongoose = require('mongoose');
|
|
||||||
|
|
||||||
// custom util imports
|
// custom util imports
|
||||||
const { DownloadNitradoFile, CheckServerStatus } = require('../util/NitradoAPI');
|
const { DownloadNitradoFile, CheckServerStatus } = require('../util/NitradoAPI');
|
||||||
@@ -11,6 +10,10 @@ const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandl
|
|||||||
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
||||||
const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler');
|
const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler');
|
||||||
|
|
||||||
|
// Data structures imports
|
||||||
|
const { getDefaultPlayerStats } = require('../database/playerStatistics');
|
||||||
|
const { getDefaultSettings } = require('../database/guildSettings');
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
@@ -193,7 +196,7 @@ class DayzRBot extends Client {
|
|||||||
|
|
||||||
lastDetectedTime = await this.getDateEST(info.time);
|
lastDetectedTime = await this.getDateEST(info.time);
|
||||||
let playerStat = s.find(stat => stat.playerID == info.playerID);
|
let playerStat = s.find(stat => stat.playerID == info.playerID);
|
||||||
if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID);
|
if (playerStat == undefined) playerStat = getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
||||||
|
|
||||||
@@ -283,19 +286,13 @@ class DayzRBot extends Client {
|
|||||||
// Connect to Mongo database.
|
// Connect to Mongo database.
|
||||||
this.db = await MongoClient.connect(mongoURI, { connectTimeoutMS: 1000 });
|
this.db = await MongoClient.connect(mongoURI, { connectTimeoutMS: 1000 });
|
||||||
this.dbo = this.db.db(dbo);
|
this.dbo = this.db.db(dbo);
|
||||||
mongoose.connect(`mongodb://${mongoURI.split('@')[1]}/${dbo}`, {
|
|
||||||
authSource: "admin",
|
|
||||||
user: mongoURI.split('//')[1].split(':')[0],
|
|
||||||
pass: mongoURI.split('//')[1].split(':')[1].split('@')[0],
|
|
||||||
useNewUrlParser: true,
|
|
||||||
}).catch(e => this.error(e));
|
|
||||||
this.log('Successfully connected to mongoDB');
|
this.log('Successfully connected to mongoDB');
|
||||||
databaselogs.connected = true;
|
databaselogs.connected = true;
|
||||||
databaselogs.attempts = 0; // reset attempts
|
databaselogs.attempts = 0; // reset attempts
|
||||||
this.databaseConnected = true;
|
this.databaseConnected = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
databaselogs.attempts++;
|
databaselogs.attempts++;
|
||||||
this.error(`Failed to connect to mongodb (mongodb://${mongoURI.split('@')[1]}/${dbo}): attempt ${databaselogs.attempts} - Error: ${err}`);
|
this.error(`Failed to connect to mongodb (mongodb://${mongoURI.split('@')[1]}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,66 +401,6 @@ class DayzRBot extends Client {
|
|||||||
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultSettings(GuildId) {
|
|
||||||
return {
|
|
||||||
serverID: GuildId,
|
|
||||||
autoRestart: 0,
|
|
||||||
allowedChannels: [],
|
|
||||||
killfeedChannel: "",
|
|
||||||
showKillfeedCoords: 0,
|
|
||||||
connectionLogsChannel: "",
|
|
||||||
activePlayersChannel: "",
|
|
||||||
welcomeChannel: "",
|
|
||||||
factionArmbands: {},
|
|
||||||
usedArmbands: [],
|
|
||||||
excludedRoles: [],
|
|
||||||
botAdminRoles: [],
|
|
||||||
playerstats: [],
|
|
||||||
alarms: [],
|
|
||||||
events: [],
|
|
||||||
uavs: [],
|
|
||||||
incomeRoles: [],
|
|
||||||
incomeLimiter: 168, // # of hours in 7 days
|
|
||||||
linkedGamertagRole: "",
|
|
||||||
startingBalance: 500,
|
|
||||||
uavPrice: 50000,
|
|
||||||
empPrice: 500000,
|
|
||||||
memberRole: "",
|
|
||||||
adminRole: "",
|
|
||||||
combatLogTimer: 5, // minutes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getDefaultPlayerStats(gt, pID) {
|
|
||||||
return {
|
|
||||||
gamertag: gt,
|
|
||||||
playerID: pID,
|
|
||||||
discordID: "",
|
|
||||||
KDR: 0.00,
|
|
||||||
kills: 0,
|
|
||||||
deaths: 0,
|
|
||||||
killStreak: 0,
|
|
||||||
bestKillStreak: 0,
|
|
||||||
longestKill: 0,
|
|
||||||
deathStreak: 0,
|
|
||||||
worstDeathStreak: 0,
|
|
||||||
pos: [],
|
|
||||||
lastPos: [],
|
|
||||||
time: null,
|
|
||||||
lastTime: null,
|
|
||||||
lastConnectionDate: null,
|
|
||||||
lastDisconnectionDate: null,
|
|
||||||
lastDamageDate: null,
|
|
||||||
lastDeathDate: null,
|
|
||||||
lastHitBy: null,
|
|
||||||
connected: false,
|
|
||||||
totalSessionTime: 0,
|
|
||||||
lastSessionTime: 0,
|
|
||||||
longestSessionTime: 0,
|
|
||||||
bounties: [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async GetGuild(GuildId) {
|
async GetGuild(GuildId) {
|
||||||
let guild = undefined;
|
let guild = undefined;
|
||||||
if (this.databaseConnected) guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild);
|
if (this.databaseConnected) guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild);
|
||||||
@@ -471,7 +408,7 @@ class DayzRBot extends Client {
|
|||||||
// If guild not found, generate guild default
|
// If guild not found, generate guild default
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
guild = {}
|
guild = {}
|
||||||
guild.server = this.getDefaultSettings(GuildId);
|
guild.server = getDefaultSettings(GuildId);
|
||||||
if (this.databaseConnected) {
|
if (this.databaseConnected) {
|
||||||
this.dbo.collection("guilds").insertOne(guild, (err, res) => {
|
this.dbo.collection("guilds").insertOne(guild, (err, res) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
const mongoose = require('mongoose');
|
|
||||||
|
|
||||||
let userSchema = mongoose.Schema({
|
|
||||||
user: {
|
|
||||||
userID: String,
|
|
||||||
guilds: {}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
userSchema.methods.createUser = function (userID, guildID, startingBalance) {
|
|
||||||
this.user.userID = userID;
|
|
||||||
this.user.guilds = {};
|
|
||||||
this.user.guilds[guildID] = {
|
|
||||||
balance: startingBalance,
|
|
||||||
lastIncome: new Date('2000-01-01T00:00:00'),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
This function is to add a new guild specific user to an already existing
|
|
||||||
user document
|
|
||||||
or
|
|
||||||
can be used to reset a data back to default
|
|
||||||
*/
|
|
||||||
function addUser(guilds, guildID, userID, client, startingBalance) {
|
|
||||||
let updatedGuilds = guilds;
|
|
||||||
updatedGuilds[guildID] = {
|
|
||||||
balance: startingBalance,
|
|
||||||
lastIncome: new Date('2000-01-01T00:00:00')
|
|
||||||
}
|
|
||||||
|
|
||||||
client.dbo.collection("users").updateOne({"user.userID":userID}, {$set: {"user.guilds": updatedGuilds}}, (err, res) => {
|
|
||||||
if (err) return false
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
User: mongoose.model('User', userSchema),
|
|
||||||
addUser: addUser,
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { destinations } = require('../config/destinations');
|
const { destinations } = require('../database/destinations');
|
||||||
const { calculateVector } = require('./vector');
|
const { calculateVector } = require('./vector');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { calculateVector } = require('./vector');
|
const { calculateVector } = require('./vector');
|
||||||
const { destinations } = require('../config/destinations');
|
const { destinations } = require('../database/destinations');
|
||||||
|
|
||||||
// Private functions (only called locally)
|
// Private functions (only called locally)
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -1,15 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
CommandOptionTypes: {
|
CommandOptionTypes: {
|
||||||
SubCommand: 1,
|
SubCommand: 1,
|
||||||
SubCommandGroup: 2,
|
SubCommandGroup: 2,
|
||||||
String: 3,
|
String: 3,
|
||||||
Integer: 4,
|
Integer: 4,
|
||||||
Boolean: 5,
|
Boolean: 5,
|
||||||
User: 6,
|
User: 6,
|
||||||
Channel: 7,
|
Channel: 7,
|
||||||
Role: 8,
|
Role: 8,
|
||||||
Mentionable: 9,
|
Mentionable: 9,
|
||||||
Float: 10, // AKA Number in Discord's Documentation
|
Float: 10, // AKA Number in Discord's Documentation
|
||||||
Attachment: 11,
|
Attachment: 11,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+15
-26
@@ -1,8 +1,9 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { User, addUser } = require('../structures/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
const { KillInAlarm } = require('./AlarmsHandler');
|
const { KillInAlarm } = require('./AlarmsHandler');
|
||||||
const { destinations } = require('../config/destinations');
|
const { destinations } = require('../database/destinations');
|
||||||
const { calculateVector } = require('./vector');
|
const { calculateVector } = require('./vector');
|
||||||
|
const { getDefaultPlayerStats } = require('../database/playerStatistics');
|
||||||
|
|
||||||
const Templates = {
|
const Templates = {
|
||||||
Killed: 1,
|
Killed: 1,
|
||||||
@@ -59,7 +60,7 @@ module.exports = {
|
|||||||
|
|
||||||
let victimStat = stats.find(stat => stat.playerID == info.victimID);
|
let victimStat = stats.find(stat => stat.playerID == info.victimID);
|
||||||
let victimStatIndex = stats.indexOf(victimStat);
|
let victimStatIndex = stats.indexOf(victimStat);
|
||||||
if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID);
|
if (victimStat == undefined) victimStat = getDefaultPlayerStats(info.victim, info.victimID);
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
if (victimStatIndex == -1) stats.push(victimStat);
|
if (victimStatIndex == -1) stats.push(victimStat);
|
||||||
else stats[victimStatIndex] = victimStat;
|
else stats[victimStatIndex] = victimStat;
|
||||||
@@ -146,7 +147,7 @@ module.exports = {
|
|||||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||||
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
||||||
let victimStatIndex = stats.indexOf(victimStat);
|
let victimStatIndex = stats.indexOf(victimStat);
|
||||||
if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID);
|
if (victimStat == undefined) victimStat = getDefaultPlayerStats(info.victim, info.victimID);
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
if (victimStatIndex == -1) stats.push(victimStat);
|
if (victimStatIndex == -1) stats.push(victimStat);
|
||||||
else stats[victimStatIndex] = victimStat;
|
else stats[victimStatIndex] = victimStat;
|
||||||
@@ -172,8 +173,8 @@ module.exports = {
|
|||||||
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
||||||
let killerStatIndex = stats.indexOf(killerStat);
|
let killerStatIndex = stats.indexOf(killerStat);
|
||||||
let victimStatIndex = stats.indexOf(victimStat);
|
let victimStatIndex = stats.indexOf(victimStat);
|
||||||
if (killerStat == undefined) killerStat = client.getDefaultPlayerStats(info.killer, info.killerID);
|
if (killerStat == undefined) killerStat = getDefaultPlayerStats(info.killer, info.killerID);
|
||||||
if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID);
|
if (victimStat == undefined) victimStat = getDefaultPlayerStats(info.victim, info.victimID);
|
||||||
|
|
||||||
killerStat.kills++;
|
killerStat.kills++;
|
||||||
killerStat.killStreak++;
|
killerStat.killStreak++;
|
||||||
@@ -197,28 +198,16 @@ module.exports = {
|
|||||||
|
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
|
||||||
|
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = {
|
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||||
userID: killerStat.discordID,
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
guilds: {
|
}
|
||||||
[guildId]: {
|
banking = banking.user;
|
||||||
balance: guild.startingBalance,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register bank for user
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
let newBank = new User();
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
newBank.createUser(killerStat.discordID, guildId, guild.startingBalance);
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
newBank.save().catch(err => {
|
|
||||||
if (err) return client.sendError(client.GetChannel(guild.killfeedChannel), err);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else banking = banking.user;
|
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[guildId])) {
|
|
||||||
const success = addUser(banking.guilds, guildId, killer.discordID, this, guild.startingBalance);
|
|
||||||
if (!success) return client.sendError(client.GetChannel(guild.killfeedChannel), 'Automatic Bounty Payout: Failed to add bank to database.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBalance = banking.guilds[guildId].balance + totalBounty;
|
const newBalance = banking.guilds[guildId].balance + totalBounty;
|
||||||
|
|||||||
+5
-6
@@ -1,8 +1,7 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { HandleAlarmsAndUAVs } = require('./AlarmsHandler');
|
const { HandleAlarmsAndUAVs } = require('./AlarmsHandler');
|
||||||
const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler');
|
const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler');
|
||||||
|
const { getDefaultPlayerStats } = require('../database/playerStatistics');
|
||||||
// custom util imports
|
|
||||||
const { FetchServerSettings } = require('../util/NitradoAPI');
|
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||||
|
|
||||||
let lastSendMessage;
|
let lastSendMessage;
|
||||||
@@ -31,7 +30,7 @@ module.exports = {
|
|||||||
|
|
||||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||||
let playerStatIndex = stats.indexOf(playerStat);
|
let playerStatIndex = stats.indexOf(playerStat);
|
||||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
if (playerStat === undefined) playerStat = getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
@@ -77,7 +76,7 @@ module.exports = {
|
|||||||
|
|
||||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||||
let playerStatIndex = stats.indexOf(playerStat);
|
let playerStatIndex = stats.indexOf(playerStat);
|
||||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
if (playerStat === undefined) playerStat = getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
const unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
const unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
||||||
@@ -129,7 +128,7 @@ module.exports = {
|
|||||||
|
|
||||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||||
let playerStatIndex = stats.indexOf(playerStat);
|
let playerStatIndex = stats.indexOf(playerStat);
|
||||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
if (playerStat === undefined) playerStat = getDefaultPlayerStats(info.player, info.playerID);
|
||||||
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastPos = playerStat.pos;
|
playerStat.lastPos = playerStat.pos;
|
||||||
@@ -168,7 +167,7 @@ module.exports = {
|
|||||||
|
|
||||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||||
let playerStatIndex = stats.indexOf(playerStat);
|
let playerStatIndex = stats.indexOf(playerStat);
|
||||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
if (playerStat === undefined) playerStat = getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
||||||
playerStat.lastHitBy = info.attacker;
|
playerStat.lastHitBy = info.attacker;
|
||||||
|
|||||||
Reference in new issue
Block a user