utils: misc cleanup and fixes
This commit is contained in:
parent
4af91ad249
commit
9b86bbcabe
1 changed files with 21 additions and 11 deletions
|
@ -70,7 +70,9 @@ function readableTime(number) {
|
|||
}
|
||||
|
||||
async function isGif(url) {
|
||||
const type = await fetch(url).then((res) => res.headers.get("Content-Type"));
|
||||
const type = await fetch(url, {method: "HEAD"}).then((res) =>
|
||||
res.headers.get("Content-Type")
|
||||
);
|
||||
return type == "image/gif";
|
||||
}
|
||||
|
||||
|
@ -115,11 +117,11 @@ async function getImage(msg, str) {
|
|||
const attachments = [...refMsg.attachments.values()];
|
||||
if (attachments[0]?.url) {
|
||||
return attachments[0].url;
|
||||
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(refMsg.content)) {
|
||||
const id = refMsg.content.match(/<a?:[a-zA-Z0-9_]*:([0-9]*)>/)[1];
|
||||
} else if (/<a?:[a-zA-Z0-9_]+:([0-9]+)>/.test(refMsg.content)) {
|
||||
const id = refMsg.content.match(/<a?:[a-zA-Z0-9_]+:([0-9]+)>/)[1];
|
||||
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
|
||||
} else if (/<@!?([0-9]*)>/.test(refMsg.content)) {
|
||||
const id = refMsg.content.match(/<@!?([0-9]*)>/)[1];
|
||||
} else if (/<@!?([0-9]+)>/.test(refMsg.content)) {
|
||||
const id = refMsg.content.match(/<@!?([0-9]+)>/)[1];
|
||||
const user = await hf.bot.requestHandler.request(
|
||||
"GET",
|
||||
"/users/" + id,
|
||||
|
@ -140,11 +142,11 @@ async function getImage(msg, str) {
|
|||
return attachments[0]?.url;
|
||||
} else if (urlRegex.test(str)) {
|
||||
return str;
|
||||
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(str)) {
|
||||
const id = str.match(/<a?:[a-zA-Z0-9_]*:([0-9]*)>/)[1];
|
||||
} else if (/<a?:[a-zA-Z0-9_]+:([0-9]+)>/.test(str)) {
|
||||
const id = str.match(/<a?:[a-zA-Z0-9_]+:([0-9]+)>/)[1];
|
||||
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
|
||||
} else if (/<@!?([0-9]*)>/.test(str)) {
|
||||
const id = str.match(/<@!?([0-9]*)>/)[1];
|
||||
} else if (/<@!?([0-9]+)>/.test(str)) {
|
||||
const id = str.match(/<@!?([0-9]+)>/)[1];
|
||||
const user = await hf.bot.requestHandler.request(
|
||||
"GET",
|
||||
"/users/" + id,
|
||||
|
@ -325,12 +327,20 @@ async function lookupUser(msg, str, filter) {
|
|||
return user;
|
||||
} else if (
|
||||
user.username.toLowerCase().indexOf(str.toLowerCase()) > -1 ||
|
||||
(user.nick && user.nick.indexOf(str.toLowerCase()) > -1)
|
||||
(user.nick && user.nick.toLowerCase().indexOf(str.toLowerCase()) > -1) ||
|
||||
(user.globalName &&
|
||||
user.globalName.toLowerCase().indexOf(str.toLowerCase()) > -1)
|
||||
) {
|
||||
selection.push({
|
||||
value: user,
|
||||
key: user.id,
|
||||
display: `${formatUsername(user)}${user.nick ? ` (${user.nick})` : ""}`,
|
||||
display: `${formatUsername(user)}${
|
||||
user.nick
|
||||
? ` (${user.nick})`
|
||||
: user.globalName
|
||||
? ` (${user.globalName})`
|
||||
: ""
|
||||
}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue