diff --git a/commands/bank.js b/commands/bank.js index 7781a83..8f28911 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -135,7 +135,7 @@ module.exports = { if (err) return client.sendInternalError(interaction, err); }); - } else banking = banking.banking; + } else banking = banking.user; if (!client.exists(banking.guilds[GuildDB.serverID])) { const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); diff --git a/commands/bounty.js b/commands/bounty.js index 9954415..f0fc999 100644 --- a/commands/bounty.js +++ b/commands/bounty.js @@ -73,7 +73,7 @@ module.exports = { if (err) return client.sendInternalError(interaction, err); }); - } else banking = banking.banking; + } else banking = banking.user; if (!client.exists(banking.guilds[GuildDB.serverID])) { const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); diff --git a/commands/collect-income.js b/commands/collect-income.js index e69de29..bf34faf 100644 --- a/commands/collect-income.js +++ b/commands/collect-income.js @@ -0,0 +1,46 @@ +const { EmbedBuilder, } = require('discord.js'); +const { Inventory, addInventory } = require('../structures/inventory'); +const { Bank, addBank } = require('../structures/bank'); + +module.exports = { + name: "collect-income", + debug: false, + global: false, + description: "Collect Your Income", + 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 (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); + } + + const hasIncomeRole = GuildDB.incomeRoles.some(data => { + if (interaction.member.roles.includes(data.role)) return true; + return false; + }); + + if (!hasIncomeRole) { + const error = new EmbedBuilder() + .setColor(client.config.Colors.Red) + .setTitle('No Income!') + .setDescription(`It appears you don't have any roles to earn income.`) + + return interaction.send({ embeds: [error] }) + } + + + }, + }, +} \ No newline at end of file diff --git a/commands/money.js b/commands/money.js index 2edeb52..e1e9be8 100644 --- a/commands/money.js +++ b/commands/money.js @@ -94,8 +94,8 @@ module.exports = { // Register inventory for user let newBank = new User(); - newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0); - newBank.save().catch(err => { + await newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0); + await newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); diff --git a/commands/player-list.js b/commands/player-list.js index 624386a..b234413 100644 --- a/commands/player-list.js +++ b/commands/player-list.js @@ -1,10 +1,10 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { - name: "stats", - debug: true, - global: true, - description: "check bot statistics", + name: "player-list", + debug: false, + global: false, + description: "get current online players", usage: "", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], diff --git a/commands/reset.js b/commands/reset.js index 9316efc..6a69f96 100644 --- a/commands/reset.js +++ b/commands/reset.js @@ -81,7 +81,7 @@ module.exports = { let bankingReset = false; if (!banking) bankingReset = true - else banking = banking.banking + else banking = banking.user if (!bankingReset) { const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 29e7309..71ab785 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -3,6 +3,7 @@ const { Collection, Client, EmbedBuilder, Routes } = require('discord.js'); const MongoClient = require('mongodb').MongoClient; const { REST } = require('@discordjs/rest'); const Logger = require("../util/Logger"); +const mongoose = require('mongoose'); const path = require("path"); const fs = require('fs'); @@ -186,7 +187,7 @@ class DayzArmbands extends Client { if (err) return client.sendInternalError(interaction, err); }); - } else banking = banking.banking; + } else banking = banking.user; if (!this.exists(banking.guilds[guild.serverID])) { const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, this, guild.startingBalance); @@ -310,6 +311,30 @@ class DayzArmbands extends Client { if (this.exists(channel)) channel.send({ embeds: [connectionLog] }); } + async detectCombatLog(guildId, data) { + if (data.lastDamageDate == null) return; + + let today = new Date(); + let newDt = new Date(`${today.toLocaleDateString('default', { month: 'long' })} ${today.getDate()}, ${today.getFullYear()} ${info.time} EST`); + + let diffMs = (newDt - data.lastDamageDate) + let diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes + + if (diffMins > 5) return; + + let guild = await this.GetGuild(guildId); + if (!this.exists(guild.connectionLogsChannel)) return; + const channel = this.channels.cache.get(guild.connectionLogsChannel); + + let unixTime = Math.floor(newDt.getTime()/1000); + + let combatLog = new EmbedBuilder() + .setColor(this.config.Colors.Red) + .setDescription(`**NOTICE:**\n**${info.player}** has combat logged at when fighting **${info.lastHitBy}**`); + + return channel.send({ embeds: {combatLog} }); + } + async handlePlayerLogs(guildId, line) { let guild = await this.GetGuild(guildId); @@ -318,6 +343,7 @@ class DayzArmbands extends Client { const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g; const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g; const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; + const damangeTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP: (.*)\] hit by Player \"(.*)\"\(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; if (line.includes('connected')) { let data = [...line.matchAll(connectTemplate)][0]; @@ -388,9 +414,16 @@ class DayzArmbands extends Client { this.sendConnectionLogs(guildId, { time: info.time, player: info.player, - conected: info.connected, + connected: info.connected, lastConnectionDate: playerStat.lastConnectionDate, }); + + this.detectCombatLog(guildId, { + time: info.time, + player: info.player, + lastDamageDate: playerStat.lastDamageDate, + lastHitBy: playerStat.lastHitBy, + }); } if (line.includes('pos=<')) { @@ -427,6 +460,37 @@ class DayzArmbands extends Client { if (err) this.error(err); }); } + + if (line.includes('hit by Player')) { + let data = [...line.matchAll(damangeTemplate)]; + + let info = { + time: data[1], + player: data[2], + playerID: data[3], + } + + let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID) + let playerStatIndex = guild.playerstats.indexOf(playerStat); + if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID); + + let today = new Date(); + let newDt = new Date(`${today.toLocaleDateString('default', { month: 'long' })} ${today.getDate()}, ${today.getFullYear()} ${info.time} EST`); + + playerStats.lastDamageDate = newDt; + playerStats.lastHitBy = data[6]; + + if (playerStatIndex == -1) guild.playerstats.push(playerStat); + else guild.playerstatus[playerStatIndex] = playerStat; + + this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, { + $set: { + "server.playerstats": guild.playerstats + } + }, function (err, res) { + if (err) this.error(err); + }); + } } async handleActivePlayersList(guildId) { @@ -524,6 +588,7 @@ class DayzArmbands extends Client { // Connect to Mongo database. this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 1000}); this.dbo = this.db.db(dbo); + mongoose.connect(`${mongoURI}/${dbo}`); this.log('Successfully connected to mongoDB'); databaselogs.connected = true; databaselogs.attempts = 0; // reset attempts @@ -635,6 +700,7 @@ class DayzArmbands extends Client { botAdminRoles: [], playerstats: [], alarms: [], + incomeRoles: [] } } @@ -652,6 +718,8 @@ class DayzArmbands extends Client { worstDeathStreak: 0, pos: [], lastConnectionDate: null, + lastDamageDate: null, + lastHitBy: null, connected: false, bounties: [], } diff --git a/structures/user.js b/structures/user.js index 022a549..f20e400 100644 --- a/structures/user.js +++ b/structures/user.js @@ -15,8 +15,6 @@ userSchema.methods.createUser = function (userID, guildID, startingBalance, cash balance: startingBalance, cash: cash, }, - faction: "", - gamertag: "" }; };