Include ports in netmsg and logs, and make mail fancier
This commit is contained in:
parent
93f911aaa8
commit
d2166651be
6 changed files with 29 additions and 9 deletions
3
bot.js
3
bot.js
|
@ -48,7 +48,8 @@ function createBot (options = {}) {
|
|||
|
||||
// properties
|
||||
bot.host = options.host
|
||||
bot.port = options.port
|
||||
bot.port = options.port ?? 25565
|
||||
bot.hostPortPair = bot.port !== 25565 ? bot.host + ':' + bot.port : bot.host
|
||||
|
||||
bot.brand = options.brand
|
||||
bot.styles = options.styles
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { literal, argument, string, greedyString, DynamicCommandExceptionType } = require('brigadier-commands')
|
||||
const { createUuidSelector } = require('../util/command/utility')
|
||||
|
||||
const UNABLE_TO_LOAD_PLAYER_DATA_ERROR = new DynamicCommandExceptionType(error => new TextMessage([{ text: 'An unexpected error occurred trying to send that message', hoverEvent: { action: 'show_text', contents: error.stack } }]))
|
||||
const UNABLE_TO_SEND_MAIL_ERROR = new DynamicCommandExceptionType(error => new TextMessage([{ text: 'An unexpected error occurred trying to send that message', hoverEvent: { action: 'show_text', contents: error.stack } }]))
|
||||
|
||||
module.exports = {
|
||||
register (dispatcher) {
|
||||
|
@ -48,6 +48,7 @@ module.exports = {
|
|||
try {
|
||||
await bot.sendMail(player.username, username, message)
|
||||
} catch (error) {
|
||||
bot.console.error(error.stack)
|
||||
throw UNABLE_TO_SEND_MAIL_ERROR.create(error)
|
||||
}
|
||||
|
||||
|
@ -79,6 +80,8 @@ module.exports = {
|
|||
msg[msg.length - 1].text = msg[msg.length - 1].text.slice(0, -1)
|
||||
|
||||
bot.tellraw(msg, createUuidSelector(player.uuid))
|
||||
|
||||
delete playerData.data.mailUnread
|
||||
},
|
||||
|
||||
clearCommand (context) {
|
||||
|
|
|
@ -19,7 +19,6 @@ module.exports = {
|
|||
const bot = source.bot
|
||||
const message = context.getArgument('message')
|
||||
|
||||
const host = bot.host
|
||||
bot.bots.forEach((bot) => bot.fancyMsg(host, source.displayName, message))
|
||||
bot.bots.forEach((bot2) => bot2.fancyMsg(bot.hostPortPair, source.displayName, message))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ const CommandSource = require('../util/command/command_source')
|
|||
const Console = require('../util/console')
|
||||
|
||||
function inject (bot, options) {
|
||||
bot.console = options.console ? options.console.fork(bot.host) : new Console({ namespace: bot.host })
|
||||
bot.console = options.console ? options.console.fork(bot.hostPortPair) : new Console({ namespace: bot.hostPortPair })
|
||||
|
||||
bot.on('registry_loaded', () => (bot.console.language = bot.registry.language))
|
||||
|
||||
|
|
|
@ -17,15 +17,28 @@ function inject (bot) {
|
|||
playerData.data.mail ??= []
|
||||
playerData.data.mail.push({ sender: sender, message, host: bot.host, port: bot.port })
|
||||
|
||||
const previouslyUnread = playerData.data.mailUnread
|
||||
playerData.data.mailUnread = true
|
||||
|
||||
if (!loadedManually && !previouslyUnread) {
|
||||
for (const bot2 of bot.bots) {
|
||||
const player = bot2.players.find(player => player.username === receiver)
|
||||
if (player) sendMailNotification(player.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
if (loadedManually) await playerData.save()
|
||||
}
|
||||
|
||||
bot.on('player_data_loaded', (player, playerData) => {
|
||||
if (!playerData.data.mail?.length) return
|
||||
|
||||
const msg = [{ text: "You\'ve got mail!\nRun ", ...bot.styles.primary }, { text: bot.commands.prefixes[0] + 'mail list', ...bot.styles.secondary }, ' to read it']
|
||||
bot.tellraw(msg, createUuidSelector(player.uuid))
|
||||
if (!playerData.data.mailUnread) return
|
||||
sendMailNotification(player.uuid)
|
||||
})
|
||||
|
||||
function sendMailNotification (uuid) {
|
||||
const msg = [{ text: "You've got mail!\nRun ", ...bot.styles.primary }, { text: bot.commands.prefixes[0] + 'mail list', ...bot.styles.secondary }, ' to read it']
|
||||
bot.tellraw(msg, createUuidSelector(uuid))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = inject
|
||||
|
|
|
@ -20,6 +20,8 @@ class PlayerData extends PersistentData {
|
|||
parsed.mail = data.mail.value.value.map(this.#parseMail)
|
||||
}
|
||||
|
||||
parsed.mailUnread = !!data.mailUnread?.value
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
|
@ -50,6 +52,8 @@ class PlayerData extends PersistentData {
|
|||
data.mail = nbt.list(nbt.comp(parsed.mail.map(this.#unparseMail)))
|
||||
}
|
||||
|
||||
if (parsed.mailUnread) data.mailUnread = nbt.byte(+parsed.mailUnread)
|
||||
|
||||
return nbt.comp(data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue