feat: add SST
This commit is contained in:
1 parent
51093da660
commit
bfd16ab02c
11 files changed
+196
-4
No files matched your search
@@ -3,6 +3,8 @@ from pyrogram.types import Message
|
||||
from userbot import PyroClient
|
||||
from userbot.modules.capture import capture_message
|
||||
from userbot.modules.capture.chat_meta import meta_from_chat
|
||||
from userbot.modules.stt import is_transcribable
|
||||
from userbot.modules.stt.gate import safe_transcribe
|
||||
|
||||
|
||||
@PyroClient.on_message()
|
||||
@@ -15,6 +17,12 @@ async def on_message(client: PyroClient, message: Message) -> None:
|
||||
if not toggles.messages:
|
||||
return
|
||||
await capture_message(client, message, ctx, toggles)
|
||||
if (
|
||||
toggles.stt
|
||||
and is_transcribable(message)
|
||||
and (message.outgoing or message.unread_media is False)
|
||||
):
|
||||
await safe_transcribe(client, ctx, meta.chat_id, message.id)
|
||||
|
||||
|
||||
handlers = on_message.handlers
|
||||
@@ -3,11 +3,17 @@ from collections.abc import Awaitable, Callable
|
||||
from pyrogram import raw
|
||||
|
||||
from userbot import PyroClient
|
||||
from userbot.handlers.raw import contacts, dialog_filters, reactions
|
||||
from userbot.handlers.raw import (
|
||||
contacts,
|
||||
dialog_filters,
|
||||
reactions,
|
||||
read_contents,
|
||||
transcribed,
|
||||
)
|
||||
|
||||
RawHandler = Callable[..., Awaitable[None]]
|
||||
|
||||
_MODULES = (contacts, dialog_filters, reactions)
|
||||
_MODULES = (contacts, dialog_filters, reactions, read_contents, transcribed)
|
||||
_REGISTRY: dict[type, RawHandler] = {
|
||||
update_type: module.handle for module in _MODULES for update_type in module.HANDLES
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from pyrogram import raw, utils
|
||||
|
||||
from userbot import PyroClient
|
||||
from userbot.modules.capture.chat_meta import meta_from_chat_id
|
||||
from userbot.modules.stt import repository
|
||||
from userbot.modules.stt.gate import safe_transcribe
|
||||
|
||||
HANDLES = (
|
||||
raw.types.UpdateReadMessagesContents,
|
||||
raw.types.UpdateChannelReadMessagesContents,
|
||||
)
|
||||
|
||||
|
||||
async def handle(
|
||||
client: PyroClient, update: raw.base.Update, _users: dict, _chats: dict
|
||||
) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None:
|
||||
return
|
||||
if isinstance(update, raw.types.UpdateChannelReadMessagesContents):
|
||||
chat_id = utils.get_peer_id(raw.types.PeerChannel(channel_id=update.channel_id))
|
||||
candidates = await repository.pending_voice_reads(
|
||||
ctx.pool, ctx.account_id, update.messages, chat_id=chat_id
|
||||
)
|
||||
elif isinstance(update, raw.types.UpdateReadMessagesContents):
|
||||
candidates = await repository.pending_voice_reads(
|
||||
ctx.pool, ctx.account_id, update.messages
|
||||
)
|
||||
else:
|
||||
return
|
||||
for cand_chat_id, message_id in candidates:
|
||||
meta = meta_from_chat_id(cand_chat_id, ctx.contacts.ids)
|
||||
if ctx.resolve(meta).stt:
|
||||
await safe_transcribe(client, ctx, cand_chat_id, message_id)
|
||||
@@ -0,0 +1,22 @@
|
||||
from pyrogram import raw
|
||||
|
||||
from userbot import PyroClient
|
||||
from userbot.modules.capture.chat_meta import meta_from_peer
|
||||
from userbot.modules.stt import repository
|
||||
|
||||
HANDLES = (raw.types.UpdateTranscribedAudio,)
|
||||
|
||||
|
||||
async def handle(
|
||||
client: PyroClient,
|
||||
update: raw.types.UpdateTranscribedAudio,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None or not update.text:
|
||||
return
|
||||
meta = meta_from_peer(update.peer, chats, users, ctx.contacts.ids)
|
||||
await repository.set_extracted_text(
|
||||
ctx.pool, ctx.account_id, meta.chat_id, update.msg_id, update.text
|
||||
)
|
||||
Reference in new issue
Block a user