chipmunkbot3/plugins/seen.js

27 lines
730 B
JavaScript

function inject (bot) {
bot.on('player_data_loaded', (player, data) => {
data.data.seen ??= {}
const seenData = data.data.seen
if (seenData.first == null) {
seenData.first = createSeenValue()
bot.tellraw([
{ text: 'Welcome ', ...bot.styles.primary },
{ text: player.username, ...bot.styles.secondary },
' to the server!'
], '@a')
}
seenData.last = createSeenValue()
})
bot.on('player_data_unloading', (player, data) => {
const seenData = data.data.seen
if (seenData != null) seenData.last = createSeenValue()
})
function createSeenValue () {
return { date: new Date(), host: bot.host, port: bot.port ?? 25565 }
}
}
module.exports = inject