Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bot.on('channelDelete', async (channel) => {
if (! (channel instanceof Eris.TextChannel)) return;
if (channel.guild.id !== utils.getInboxGuild().id) return;
const thread = await threads.findOpenThreadByChannelId(channel.id);
if (! thread) return;
console.log(`[INFO] Auto-closing thread with ${thread.user_name} because the channel was deleted`);
if (config.closeMessage) await thread.postToUser(config.closeMessage).catch(() => {});
await thread.close(true);
const logUrl = await thread.getLogUrl();
utils.postLog(utils.trimAll(`
Modmail thread with ${thread.user_name} (${thread.user_id}) was closed automatically because the channel was deleted
Logs: ${logUrl}
`));
});
};
async function saveDiscordAttachment(attachment) {
if (attachment.size > 1024 * 1024 * 8) {
return getErrorResult('attachment too large (max 8MB)');
}
const attachmentChannelId = config.attachmentStorageChannelId;
const inboxGuild = utils.getInboxGuild();
if (! inboxGuild.channels.has(attachmentChannelId)) {
throw new Error('Attachment storage channel not found!');
}
const attachmentChannel = inboxGuild.channels.get(attachmentChannelId);
if (! (attachmentChannel instanceof Eris.TextChannel)) {
throw new Error('Attachment storage channel must be a text channel!');
}
const file = await attachmentToDiscordFileObject(attachment);
const savedAttachment = await createDiscordAttachmentMessage(attachmentChannel, file);
if (! savedAttachment) return getErrorResult();
return { url: savedAttachment.url };
}
odf(esp, "broadcastEval", function (cmd) {
return new Promise((res, rej) => {
process.send({"_sEval": cmd});
function receiver(msg) {
if (msg._sEval === cmd)
res(msg._result);
else
process.once("message", receiver);
}
process.once("message", receiver);
});
});
})(Eris.Shard.prototype);
Eris.TextChannel.prototype.send = Eris.TextChannel.prototype.createMessage;
odf(Eris.User.prototype, "send", function () {
const args = arguments;
const user = this;
return new Promise((res, rej) => {
user.getDMChannel().then((channel) => {
channel.createMessage.apply(channel, args).then(res).catch(rej);
}).catch(rej);
});
});
odg(Eris.VoiceChannel.prototype, "joinable", function(){return this.permissionsOf(this.guild.shard.client.user.id).has("voiceConnect");});
odg(Eris.VoiceChannel.prototype, "members", function(){return this.voiceMembers;});
odg(Eris.VoiceConnection.prototype, "channel", function () {
var ret = this.flavorSavedChannel;