From 9160bb808e30d0572d49a1dca7825be260b537c2 Mon Sep 17 00:00:00 2001 From: mcneb10 Date: Mon, 24 Jun 2024 17:03:12 -0500 Subject: [PATCH] bug fixes --- config.lua | 10 +++++++--- main.lua | 15 ++++++++++++++- utils.lua | 23 ++++++++++++++++++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/config.lua b/config.lua index 24e8816..c651778 100644 --- a/config.lua +++ b/config.lua @@ -14,7 +14,8 @@ config = { ]]-- prefered_website_medium = "clearnet", -- Choose random frontend instead of fallback one, will force clearnet - random_frontend = true, + --random_frontend = true, + random_frontend = false, -- Reply using XEP-0461 instead of just quoting use_reply_xep = true, -- List of desired frontends to extract from `services.json` @@ -29,9 +30,12 @@ config = { ["instagram[.]com"] = { frontends = { "proxigram" } }, - ["github[.]com"] = { - frontends = { "gothub" } + ["www[.]instagram[.]com"] = { + frontends = { "proxigram" } }, + --[[["github[.]com"] = { + frontends = { "gothub" } + },]]-- ["google[.]com"] = { frontends = { "searxng" } }, diff --git a/main.lua b/main.lua index bf67618..1018c0a 100755 --- a/main.lua +++ b/main.lua @@ -35,9 +35,22 @@ client:hook("ready", function() room:hook("message", function(event) if event.stanza.attr.type == "groupchat" and not string.find(event.stanza.attr.from, "/" .. config.name) - and not event.stanza:get_child("delay", "urn:xmpp:delay") then + and not event.stanza:get_child("delay", "urn:xmpp:delay") + and not string.find(event.stanza.attr.from, "Bot") -- This is here because of the Thumbnail bot incident + then local body = event.stanza:get_child_text("body") if body then + if event.stanza:get_child("reply", 'urn:xmpp:reply:0') then + local fallback = event.stanza:get_child("fallback", 'urn:xmpp:fallback:0') + if fallback then + local fallback_body = fallback:child_with_name("body") + if fallback_body then + body = string.sub(body, fallback_body.attr["end"]) + end + end + else + body = string.gsub(body, ">[^\n\r]-[\n\r]+", "") + end for site, services in pairs(config.sites) do local instance = choose_instance(services) for match in string.gmatch(body, string.format("%%s(%s/%%S+)", site)) do diff --git a/utils.lua b/utils.lua index fefdadf..d0aeef0 100644 --- a/utils.lua +++ b/utils.lua @@ -42,7 +42,8 @@ function read_all_text(file) end function send_reply_link(room, match, site, instance, event) - local msg = string.format("> %s\nPrivate frontend: %s", match, string.gsub(match, site, instance)) + --local msg = string.format("> %s\nPrivate frontend: %s", match, string.gsub(match, site, instance)) + local msg = string.format("Private frontend: %s", string.gsub(match, site, instance)) if config.use_reply_xep then room:send(verse.message() -- Set message text @@ -51,8 +52,24 @@ function send_reply_link(room, match, site, instance, event) :tag("reply", { xmlns = 'urn:xmpp:reply:0', to = event.stanza.attr.from, - id = event.stanza.attr.id, - })) + id = event.stanza:get_child("stanza-id", "urn:xmpp:sid:0").attr.id, + }):up() + --[[Add fallback + :tag("fallback", { + ["xmlns"] = 'urn:xmpp:feature-fallback:0', + ["for"] = 'urn:xmpp:reply:0', + }) + :tag("body", { + ["start"] = 0, + ["end"] = string.len(match) + 2 + }):up():up() + ]]-- + -- Idk what this does, but it's in gajim's replies + :tag("markable", { + xmlns = "urn:xmpp:chat-markers:0" + }) + ) + else room:send_message(msg) end