mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
support user context tcr
This commit is contained in:
parent
1292ae58b4
commit
a3ae9d819c
1 changed files with 63 additions and 0 deletions
63
commands/interaction/context/transcribe.js
Normal file
63
commands/interaction/context/transcribe.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
const { Constants } = require('detritus-client');
|
||||
const { InteractionCallbackTypes, ApplicationCommandTypes, MessageFlags } = Constants;
|
||||
|
||||
const { googleSpeechRecognitionWithLabels } = require('../../../labscore/api');
|
||||
|
||||
const { createEmbed } = require('../../../labscore/utils/embed');
|
||||
const { codeblock } = require('../../../labscore/utils/markdown');
|
||||
const { STATICS } = require('../../../labscore/utils/statics');
|
||||
const { editOrReply } = require('../../../labscore/utils/message');
|
||||
|
||||
module.exports = {
|
||||
name: 'Transcribe Voice Message',
|
||||
type: ApplicationCommandTypes.MESSAGE,
|
||||
contexts: [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
integrationTypes: [
|
||||
1
|
||||
],
|
||||
run: async (context, args) => {
|
||||
await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
||||
|
||||
try {
|
||||
const { message } = args;
|
||||
|
||||
if(!message.attachments.first()) return editOrReply(context, {
|
||||
embeds: [createEmbed("warning", context, "No voice message found.")],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
if(!message.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, {
|
||||
embeds: [createEmbed("warning", context, "No voice message found.")],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
const recog = await googleSpeechRecognitionWithLabels(context, message.attachments.first().url)
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: codeblock("md", [ recog.response.body.transcription_with_speakers ]),
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud • Confidence: ${(recog.response.body.confidence* 100).toFixed(1)}% • ${context.application.name}`
|
||||
}
|
||||
})],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
} 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)],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("error", context, "Unable to transcribe message.")],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue