-
Notifications
You must be signed in to change notification settings - Fork 4
Added fix to issue #10 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ export function handleChat(client: DiscordClient) { | |
| const { id } = hoverEvent?.contents || {}; | ||
| const player = bot.playerManager.getPlayerByUUID(id); | ||
|
|
||
| if(username === client.bot.username) return; | ||
| if (username === client.bot.username) return; | ||
| if ( | ||
| client.config['in-game-bot'].muted.find( | ||
| (entry) => entry.name === username | ||
|
|
@@ -47,24 +47,31 @@ export function handleChat(client: DiscordClient) { | |
| case 'multiplayer.player.joined': | ||
| if (color !== 'yellow' || !translate || !username || !id) | ||
| return; | ||
|
|
||
| client.sendEmbedMessage( | ||
| client.config.guild.channels.relay_channel, | ||
| username, | ||
| `${username} has joined the game.`, | ||
| player?.getHeadURL() || client.config.constants.defaultProfile, | ||
| player?.getHeadURL() || | ||
| client.config.constants.defaultProfile, | ||
| '#00ff00' | ||
| ); | ||
| break; | ||
| case 'multiplayer.player.left': | ||
| if (color !== 'yellow' || !translate || !raw.with) return; | ||
| if (client.config['in-game-bot'].muted.find((entry) => entry.name === raw?.with[0]?.text)) return; | ||
| if ( | ||
| client.config['in-game-bot'].muted.find( | ||
| (entry) => entry.name === raw?.with[0]?.text | ||
| ) | ||
| ) | ||
| return; | ||
|
|
||
| client.sendEmbedMessage( | ||
| client.config.guild.channels.relay_channel, | ||
| raw?.with[0]?.text, | ||
| `${raw?.with[0]?.text} has left the game.`, | ||
| player?.getHeadURL() || client.config.constants.defaultProfile, | ||
| player?.getHeadURL() || | ||
| client.config.constants.defaultProfile, | ||
| '#9d3838' | ||
| ); | ||
| break; | ||
|
|
@@ -74,34 +81,85 @@ export function handleChat(client: DiscordClient) { | |
| client.config.guild.channels.relay_channel, | ||
| `Sleeper count has changed!`, | ||
| `There are now ${raw.with.join('/')} players sleeping.`, | ||
| player?.getHeadURL() || client.config.constants.defaultProfile, | ||
| player?.getHeadURL() || | ||
| client.config.constants.defaultProfile, | ||
| '#c2c5cc' | ||
| ); | ||
| break; | ||
| } | ||
| }); | ||
|
|
||
| let messageQueue: string[] = []; | ||
| let sending = false; | ||
| // Detects when a player sends a message in discord channel | ||
| client.on('messageCreate', (message) => { | ||
| if (message.author.bot) return; // Ignore messages from bot | ||
| if (message.channel.id !== client.config.guild.channels.relay_channel) | ||
| // Ignore messages from other channels | ||
| return; | ||
| if (message.content.length > 255) { | ||
| // Ignore messages longer than the MC chat limit | Temporary | ||
| // TODO: Split long messages into multiple and send with delay! | ||
| message.react('❌') | ||
| return; | ||
|
|
||
| // Split long messages to prevent kick from mc server | ||
| if (message.content.length > 255 - message.author.tag.length - 3) { | ||
| // 3 is to account for the " > " in the sent message | ||
| let originalMessage = message.content; | ||
| let splitMessage: string[] = []; | ||
|
|
||
| // Repeat while the message is too long (I use 250 to account for the index of the split message added to the beggining of the message) | ||
| let j = 0; | ||
| while ( | ||
| originalMessage.length > | ||
| 250 - message.author.tag.length - 3 | ||
| ) { | ||
| // Find the space to split the message at | ||
| let i = 250 - message.author.tag.length - 3; | ||
| while (originalMessage[i] !== ' ' || i > 50) { | ||
| i--; | ||
| } | ||
|
|
||
| // If there was no space found, split close to the 255 character limit | ||
| if (i <= 50 || originalMessage[i] !== ' ') { | ||
| splitMessage.push( | ||
| `[${j}] ` + | ||
| originalMessage.slice( | ||
| 0, | ||
| 250 - message.author.tag.length - 3 | ||
| ) | ||
| ); | ||
| originalMessage = originalMessage.slice( | ||
| 250 - message.author.tag.length - 3 | ||
| ); | ||
| } | ||
| // If there was a space found, split at the space | ||
| else { | ||
| splitMessage.push(`[${j}] ` + originalMessage.slice(0, i)); | ||
| originalMessage = originalMessage.slice(i + 1); | ||
| } | ||
| j++; | ||
| } | ||
|
|
||
| // Add the split messages to the queue | ||
| messageQueue = messageQueue.concat(splitMessage); | ||
| } else { | ||
| // Add current message to queue | ||
| messageQueue.push(message.content); | ||
| } | ||
|
|
||
| while (messageQueue.length > 0) { | ||
| if (!sending) { | ||
| bot.write('chat_message', { | ||
| message: message.author.tag + ' > ' + messageQueue[0], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace this with |
||
| timestamp: BigInt(Date.now()), | ||
| salt: 0, | ||
| signature: Buffer.alloc(0), | ||
| signedPreview: false, | ||
| previousMessages: [], | ||
| lastMessage: null | ||
| }); // Send the message to minecraft chat | ||
|
|
||
| messageQueue.shift(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then remove this |
||
| sending = true; | ||
| setTimeout(() => (sending = false), 1000); | ||
| } | ||
| } | ||
|
|
||
| bot.write('chat_message', { | ||
| message: message.author.tag + ' > ' + message.content, | ||
| timestamp: BigInt(Date.now()), | ||
| salt: 0, | ||
| signature: Buffer.alloc(0), | ||
| signedPreview: false, | ||
| previousMessages: [], | ||
| lastMessage: null | ||
| }); // Send the message to minecraft chat | ||
| }); | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A while true loop hangs the program I think