Compare commits
2 commits
2cf8260a9c
...
e1b16065b0
| Author | SHA1 | Date | |
|---|---|---|---|
| e1b16065b0 | |||
| bd825c5104 |
2 changed files with 78 additions and 4 deletions
75
src/modules/utility/cache.js
Normal file
75
src/modules/utility/cache.js
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
const {readFile} = require("node:fs/promises");
|
||||||
|
|
||||||
|
const Command = require("#lib/command.js");
|
||||||
|
|
||||||
|
const {APIEndpoints} = require("#util/dconstants.js");
|
||||||
|
const {Icons} = require("#util/constants.js");
|
||||||
|
|
||||||
|
const cache = new Command("cache");
|
||||||
|
cache.category = "utility";
|
||||||
|
cache.helpText = "Cache a user to your client from their ID";
|
||||||
|
cache.usage = "<user id>";
|
||||||
|
cache.callback = async function (msg, id) {
|
||||||
|
if (id == msg.author?.id ?? msg.user?.id) return "Can't cache yourself.";
|
||||||
|
|
||||||
|
try {
|
||||||
|
await hf.bot.requestHandler.request("GET", APIEndpoints.USER(id), true);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code == 10013) {
|
||||||
|
return "User not found.";
|
||||||
|
} else {
|
||||||
|
return `${Icons.silk.error} Failed to validate user exists:\n\`\`\`\n${err}\`\`\``;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let member;
|
||||||
|
if (msg.guildID) {
|
||||||
|
const guild = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID);
|
||||||
|
member = guild?.members?.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member != null) {
|
||||||
|
return `"Cached" <@${id}>\n-# User is in this server silly`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const attachments = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const clip = {
|
||||||
|
is_clip: true,
|
||||||
|
clip_created_at: new Date().toISOString(),
|
||||||
|
clip_participant_ids: [id],
|
||||||
|
application_id: hf.bot.application?.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const video = await readFile(require.resolve("#root/data/clip.mp4"));
|
||||||
|
|
||||||
|
const {upload_url, upload_filename} = await hf.bot.requestHandler
|
||||||
|
.request("POST", APIEndpoints.MESSAGE_CREATE_ATTACHMENT_UPLOAD(msg.channel.id), true, {
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
file_size: video.length,
|
||||||
|
filename: "clip.mp4",
|
||||||
|
...clip,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((res) => res.attachments[0]);
|
||||||
|
|
||||||
|
await fetch(upload_url, {method: "PUT", body: video});
|
||||||
|
|
||||||
|
attachments.push({
|
||||||
|
filename: "clip.mp4",
|
||||||
|
uploaded_filename: upload_filename,
|
||||||
|
is_thumbnail: true,
|
||||||
|
...clip,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
return `${Icons.silk.error} Failed to create clip for caching:\n\`\`\`\n${err}\`\`\``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: `Cached <@${id}>`,
|
||||||
|
attachments,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -362,11 +362,10 @@ userinfo.callback = async function (msg, line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared = Array.from(hf.bot.guilds.values()).filter((g) => g.members.get(id) != null);
|
const shared = Array.from(hf.bot.guilds.values()).filter((g) => g.members.get(id) != null);
|
||||||
|
const displayName = user.global_name ?? user.username;
|
||||||
|
|
||||||
const descLines = [
|
const descLines = [
|
||||||
`# ${member?.nick ? member.nick : user.global_name ?? user.username} ${
|
`# ${member?.nick ? member.nick : displayName} ${user.bot ? Icons.boat.replace(":i:", ":Bot:") : ""}`,
|
||||||
user.bot ? Icons.boat.replace(":i:", ":Bot:") : ""
|
|
||||||
}`,
|
|
||||||
`${formatUsername(user).replace("@", "")} \u2022 <@${id}>`,
|
`${formatUsername(user).replace("@", "")} \u2022 <@${id}>`,
|
||||||
];
|
];
|
||||||
let subline = "";
|
let subline = "";
|
||||||
|
|
@ -449,7 +448,7 @@ userinfo.callback = async function (msg, line) {
|
||||||
name: user.primary_guild.tag,
|
name: user.primary_guild.tag,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
title: member?.nick ? user.global_name ?? user.username : null,
|
title: member?.nick && member.nick !== displayName ? displayName : null,
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
url: guildAvatar || avatar,
|
url: guildAvatar || avatar,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue