major cleanup

This commit is contained in:
derpystuff 2023-11-04 17:29:06 +01:00
parent ddd918470e
commit a8cf49e31e
60 changed files with 537 additions and 619 deletions

View file

@ -19,25 +19,23 @@ module.exports = {
run: async (context) => {
context.triggerTyping();
let image = await getRecentImage(context, 50)
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
let label = await googleVisionLabels(context, image)
let labels = []
for(const l of label.response.body.labels){
labels.push(smallPill(`${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`) + ' ' + pill(l.name))
for (const l of label.response.body.labels) {
labels.push(smallPill(`${l.score.toString().substr(2, 2)}.${l.score.toString().substr(3, 1)}%`) + ' ' + pill(l.name))
}
return editOrReply(context, {
embeds: [createEmbed("default", context, {
description: labels.join('\n'),
thumbnail: {
url: image
},
footer: {
iconUrl: STATICS.google,
text: `Google Cloud Vision • ${context.application.name}`
}
})]
})
return editOrReply(context, createEmbed("default", context, {
description: labels.join('\n'),
thumbnail: {
url: image
},
footer: {
iconUrl: STATICS.google,
text: `Google Cloud Vision • ${context.application.name}`
}
}))
},
};

View file

@ -2,7 +2,7 @@ const { googleVisionSafetyLabels } = require("../../../labscore/api");
const { GOOGLE_CLOUD_SAFETY_LABELS, GOOGLE_CLOUD_SAFETY_LABELS_NAMES } = require("../../../labscore/constants");
const { getRecentImage } = require("../../../labscore/utils/attachment");
const { createEmbed } = require("../../../labscore/utils/embed");
const { pill, iconPill, smallPill } = require("../../../labscore/utils/markdown");
const { iconPill, smallPill } = require("../../../labscore/utils/markdown");
const { editOrReply } = require("../../../labscore/utils/message");
const { STATICS } = require("../../../labscore/utils/statics");
@ -20,29 +20,27 @@ module.exports = {
run: async (context) => {
context.triggerTyping();
let image = await getRecentImage(context, 50)
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
let label = await googleVisionSafetyLabels(context, image)
let labels = []
for(const l of Object.keys(label.response.body.labels)){
for (const l of Object.keys(label.response.body.labels)) {
let rating = GOOGLE_CLOUD_SAFETY_LABELS[label.response.body.labels[l]]
labels.push([
smallPill(GOOGLE_CLOUD_SAFETY_LABELS_NAMES[l]),
iconPill(rating.icon, rating.name)
].join(' '))
}
return editOrReply(context, {
embeds: [createEmbed("default", context, {
description: labels.join('\n'),
thumbnail: {
url: image
},
footer: {
iconUrl: STATICS.google,
text: `Google Cloud Vision • ${context.application.name}`
}
})]
})
return editOrReply(context, createEmbed("default", context, {
description: labels.join('\n'),
thumbnail: {
url: image
},
footer: {
iconUrl: STATICS.google,
text: `Google Cloud Vision • ${context.application.name}`
}
}))
},
};

View file

@ -20,17 +20,17 @@ module.exports = {
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY, Permissions.READ_MESSAGE_HISTORY],
run: async (context) => {
context.triggerTyping();
if (!context.message.messageReference) return editOrReply(context, { embeds: [createEmbed("warning", context, "You need to reply to a voice message.")] })
if (!context.message.messageReference) return editOrReply(context, createEmbed("warning", context, "You need to reply to a voice message."))
try {
let msg;
try {
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
} catch (e) {
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to fetch message.")] })
return editOrReply(context, createEmbed("error", context, "Unable to fetch message."))
}
if(!msg.attachments.first()) return editOrReply(context, { embeds: [createEmbed("warning", context, "No voice message found.")] })
if(!msg.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, { embeds: [createEmbed("warning", context, "No voice message found.")] })
if(!msg.attachments.first()) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
if(!msg.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
const recog = await googleSpeechRecognition(context, msg.attachments.first().url)
@ -44,8 +44,8 @@ module.exports = {
} catch (e) {
console.log(e)
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {embeds:[createEmbed("warning", context, e.response.body.message)]})
return editOrReply(context, { embeds: [createEmbed("error", context, `Unable to transcribe audio.`)] })
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
return editOrReply(context, createEmbed("error", context, `Unable to transcribe audio.`))
}
},
};