This repository was archived by the owner on Feb 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Added fix to issue #10 #13
Open
XeynQ4
wants to merge
1
commit into
nullsoepic:main
Choose a base branch
from
XeynQ4:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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