mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 15:47:57 -05:00
110 lines
3.3 KiB
JavaScript
110 lines
3.3 KiB
JavaScript
/* eslint-disable max-len */
|
||
const {escapeMarkdown} = require('../util/escapeMarkdown');
|
||
async function inject(bot, dcclient, config, rl) {
|
||
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
|
||
|
||
let queue = '';
|
||
const queueInterval = setInterval(() => {
|
||
if (queue === '') return;
|
||
|
||
channel.send({
|
||
content: '```ansi\n' + queue.substring(0, 1986) + '\n```',
|
||
allowedMentions: {
|
||
parse: [],
|
||
},
|
||
});
|
||
queue = '';
|
||
}, 1000);
|
||
|
||
bot.on('parsed_chat', (message) => {
|
||
const cleanMessage = escapeMarkdown(message.toAnsi(), true);
|
||
const discordMsg = cleanMessage
|
||
.replaceAll('@', '@\u200b')
|
||
.replaceAll('http', 'http\u200b')
|
||
.replaceAll('\u001b[9', '\u001b[3');
|
||
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
|
||
queue += '\n' + discordMsg;
|
||
});
|
||
|
||
bot.once('end', () => {
|
||
clearInterval(queueInterval);
|
||
});
|
||
|
||
// handle discord messages!!!
|
||
dcclient.on('messageCreate', async (message) => {
|
||
// Ignore messages from the bot itself
|
||
if (message.author.id === dcclient.user.id) return;
|
||
|
||
// Only handle messages in specified channel
|
||
if (message.channel.id !== channel.id) return;
|
||
if (message.content.startsWith(config.discord.prefix)) return;
|
||
|
||
try {
|
||
const attachmentsComponent = [];
|
||
if (message.attachments) {
|
||
message.attachments.forEach((value) => {
|
||
attachmentsComponent.push({
|
||
text: message.content === '' ? '[Attachment]' : ' [Attachment]', // may not be the best fix
|
||
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}`,
|
||
},
|
||
hoverEvent: {
|
||
action: 'show_text',
|
||
value: [
|
||
{
|
||
text: message.author.username,
|
||
color: 'white',
|
||
},
|
||
{
|
||
text: '#',
|
||
color: 'dark_gray',
|
||
},
|
||
{
|
||
text: message.author.discriminator,
|
||
color: 'gray',
|
||
},
|
||
'\n',
|
||
{
|
||
text: 'Click here to copy the tag to your clipboard',
|
||
color: 'green',
|
||
},
|
||
],
|
||
},
|
||
},
|
||
{text: ' › ', color: 'dark_gray'},
|
||
chatMessage.MessageBuilder.fromString('&7' + message.content),
|
||
attachmentsComponent.length === 0 ? '' : attachmentsComponent,
|
||
];
|
||
bot.tellraw('@a', component);
|
||
} catch (e) {
|
||
return;
|
||
}
|
||
});
|
||
};
|
||
|
||
module.exports = {inject};
|