Add support for albums
This was hard Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
b27f910362
commit
869820bc19
1 changed files with 43 additions and 21 deletions
|
@ -17,6 +17,8 @@ type
|
|||
|
||||
var RateLimiter = initTable[int64, seq[float]]()
|
||||
|
||||
var GroupMedia = initTable[int, string]()
|
||||
|
||||
let AdminID = getEnv("ADMIN_ID").split(",")
|
||||
|
||||
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
|
||||
|
@ -82,19 +84,27 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
|||
else:
|
||||
var TempData = @[NewCensoredData()]
|
||||
dbConn.select(TempData, "fhash = ?", deeplink[1])
|
||||
if len(TempData) > 1:
|
||||
var inputmedia = newSeq[InputMediaPhoto]()
|
||||
for i in TempData:
|
||||
if i.ftype == "photo":
|
||||
discard await b.sendPhoto(response.chat.id, i.fileid, i.caption)
|
||||
elif i.ftype == "document":
|
||||
discard await b.sendDocument(response.chat.id, i.fileid, i.caption)
|
||||
elif i.ftype == "video":
|
||||
discard await b.sendVideo(response.chat.id, i.fileid, caption=i.caption)
|
||||
elif i.ftype == "videonote":
|
||||
discard await b.sendVideoNote(response.chat.id, i.fileid)
|
||||
elif i.ftype == "animation":
|
||||
discard await b.sendAnimation(response.chat.id, i.fileid, caption=i.caption)
|
||||
elif i.ftype == "sticker":
|
||||
discard await b.sendSticker(response.chat.id, i.fileid)
|
||||
if i.caption != "":
|
||||
inputmedia.insert(InputMediaPhoto(kind: i.ftype, media: i.fileid, caption: some(i.caption)))
|
||||
else:
|
||||
inputmedia.insert(InputMediaPhoto(kind: i.ftype, media: i.fileid))
|
||||
discard await b.sendMediaGroup($response.chat.id, media=inputmedia)
|
||||
else:
|
||||
if TempData[0].ftype == "photo":
|
||||
discard await b.sendPhoto(response.chat.id, TempData[0].fileid, TempData[0].caption)
|
||||
elif TempData[0].ftype == "document":
|
||||
discard await b.sendDocument(response.chat.id, TempData[0].fileid, TempData[0].caption)
|
||||
elif TempData[0].ftype == "video":
|
||||
discard await b.sendVideo(response.chat.id, TempData[0].fileid, caption=TempData[0].caption)
|
||||
elif TempData[0].ftype == "videoNote":
|
||||
discard await b.sendVideoNote(response.chat.id, TempData[0].fileid)
|
||||
elif TempData[0].ftype == "animation":
|
||||
discard await b.sendAnimation(response.chat.id, TempData[0].fileid, caption=TempData[0].caption)
|
||||
elif TempData[0].ftype == "sticker":
|
||||
discard await b.sendSticker(response.chat.id, TempData[0].fileid)
|
||||
else:
|
||||
var fileid = ""
|
||||
var ftype = ""
|
||||
|
@ -109,7 +119,7 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
|||
ftype = "video"
|
||||
elif response.videoNote.isSome:
|
||||
fileid = response.videoNote.get.fileId
|
||||
ftype = "videonote"
|
||||
ftype = "videoNote"
|
||||
elif response.animation.isSome:
|
||||
fileid = response.animation.get.fileId
|
||||
ftype = "animation"
|
||||
|
@ -120,13 +130,25 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
|||
fileid = response.sticker.get.fileId
|
||||
ftype = "sticker"
|
||||
|
||||
if response.mediaGroupId.isSome:
|
||||
if parseInt(response.mediaGroupId.get) notin GroupMedia.keys().toSeq():
|
||||
let filehash = generate_hash()
|
||||
|
||||
GroupMedia[parseInt(response.mediaGroupId.get)] = filehash
|
||||
var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption)
|
||||
with dbConn:
|
||||
insert CensoredRow
|
||||
discard await b.sendMessage(response.chat.id, "Censored --> " & "tg://resolve?domain=botbotbotnotabot&start=" & filehash)
|
||||
else:
|
||||
let filehash = GroupMedia[parseInt(response.mediaGroupId.get)]
|
||||
var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption)
|
||||
|
||||
with dbConn:
|
||||
insert CensoredRow
|
||||
|
||||
else:
|
||||
let filehash = generate_hash()
|
||||
var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption)
|
||||
with dbConn:
|
||||
insert CensoredRow
|
||||
discard await b.sendMessage(response.chat.id, "Censored --> " & "tg://resolve?domain=botbotbotnotabot&start=" & filehash)
|
||||
|
||||
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
|
||||
|
|
Loading…
Reference in a new issue