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);
// }
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;
}