2024-04-02 17:53:10 -04:00
|
|
|
const { literal, argument, string, greedyString } = require('brigadier-commands')
|
|
|
|
const { createUuidSelector } = require('../util/command/utility')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
register (dispatcher) {
|
|
|
|
const listNode = literal('list').executes(this.listCommand).build()
|
|
|
|
|
|
|
|
const node = dispatcher.register(
|
|
|
|
literal('mail')
|
|
|
|
.then(
|
|
|
|
literal('send')
|
|
|
|
.then(
|
|
|
|
argument('username', string())
|
|
|
|
.then(
|
|
|
|
argument('message', greedyString())
|
|
|
|
.executes(this.sendCommand)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
listNode
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
literal('read')
|
|
|
|
.executes(this.listCommand)
|
|
|
|
.redirect(listNode)
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
literal('clear')
|
|
|
|
.executes(this.clearCommand)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
node.description = 'Sends and receives mail from players'
|
|
|
|
node.permissionLevel = 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sendCommand (context) {
|
|
|
|
const source = context.source
|
|
|
|
const bot = source.bot
|
|
|
|
const player = source.getPlayerOrThrow()
|
|
|
|
|
|
|
|
const username = context.getArgument('username')
|
|
|
|
const message = context.getArgument('message')
|
|
|
|
|
|
|
|
bot.sendMail(player.username, username, message)
|
|
|
|
bot.tellraw([
|
|
|
|
{ text: 'Sent ', ...bot.styles.primary },
|
|
|
|
{ text: message, ...bot.styles.secondary },
|
|
|
|
' to ',
|
|
|
|
{ text: username, ...bot.styles.secondary }
|
|
|
|
], createUuidSelector(player.uuid))
|
|
|
|
},
|
|
|
|
|
|
|
|
listCommand (context) {
|
|
|
|
const source = context.source
|
|
|
|
const bot = source.bot
|
|
|
|
const player = source.getPlayerOrThrow()
|
|
|
|
|
|
|
|
const messages = bot.mail[player.username]
|
|
|
|
if (!messages || messages.length < 1) {
|
|
|
|
bot.tellraw({ text: 'You have no mail', ...bot.styles.primary }, createUuidSelector(player.uuid))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg = [{ text: 'Mail:\n', ...bot.styles.primary }]
|
|
|
|
messages.forEach((message) => {
|
|
|
|
msg.push(`${message.sender} (from ${message.host}): `)
|
|
|
|
msg.push({ text: `${message.message}\n`, ...bot.styles.secondary })
|
|
|
|
})
|
|
|
|
msg[msg.length - 1].text = msg[msg.length - 1].text.slice(0, -1)
|
|
|
|
|
|
|
|
bot.tellraw(msg, createUuidSelector(player.uuid))
|
|
|
|
},
|
|
|
|
|
|
|
|
clearCommand (context) {
|
|
|
|
const source = context.source
|
|
|
|
const bot = source.bot
|
|
|
|
const player = source.getPlayerOrThrow()
|
|
|
|
|
|
|
|
delete bot.mail[player.username]
|
|
|
|
bot.tellraw({ text: 'Your mail has been cleared', ...bot.styles.primary }, createUuidSelector(player.uuid))
|
2024-02-11 21:23:41 -05:00
|
|
|
}
|
|
|
|
}
|