Compare commits

..

2 Commits

Author SHA1 Message Date
13fb466144 make pin quote things use attached avatar now that it's possible 2021-12-03 00:39:31 -08:00
606aa4b72f /avatar user default self 2021-12-03 00:31:42 -08:00
2 changed files with 10 additions and 20 deletions

View File

@ -71,12 +71,11 @@ var commands = module.exports = [
{
name: "user",
description: "can i not leave some obvious descriptions blank?",
type: "USER",
required: true
type: "USER"
}
],
exec: async i => {
var user = i.options.getUser("user");
var user = i.options.getUser("user") || i.user;
var au = user.avatarURL({size:4096, dynamic: true});
var an = au.split('/').pop(); an = an.substring(0, an.indexOf('?'));
i.reply({files: [{attachment: au, name: an}], embeds: [{

View File

@ -53,26 +53,13 @@ client.on("messageReactionAdd", async (reaction, user) => {
async function doThing(message, user) {
// cache avatar because discord doesn't keep it if they change it
var avatarURL = message.author.avatarURL({dynamic: true});
if (avatarURL) {
let afn = avatarURL.split('/').pop();
let lapath = config.data_dir + "avatars/" + afn;
if (!fs.existsSync(lapath)) {
try {
(await fetch(avatarURL)).body.pipe(fs.createWriteStream(lapath));
} catch (error) {
console.error("avatar download", error.message);
}
}
avatarURL = `${config.base_uri}/avatars/${afn}`
} else avatarURL = message.author.defaultAvatarURL;
var avatarURL = message.author.avatarURL({dynamic: true}) || message.author.defaultAvatarURL;
var avatarName = avatarURL.split('/').pop();
let imageCandidate = message.attachments.find(a => [".png",".jpg",".jpeg",".webp",".gif"].some(e => a.url.toLowerCase().endsWith(e)));
if (imageCandidate) imageCandidate["will be used for the image of the embed"] = true;
else imageCandidate = message.embeds.find(e => e.type == 'image');
let embed = new Discord.MessageEmbed()
.setAuthor(message.member?.displayName || message.author.username, avatarURL)
.setAuthor(message.member?.displayName || message.author.username, `attachment://${avatarName}`)
.setDescription(message.content)
.setImage(imageCandidate?.url)
.setFooter(`Pinned by ${message.guild.members.resolve(user)?.displayName || user.username}`)
@ -80,7 +67,11 @@ async function doThing(message, user) {
.setColor(message.member?.roles.color?.color);
let attachments = message.attachments.filter(a => !a["will be used for the image of the embed"]).map(a => `[${a.name}](${a.url})`).join('\n');
if (attachments) embed.addField("Attachments", attachments);
return (await client.channels.fetch(config.archive_channel))?.send({content: `https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`, embeds:[embed]});
return (await client.channels.fetch(config.archive_channel))?.send({
content: `https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`,
files: [{attachment: avatarURL, name: avatarName}],
embeds:[embed]
});
}