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 RateLimiter = initTable[int64, seq[float]]()
|
||||||
|
|
||||||
|
var GroupMedia = initTable[int, string]()
|
||||||
|
|
||||||
let AdminID = getEnv("ADMIN_ID").split(",")
|
let AdminID = getEnv("ADMIN_ID").split(",")
|
||||||
|
|
||||||
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
|
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
|
||||||
|
@ -82,19 +84,27 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
||||||
else:
|
else:
|
||||||
var TempData = @[NewCensoredData()]
|
var TempData = @[NewCensoredData()]
|
||||||
dbConn.select(TempData, "fhash = ?", deeplink[1])
|
dbConn.select(TempData, "fhash = ?", deeplink[1])
|
||||||
for i in TempData:
|
if len(TempData) > 1:
|
||||||
if i.ftype == "photo":
|
var inputmedia = newSeq[InputMediaPhoto]()
|
||||||
discard await b.sendPhoto(response.chat.id, i.fileid, i.caption)
|
for i in TempData:
|
||||||
elif i.ftype == "document":
|
if i.caption != "":
|
||||||
discard await b.sendDocument(response.chat.id, i.fileid, i.caption)
|
inputmedia.insert(InputMediaPhoto(kind: i.ftype, media: i.fileid, caption: some(i.caption)))
|
||||||
elif i.ftype == "video":
|
else:
|
||||||
discard await b.sendVideo(response.chat.id, i.fileid, caption=i.caption)
|
inputmedia.insert(InputMediaPhoto(kind: i.ftype, media: i.fileid))
|
||||||
elif i.ftype == "videonote":
|
discard await b.sendMediaGroup($response.chat.id, media=inputmedia)
|
||||||
discard await b.sendVideoNote(response.chat.id, i.fileid)
|
else:
|
||||||
elif i.ftype == "animation":
|
if TempData[0].ftype == "photo":
|
||||||
discard await b.sendAnimation(response.chat.id, i.fileid, caption=i.caption)
|
discard await b.sendPhoto(response.chat.id, TempData[0].fileid, TempData[0].caption)
|
||||||
elif i.ftype == "sticker":
|
elif TempData[0].ftype == "document":
|
||||||
discard await b.sendSticker(response.chat.id, i.fileid)
|
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:
|
else:
|
||||||
var fileid = ""
|
var fileid = ""
|
||||||
var ftype = ""
|
var ftype = ""
|
||||||
|
@ -109,7 +119,7 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
||||||
ftype = "video"
|
ftype = "video"
|
||||||
elif response.videoNote.isSome:
|
elif response.videoNote.isSome:
|
||||||
fileid = response.videoNote.get.fileId
|
fileid = response.videoNote.get.fileId
|
||||||
ftype = "videonote"
|
ftype = "videoNote"
|
||||||
elif response.animation.isSome:
|
elif response.animation.isSome:
|
||||||
fileid = response.animation.get.fileId
|
fileid = response.animation.get.fileId
|
||||||
ftype = "animation"
|
ftype = "animation"
|
||||||
|
@ -120,14 +130,26 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
||||||
fileid = response.sticker.get.fileId
|
fileid = response.sticker.get.fileId
|
||||||
ftype = "sticker"
|
ftype = "sticker"
|
||||||
|
|
||||||
let filehash = generate_hash()
|
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
|
||||||
|
|
||||||
var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption)
|
else:
|
||||||
|
let filehash = generate_hash()
|
||||||
with dbConn:
|
var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption)
|
||||||
insert CensoredRow
|
with dbConn:
|
||||||
|
insert CensoredRow
|
||||||
discard await b.sendMessage(response.chat.id, "Censored --> " & "tg://resolve?domain=botbotbotnotabot&start=" & filehash)
|
discard await b.sendMessage(response.chat.id, "Censored --> " & "tg://resolve?domain=botbotbotnotabot&start=" & filehash)
|
||||||
|
|
||||||
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
|
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
|
||||||
bot.onUpdate(updateHandler)
|
bot.onUpdate(updateHandler)
|
||||||
|
|
Loading…
Reference in a new issue