mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-24 05:47:02 -04:00
a lot of thingssss
This commit is contained in:
parent
eb0ba140f3
commit
726861294b
14 changed files with 420 additions and 24 deletions
57
labscore/utils/attachment.js
Normal file
57
labscore/utils/attachment.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
|
||||
|
||||
const attachmentTypes = Object.freeze({
|
||||
image: ["image/png", "image/jpeg", "image/gif"]
|
||||
})
|
||||
|
||||
async function getRecentMedia(context, limit){
|
||||
if (!context.message.channel) {
|
||||
return undefined;
|
||||
} else if (context.message.attachments.length > 0) {
|
||||
return context.message.attachments.first();
|
||||
}
|
||||
const messages = await context.message.channel.fetchMessages({
|
||||
limit
|
||||
});
|
||||
|
||||
if (!messages) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let attachments = [];
|
||||
for(const m of messages){
|
||||
let message = m[1]
|
||||
if ( // First the attachment on the message
|
||||
message.attachments.first()
|
||||
) { attachments.push(message.attachments.first())
|
||||
} else if ( // Then the embed image
|
||||
message.embeds.length > 0 &&
|
||||
message.embeds.toArray()[0].image
|
||||
) { attachments.push(message.embeds.toArray()[0].image)
|
||||
} else if (
|
||||
message.embeds.length > 0 &&
|
||||
message.embeds.toArray()[0].thumbnail
|
||||
) { attachments.push(message.embeds.toArray()[0].thumbnail) }
|
||||
}
|
||||
return attachments;
|
||||
}
|
||||
|
||||
// simple helpers
|
||||
|
||||
async function getRecentImage(context, limit){
|
||||
let attachments = await getRecentMedia(context, limit)
|
||||
let at;
|
||||
let validImages = attachmentTypes.image
|
||||
for(const a of attachments){
|
||||
if(a.contentType && validImages.includes(a.contentType) && at === undefined){ // discord attachment
|
||||
at = a.url
|
||||
} else if (!a.content_type && at === undefined){ // other form of media
|
||||
at = a.url
|
||||
}
|
||||
}
|
||||
return at;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getRecentImage
|
||||
}
|
|
@ -21,6 +21,10 @@ const Statics = Object.freeze({
|
|||
wolframalpha: {
|
||||
file: "brands/wolframalpha.png",
|
||||
revision: 0
|
||||
},
|
||||
inferkit: {
|
||||
file: "brands/inferkit.png",
|
||||
revision: 0
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -34,5 +38,6 @@ module.exports.STATICS = Object.freeze({
|
|||
genius: staticAsset(Statics.brands.genius),
|
||||
bing: staticAsset(Statics.brands.bing),
|
||||
google: staticAsset(Statics.brands.google),
|
||||
wolframalpha: staticAsset(Statics.brands.wolframalpha)
|
||||
wolframalpha: staticAsset(Statics.brands.wolframalpha),
|
||||
inferkit: staticAsset(Statics.brands.inferkit)
|
||||
})
|
28
labscore/utils/users.js
Normal file
28
labscore/utils/users.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
async function getUser(context, query){
|
||||
let user;
|
||||
if(/[0-9]{18}/.test(query)){ // User ID supplied, use that
|
||||
let uid = query.match(/[0-9]{18}/)
|
||||
try{
|
||||
user = await context.client.rest.fetchUser(uid)
|
||||
} catch(e){
|
||||
user = undefined
|
||||
}
|
||||
} else {
|
||||
user = await getMember(context, query)
|
||||
if(user) user = user.user
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
async function getMember(context, query){
|
||||
if(!context.guild) return;
|
||||
let members = await context.guild.fetchMembersSearch({ query })
|
||||
console.log(members)
|
||||
if(members) return members.first()
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getUser,
|
||||
getMember
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue