use JSON.stringify on dc msg + improve attachments

This commit is contained in:
ChomeNS 2022-10-26 19:12:13 +07:00
parent d432c2d3af
commit cea28a2012

View file

@ -636,16 +636,37 @@ dcclient.on('messageCreate', async (message) => {
// console.log(e); // console.log(e);
// } // }
try { try {
const attachment = message.attachments.at(0); const attachmentsComponent = [];
if (attachment!=undefined) { if (message.attachments) {
if (message.content.toLowerCase()==='') { message.attachments.forEach((value) => {
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"}` + ']'); attachmentsComponent.push({
} else { text: ' [Attachment]',
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"}` + ']'); color: 'green',
} clickEvent: {
} else { action: 'open_url',
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) + ']'); 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) { } catch (e) {
return; return;
} }