refactor/remove mongoose + quality of life
This commit is contained in:
26 files changed
+235
-329
No files matched your search
@@ -1,5 +1,5 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { destinations } = require('../config/destinations');
|
||||
const { destinations } = require('../database/destinations');
|
||||
const { calculateVector } = require('./vector');
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { calculateVector } = require('./vector');
|
||||
const { destinations } = require('../config/destinations');
|
||||
const { destinations } = require('../database/destinations');
|
||||
|
||||
// Private functions (only called locally)
|
||||
|
||||
|
||||
+10
-10
@@ -1,15 +1,15 @@
|
||||
module.exports = {
|
||||
CommandOptionTypes: {
|
||||
SubCommand: 1,
|
||||
SubCommand: 1,
|
||||
SubCommandGroup: 2,
|
||||
String: 3,
|
||||
Integer: 4,
|
||||
Boolean: 5,
|
||||
User: 6,
|
||||
Channel: 7,
|
||||
Role: 8,
|
||||
Mentionable: 9,
|
||||
Float: 10, // AKA Number in Discord's Documentation
|
||||
Attachment: 11,
|
||||
String: 3,
|
||||
Integer: 4,
|
||||
Boolean: 5,
|
||||
User: 6,
|
||||
Channel: 7,
|
||||
Role: 8,
|
||||
Mentionable: 9,
|
||||
Float: 10, // AKA Number in Discord's Documentation
|
||||
Attachment: 11,
|
||||
}
|
||||
};
|
||||
+15
-26
@@ -1,8 +1,9 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { User, addUser } = require('../structures/user');
|
||||
const { createUser, addUser } = require('../database/user');
|
||||
const { KillInAlarm } = require('./AlarmsHandler');
|
||||
const { destinations } = require('../config/destinations');
|
||||
const { destinations } = require('../database/destinations');
|
||||
const { calculateVector } = require('./vector');
|
||||
const { getDefaultPlayerStats } = require('../database/playerStatistics');
|
||||
|
||||
const Templates = {
|
||||
Killed: 1,
|
||||
@@ -59,7 +60,7 @@ module.exports = {
|
||||
|
||||
let victimStat = stats.find(stat => stat.playerID == info.victimID);
|
||||
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;
|
||||
if (victimStatIndex == -1) stats.push(victimStat);
|
||||
else stats[victimStatIndex] = victimStat;
|
||||
@@ -146,7 +147,7 @@ module.exports = {
|
||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
||||
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;
|
||||
if (victimStatIndex == -1) stats.push(victimStat);
|
||||
else stats[victimStatIndex] = victimStat;
|
||||
@@ -172,8 +173,8 @@ module.exports = {
|
||||
let victimStat = stats.find(stat => stat.playerID == info.victimID)
|
||||
let killerStatIndex = stats.indexOf(killerStat);
|
||||
let victimStatIndex = stats.indexOf(victimStat);
|
||||
if (killerStat == undefined) killerStat = client.getDefaultPlayerStats(info.killer, info.killerID);
|
||||
if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID);
|
||||
if (killerStat == undefined) killerStat = getDefaultPlayerStats(info.killer, info.killerID);
|
||||
if (victimStat == undefined) victimStat = getDefaultPlayerStats(info.victim, info.victimID);
|
||||
|
||||
killerStat.kills++;
|
||||
killerStat.killStreak++;
|
||||
@@ -197,28 +198,16 @@ module.exports = {
|
||||
|
||||
let banking = await client.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
|
||||
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
userID: killerStat.discordID,
|
||||
guilds: {
|
||||
[guildId]: {
|
||||
balance: guild.startingBalance,
|
||||
}
|
||||
}
|
||||
}
|
||||
banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client)
|
||||
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||
}
|
||||
banking = banking.user;
|
||||
|
||||
// Register bank for user
|
||||
let newBank = new User();
|
||||
newBank.createUser(killerStat.discordID, guildId, guild.startingBalance);
|
||||
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.');
|
||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||
}
|
||||
|
||||
const newBalance = banking.guilds[guildId].balance + totalBounty;
|
||||
|
||||
+5
-6
@@ -1,8 +1,7 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { HandleAlarmsAndUAVs } = require('./AlarmsHandler');
|
||||
const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler');
|
||||
|
||||
// custom util imports
|
||||
const { getDefaultPlayerStats } = require('../database/playerStatistics');
|
||||
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||
|
||||
let lastSendMessage;
|
||||
@@ -31,7 +30,7 @@ module.exports = {
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
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);
|
||||
|
||||
@@ -77,7 +76,7 @@ module.exports = {
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
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 unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
||||
@@ -129,7 +128,7 @@ module.exports = {
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
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);
|
||||
|
||||
playerStat.lastPos = playerStat.pos;
|
||||
@@ -168,7 +167,7 @@ module.exports = {
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
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.lastHitBy = info.attacker;
|
||||
|
||||
Reference in new issue
Block a user