22 lines
626 B
JavaScript
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
|