chipmunkbot3/plugins/mail.js
2024-05-27 18:34:26 -04:00

22 lines
626 B
JavaScript

function inject (bot) {
bot.sendMail = sendMail
async function sendMail (sender, receiver, message) {
let playerData = Object.values(bot.playerData).find(playerData => playerData.data.username === receiver)
let loadedManually = false
if (!playerData) {
playerData = await bot.loadPlayerData(receiver)
loadedManually = true
}
if (loadedManually) playerData.data.username ??= receiver
playerData.data.mail ??= []
playerData.data.mail.push({ sender: sender, message, host: bot.host, port: bot.port })
if (loadedManually) await playerData.save()
}
}
module.exports = inject