Fix updates, show more info
This commit is contained in:
parent
380896a0ce
commit
587a68898a
37
bot.own
37
bot.own
@ -12,11 +12,13 @@ lastUpdateId = -1
|
|||||||
while true {
|
while true {
|
||||||
sleep(6200)
|
sleep(6200)
|
||||||
updates = bot.getUpdatesSync(lastUpdateId + 1, 50, 58)
|
updates = bot.getUpdatesSync(lastUpdateId + 1, 50, 58)
|
||||||
|
println updates
|
||||||
if (updates.isEmpty()) continue
|
if (updates.isEmpty()) continue
|
||||||
|
|
||||||
lastUpdateId = stream(updates)
|
for update : updates {
|
||||||
.map(::processUpdate)
|
lastUpdateId = update.update_id
|
||||||
.reduce(0, def(a, b) = a + b)
|
processUpdate(update)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Confirm updates
|
// Confirm updates
|
||||||
bot.getUpdatesSync(lastUpdateId + 1, 1, 10)
|
bot.getUpdatesSync(lastUpdateId + 1, 1, 10)
|
||||||
@ -27,22 +29,18 @@ thread(def() {
|
|||||||
|
|
||||||
|
|
||||||
def processUpdate(update) {
|
def processUpdate(update) {
|
||||||
if !arrayKeyExists("message", update) {
|
if !arrayKeyExists("message", update) return 0
|
||||||
return update.update_id
|
|
||||||
}
|
|
||||||
msg = update.message
|
msg = update.message
|
||||||
text = msg.text ?? ""
|
text = msg.text ?? ""
|
||||||
if text.isEmpty() {
|
if text.isEmpty() return 0
|
||||||
return update.update_id
|
|
||||||
}
|
|
||||||
m = DANBOORU_REGEX.matcher(text)
|
m = DANBOORU_REGEX.matcher(text)
|
||||||
while m.find() {
|
while m.find() {
|
||||||
processPost(m.group(1), msg.chat.id, msg.message_id)
|
processPost(m.group(1), msg.chat.id, msg.message_id, msg.from)
|
||||||
|
sleep(2000)
|
||||||
}
|
}
|
||||||
return update.update_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def processPost(id, chatId, msgId) {
|
def processPost(id, chatId, msgId, from) {
|
||||||
post = api.getPost(id)
|
post = api.getPost(id)
|
||||||
url = "https://danbooru.donmai.us/posts/" + id
|
url = "https://danbooru.donmai.us/posts/" + id
|
||||||
println "%s: %s".sprintf(newDate(), url)
|
println "%s: %s".sprintf(newDate(), url)
|
||||||
@ -51,21 +49,30 @@ def processPost(id, chatId, msgId) {
|
|||||||
if post.containsTags(blacklistTags) return 0
|
if post.containsTags(blacklistTags) return 0
|
||||||
|
|
||||||
caption = getCaption(post)
|
caption = getCaption(post)
|
||||||
reply = jsonencode({"message_id": msgId, "chat_id": chatId})
|
sender = ""
|
||||||
|
if (from.id != chatId) sender = from.first_name + " "
|
||||||
|
buttonText = sprintf("%s%s 📈%d", sender, post.getResolution(), post.getScore())
|
||||||
|
markup = jsonencode({"inline_keyboard": [
|
||||||
|
[{"text":buttonText, "url":url}]
|
||||||
|
]})
|
||||||
bot.invoke("sendPhoto", {
|
bot.invoke("sendPhoto", {
|
||||||
"chat_id": chatId,
|
"chat_id": chatId,
|
||||||
"reply_parameters": reply,
|
|
||||||
"photo": post.getImageUrl(),
|
"photo": post.getImageUrl(),
|
||||||
"parse_mode": "html",
|
"parse_mode": "html",
|
||||||
"caption": caption,
|
"caption": caption,
|
||||||
|
"reply_markup": markup
|
||||||
}, def(r) {
|
}, def(r) {
|
||||||
|
bot.invoke("deleteMessage", {
|
||||||
|
"chat_id": chatId,
|
||||||
|
"message_id": msgId,
|
||||||
|
}, def(r) = 1)
|
||||||
if !r.contains("wrong file identifier") return 1
|
if !r.contains("wrong file identifier") return 1
|
||||||
bot.invoke("sendPhoto", {
|
bot.invoke("sendPhoto", {
|
||||||
"chat_id": chatId,
|
"chat_id": chatId,
|
||||||
"reply_parameters": reply,
|
|
||||||
"photo": post.getSampleImageUrl(),
|
"photo": post.getSampleImageUrl(),
|
||||||
"parse_mode": "html",
|
"parse_mode": "html",
|
||||||
"caption": "small " + caption,
|
"caption": "small " + caption,
|
||||||
|
"reply_markup": markup
|
||||||
}, def(r) = 1)
|
}, def(r) = 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user