Skip to content

Commit

Permalink
0.30.0
Browse files Browse the repository at this point in the history
update emoj-db
new contet types
small fix and changes
  • Loading branch information
LyoSU committed Nov 7, 2021
1 parent c662628 commit e44f2f8
Show file tree
Hide file tree
Showing 5 changed files with 4,891 additions and 718 deletions.
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

7 changes: 7 additions & 0 deletions handlers/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ module.exports = async (ctx, next) => {
message.media = [quoteMessage.sticker]
message.mediaType = 'sticker'
}
if (flag.media && (quoteMessage.animation || quoteMessage.video)) {
const { thumbnail } = quoteMessage.animation || quoteMessage.video
message.media = [thumbnail]
}
if (flag.media && quoteMessage.voice) {
message.voice = quoteMessage.voice
}

if (messageFrom.id) {
message.chatId = messageFrom.id
Expand Down
51 changes: 48 additions & 3 deletions helpers/tdlib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ function getChat (chatID) {
})
}

function decodeWaveform (wf) {
const bitsCount = wf.length * 8
const valuesCount = ~~(bitsCount / 5)

if (!valuesCount) return []

const lastIdx = valuesCount - 1

const result = []
for (let i = 0, j = 0; i < lastIdx; i++, j += 5) {
const byteIdx = ~~(j / 8)
const bitShift = j % 8
result[i] = (wf.readUInt16LE(byteIdx) >> bitShift) & 0b11111
}

const lastByteIdx = ~~((lastIdx * 5) / 8)
const lastBitShift = (lastIdx * 5) % 8
const lastValue =
lastByteIdx === wf.length - 1
? wf[lastByteIdx]
: wf.readUInt16LE(lastByteIdx)
result[lastIdx] = (lastValue >> lastBitShift) & 0b11111

return result
}

function getMessages (chatID, messageIds) {
const tdlibMessageIds = messageIds.map((id) => id * Math.pow(2, 20))

Expand Down Expand Up @@ -195,15 +221,25 @@ function getMessages (chatID, messageIds) {
if (messageInfo.content) {
const mediaType = {
messagePhoto: 'photo',
messageSticker: 'sticker'
// messageVideo: 'video'
messageSticker: 'sticker',
messageVoiceNote: 'voice',
messageVideo: 'video',
messageAnimation: 'animation'
}

const type = mediaType[messageInfo.content._]

if (type) {
let media
if (messageInfo.content[type].sizes) {
if (messageInfo.content.voice_note) {
const { voice_note } = messageInfo.content
const waveform = decodeWaveform(Buffer.from(voice_note.waveform, 'base64'))

media = {
file_id: voice_note.voice.remote.id,
waveform
}
} else if (messageInfo.content[type].sizes) {
media = messageInfo.content[type].sizes.map((size) => {
return {
file_id: size[type].remote.id,
Expand All @@ -213,6 +249,15 @@ function getMessages (chatID, messageIds) {
width: size.width
}
})
} else if (messageInfo.content[type].thumbnail) {
const { file } = messageInfo.content[type].thumbnail
media = {
thumbnail: {
file_id: file.remote.id,
file_unique_id: file.remote.unique_id,
file_size: file.size
}
}
} else {
media = {
file_id: messageInfo.content[type][type].remote.id,
Expand Down
Loading

0 comments on commit e44f2f8

Please sign in to comment.