mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 15:47:57 -05:00
use JSON.stringify on dc msg + improve attachments
This commit is contained in:
parent
d432c2d3af
commit
cea28a2012
1 changed files with 30 additions and 9 deletions
39
index.js
39
index.js
|
@ -636,16 +636,37 @@ dcclient.on('messageCreate', async (message) => {
|
|||
// console.log(e);
|
||||
// }
|
||||
try {
|
||||
const attachment = message.attachments.at(0);
|
||||
if (attachment!=undefined) {
|
||||
if (message.content.toLowerCase()==='') {
|
||||
bot.core.run(`minecraft:tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"ChomeNS ","color":"yellow","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"Discord","color":"blue","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"] ","color":"dark_gray"},{"text":"${message.member.displayName}","color":"red","clickEvent":{"action":"copy_to_clipboard","value":"${message.author.username}#${message.author.discriminator}"},"hoverEvent":{"action":"show_text","value":{"text":"${message.author.username}§7#${message.author.discriminator}"} }},{"text":" › ","color":"dark_gray"},` + `{"text":"[Attachment]","clickEvent":{"action":"open_url","value":"${attachment.proxyURL}"},"color":"green"}` + ']');
|
||||
} else {
|
||||
bot.core.run(`minecraft:tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"ChomeNS ","color":"yellow","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"Discord","color":"blue","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"] ","color":"dark_gray"},{"text":"${message.member.displayName}","color":"red","clickEvent":{"action":"copy_to_clipboard","value":"${message.author.username}#${message.author.discriminator}"},"hoverEvent":{"action":"show_text","value":{"text":"${message.author.username}§7#${message.author.discriminator}"} }},{"text":" › ","color":"dark_gray"},` + chatMessage.MessageBuilder.fromString('&7' + message.content) + `,{"text":" [Attachment]","clickEvent":{"action":"open_url","value":"${attachment.proxyURL}"},"color":"green"}` + ']');
|
||||
}
|
||||
} else {
|
||||
bot.core.run(`minecraft:tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"ChomeNS ","color":"yellow","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"Discord","color":"blue","clickEvent":{"action":"open_url","value":"https://discord.gg/xdgCkUyaA4"},"hoverEvent":{"action":"show_text","contents":[{"text":"https://discord.gg/xdgCkUyaA4 ","color":"blue"},{"text":"<-- join now","color":"red"}]}},{"text":"] ","color":"dark_gray"},{"text":"${message.member.displayName}","color":"red","clickEvent":{"action":"copy_to_clipboard","value":"${message.author.username}#${message.author.discriminator}"},"hoverEvent":{"action":"show_text","value":{"text":"${message.author.username}§7#${message.author.discriminator}"} }},{"text":" › ","color":"dark_gray"},` + chatMessage.MessageBuilder.fromString('&7' + message.content) + ']');
|
||||
const attachmentsComponent = [];
|
||||
if (message.attachments) {
|
||||
message.attachments.forEach((value) => {
|
||||
attachmentsComponent.push({
|
||||
text: ' [Attachment]',
|
||||
color: 'green',
|
||||
clickEvent: {
|
||||
action: 'open_url',
|
||||
value: value.proxyURL,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
const component = [
|
||||
{text: '[', color: 'dark_gray'},
|
||||
{text: 'ChomeNS ', color: 'yellow', clickEvent: {
|
||||
action: 'open_url',
|
||||
value: 'https://discord.gg/xdgCkUyaA4',
|
||||
}},
|
||||
{text: 'Discord', color: 'blue', clickEvent: {
|
||||
action: 'open_url', value: 'https://discord.gg/xdgCkUyaA4',
|
||||
}},
|
||||
{text: '] ', color: 'dark_gray'},
|
||||
{text: `${message.member.displayName}`, color: 'red', clickEvent: {
|
||||
action: 'copy_to_clipboard', value: `${message.author.username}#${message.author.discriminator}`,
|
||||
}},
|
||||
{text: ' › ', color: 'dark_gray'},
|
||||
chatMessage.MessageBuilder.fromString('&7' + message.content),
|
||||
attachmentsComponent.length === 0 ? '' : attachmentsComponent,
|
||||
];
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify(component));
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue