From 4265b03c8cc7c654d1af34ee8a60359c621c883a Mon Sep 17 00:00:00 2001 From: Eliot Date: Wed, 15 Jan 2020 15:54:41 +0000 Subject: [PATCH 1/2] Adding support for nitter, replace twitter links by nitter links --- mastodon-bot.cljs | 8 +++++--- mastodon-bot.js | 19 ++----------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/mastodon-bot.cljs b/mastodon-bot.cljs index 6cfa7ed..0321e27 100755 --- a/mastodon-bot.cljs +++ b/mastodon-bot.cljs @@ -82,9 +82,11 @@ (def shortened-url-pattern #"(https?://)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?") (defn resolve-urls [text] - (if (:resolve-urls? mastodon-config) - (string/replace text shortened-url-pattern resolve-url) - text)) + (cond-> text + (:resolve-urls? mastodon-config) + (string/replace shortened-url-pattern resolve-url) + (:nitter-urls? mastodon-config) + (string/replace #"https://twitter.com" "https://nitter.net"))) (defn set-signature [text] (if-let [signature (:signature mastodon-config )] diff --git a/mastodon-bot.js b/mastodon-bot.js index dd255b7..aae866c 100644 --- a/mastodon-bot.js +++ b/mastodon-bot.js @@ -59,7 +59,7 @@ goog.defineClass=function(a,b){var c=b.constructor,d=b.statics;c&&c!=Object.prot goog.defineClass.createSealingConstructor_=function(a,b){if(!goog.defineClass.SEAL_CLASS_INSTANCES)return a;var c=!goog.defineClass.isUnsealable_(b),d=function(){var b=a.apply(this,arguments)||this;b[goog.UID_PROPERTY_]=b[goog.UID_PROPERTY_];this.constructor===d&&c&&Object.seal instanceof Function&&Object.seal(b);return b};return d};goog.defineClass.isUnsealable_=function(a){return a&&a.prototype&&a.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_]};goog.defineClass.OBJECT_PROTOTYPE_FIELDS_="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "); goog.defineClass.applyProperties_=function(a,b){for(var c in b)Object.prototype.hasOwnProperty.call(b,c)&&(a[c]=b[c]);for(var d=0;dNumber(a[1])?!1:b('(()\x3d\x3e{"use strict";class X{constructor(){if(new.target!\x3dString)throw 1;this.x\x3d42}}let q\x3dReflect.construct(X,[],String);if(q.x!\x3d42||!(q instanceof String))throw 1;for(const a of[2,3]){if(a\x3d\x3d2)continue;function f(z\x3d{a}){let a\x3d0;return z.a}{function f(){return 0;}}return f()\x3d\x3d3}})()')}); -a("es6-impl",function(){return!0});a("es7",function(){return b("2 ** 2 \x3d\x3d 4")});a("es8",function(){return b("async () \x3d\x3e 1, true")});return c};goog.string={};goog.string.DETECT_DOUBLE_ESCAPING=!1;goog.string.FORCE_NON_DOM_HTML_UNESCAPING=!1;goog.string.Unicode={NBSP:" "};goog.string.startsWith=function(a,b){return 0==a.lastIndexOf(b,0)};goog.string.endsWith=function(a,b){var c=a.length-b.length;return 0<=c&&a.indexOf(b,c)==c};goog.string.caseInsensitiveStartsWith=function(a,b){return 0==goog.string.caseInsensitiveCompare(b,a.substr(0,b.length))}; +a("es6-impl",function(){return!0});a("es7",function(){return b("2 ** 2 \x3d\x3d 4")});a("es8",function(){return b("async () \x3d\x3e 1, true")});return c};goog.string={};goog.string.DETECT_DOUBLE_ESCAPING=!1;goog.string.FORCE_NON_DOM_HTML_UNESCAPING=!1;goog.string.Unicode={NBSP:" "};goog.string.startsWith=function(a,b){return 0==a.lastIndexOf(b,0)};goog.string.endsWith=function(a,b){var c=a.length-b.length;return 0<=c&&a.indexOf(b,c)==c};goog.string.caseInsensitiveStartsWith=function(a,b){return 0==goog.string.caseInsensitiveCompare(b,a.substr(0,b.length))}; goog.string.caseInsensitiveEndsWith=function(a,b){return 0==goog.string.caseInsensitiveCompare(b,a.substr(a.length-b.length,b.length))};goog.string.caseInsensitiveEquals=function(a,b){return a.toLowerCase()==b.toLowerCase()};goog.string.subs=function(a,b){for(var c=a.split("%s"),d="",e=Array.prototype.slice.call(arguments,1);e.length&&1=a||"€"<=a&&"�">=a};goog.string.stripNewlines=function(a){return a.replace(/(\r\n|\r|\n)+/g," ")};goog.string.canonicalizeNewlines=function(a){return a.replace(/(\r\n|\r|\n)/g,"\n")};goog.string.normalizeWhitespace=function(a){return a.replace(/\xa0|\s/g," ")}; @@ -2551,19 +2551,4 @@ mastodon_bot.core.post_tumblrs=function(a){return function(b,c){return mastodon_ mastodon_bot.core.post_tweets=function(a){return function(b,c,d){return mastodon_bot.core.post_items.call(null,a,cljs.core.map.call(null,mastodon_bot.core.parse_tweet,mastodon_bot.core.js__GT_edn.call(null,c)))}};mastodon_bot.core.strip_utm=function(a){return cljs.core.first.call(null,clojure.string.split.call(null,a,/\?utm/))}; mastodon_bot.core.parse_feed=function(a,b,c){var d=cljs.core.nth.call(null,c,0,null),e=cljs.core.nth.call(null,c,1,null);return b.parseURL(e).then(function(b,c,d){return function(e){return mastodon_bot.core.post_items.call(null,a,function(){return function(a,b,c){return function r(d){return new cljs.core.LazySeq(null,function(a,b,c){return function(){for(;;){var a=cljs.core.seq.call(null,d);if(a){if(cljs.core.chunked_seq_QMARK_.call(null,a)){var b=cljs.core.chunk_first.call(null,a),c=cljs.core.count.call(null, b),e=cljs.core.chunk_buffer.call(null,c);return function(){for(var a=0;;)if(a Date: Wed, 15 Jan 2020 17:10:45 +0000 Subject: [PATCH 2/2] Updated config.edn in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25d2eae..b0f6882 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,9 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w :content-filters [".*bannedsite.*"] ;; optional keyword filter regexes ;; any posts not matching the regexes will be filtered out - :keyword-filters [".*clojure.*"]}} + :keyword-filters [".*clojure.*"] + ;; Replace Twitter links by Nitter + : nitter-urls? false}} ``` * the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument