Merge pull request #29 from EBendinelli/master
Adding Nitter support to replace Twitter links
This commit is contained in:
commit
cdbe2b2f5b
3 changed files with 10 additions and 21 deletions
|
@ -80,7 +80,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
|
||||
|
|
|
@ -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 )]
|
||||
|
|
|
@ -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;d<goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length;d++)c=goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[d],Object.prototype.hasOwnProperty.call(b,c)&&(a[c]=b[c])};goog.tagUnsealableClass=function(a){!COMPILED&&goog.defineClass.SEAL_CLASS_INSTANCES&&(a.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_]=!0)};goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_="goog_defineClass_legacy_unsealable";
|
||||
goog.createRequiresTranspilation_=function(){function a(a,b){d?c[a]=!0:b()?c[a]=!1:d=c[a]=!0}function b(a){try{return!!eval(a)}catch(g){return!1}}var c={es3:!1},d=!1,e=goog.global.navigator&&goog.global.navigator.userAgent?goog.global.navigator.userAgent:"";a("es5",function(){return b("[1,].length\x3d\x3d1")});a("es6",function(){var a=e.match(/Edge\/(\d+)(\.\d)*/i);return a&&15>Number(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<c.length;)d+=c.shift()+e.shift();return d+c.join("%s")};goog.string.collapseWhitespace=function(a){return a.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,"")};
|
||||
goog.string.isEmptyOrWhitespace=function(a){return/^[\s\xa0]*$/.test(a)};goog.string.isEmptyString=function(a){return 0==a.length};goog.string.isEmpty=goog.string.isEmptyOrWhitespace;goog.string.isEmptyOrWhitespaceSafe=function(a){return goog.string.isEmptyOrWhitespace(goog.string.makeSafe(a))};goog.string.isEmptySafe=goog.string.isEmptyOrWhitespaceSafe;goog.string.isBreakingWhitespace=function(a){return!/[^\t\n\r ]/.test(a)};goog.string.isAlpha=function(a){return!/[^a-zA-Z]/.test(a)};
|
||||
goog.string.isNumeric=function(a){return!/[^0-9]/.test(a)};goog.string.isAlphaNumeric=function(a){return!/[^a-zA-Z0-9]/.test(a)};goog.string.isSpace=function(a){return" "==a};goog.string.isUnicodeChar=function(a){return 1==a.length&&" "<=a&&"~">=a||""<=a&&"<22>">=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<c){var d=cljs.core._nth.call(null,b,a),f=null!=d&&(d.cljs$lang$protocol_mask$partition0$&64||cljs.core.PROTOCOL_SENTINEL===d.cljs$core$ISeq$)?cljs.core.apply.call(null,cljs.core.hash_map,d):d;d=cljs.core.get.call(null,f,new cljs.core.Keyword(null,"title","title",636505583));var g=cljs.core.get.call(null,f,new cljs.core.Keyword(null,"isoDate","isoDate",1408241829)),h=cljs.core.get.call(null,f,new cljs.core.Keyword(null,"pubDate",
|
||||
"pubDate",1669529099));cljs.core.get.call(null,f,new cljs.core.Keyword(null,"content","content",15833224));f=cljs.core.get.call(null,f,new cljs.core.Keyword(null,"link","link",-1769163468));cljs.core.chunk_append.call(null,e,new cljs.core.PersistentArrayMap(null,2,[new cljs.core.Keyword(null,"created-at","created-at",-89248644),new Date(function(){var a=g;return cljs.core.truth_(a)?a:h}()),new cljs.core.Keyword(null,"text","text",-1790561697),[cljs.core.str.cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.trim_text.call(null,
|
||||
d)),"\n\n",cljs.core.str.cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.strip_utm.call(null,f))].join("")],null));a+=1}else return!0}()?cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,e),r.call(null,cljs.core.chunk_rest.call(null,a))):cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,e),null)}var f=cljs.core.first.call(null,a),g=null!=f&&(f.cljs$lang$protocol_mask$partition0$&64||cljs.core.PROTOCOL_SENTINEL===f.cljs$core$ISeq$)?cljs.core.apply.call(null,cljs.core.hash_map,f):f;f=
|
||||
cljs.core.get.call(null,g,new cljs.core.Keyword(null,"title","title",636505583));var h=cljs.core.get.call(null,g,new cljs.core.Keyword(null,"isoDate","isoDate",1408241829)),k=cljs.core.get.call(null,g,new cljs.core.Keyword(null,"pubDate","pubDate",1669529099));cljs.core.get.call(null,g,new cljs.core.Keyword(null,"content","content",15833224));g=cljs.core.get.call(null,g,new cljs.core.Keyword(null,"link","link",-1769163468));return cljs.core.cons.call(null,new cljs.core.PersistentArrayMap(null,2,[new cljs.core.Keyword(null,
|
||||
"created-at","created-at",-89248644),new Date(function(){var a=h;return cljs.core.truth_(a)?a:k}()),new cljs.core.Keyword(null,"text","text",-1790561697),[cljs.core.str.cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.trim_text.call(null,f)),"\n\n",cljs.core.str.cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.strip_utm.call(null,g))].join("")],null),r.call(null,cljs.core.rest.call(null,a)))}return null}}}(a,b,c),null,null)}}(b,c,d).call(null,(new cljs.core.Keyword(null,"items","items",1031954938)).cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.js__GT_edn.call(null,
|
||||
e)))}())}}(c,d,e))};mastodon_bot.core.twitter_client=function(a){try{return new mastodon_bot.core.node$module$twitter(cljs.core.clj__GT_js.call(null,a))}catch(b){if(b instanceof Error)return mastodon_bot.core.exit_with_error.call(null,["failed to connect to Twitter: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(b.message)].join(""));throw b;}};
|
||||
mastodon_bot.core.tumblr_client=function(a,b){try{return new mastodon_bot.core.node$module$tumblr.Blog(b,cljs.core.clj__GT_js.call(null,a))}catch(c){if(c instanceof Error)return a=c,mastodon_bot.core.exit_with_error.call(null,["failed to connect to Tumblr account ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(b),": ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(a.message)].join(""));throw c;}};
|
||||
mastodon_bot.core.get_mastodon_timeline.call(null,function(a){a=new Date((new cljs.core.Keyword(null,"created_at","created_at",1484050750)).cljs$core$IFn$_invoke$arity$1(cljs.core.first.call(null,a)));var b=(new cljs.core.Keyword(null,"twitter","twitter",-589267671)).cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.config);if(cljs.core.truth_(b)){var c=null!=b&&(b.cljs$lang$protocol_mask$partition0$&64||cljs.core.PROTOCOL_SENTINEL===b.cljs$core$ISeq$)?cljs.core.apply.call(null,cljs.core.hash_map,b):
|
||||
b,d=cljs.core.get.call(null,c,new cljs.core.Keyword(null,"access-keys","access-keys",1664175776)),e=cljs.core.get.call(null,c,new cljs.core.Keyword(null,"accounts","accounts",-935308676));b=cljs.core.get.call(null,c,new cljs.core.Keyword(null,"include-replies?","include-replies?",-938373857));c=cljs.core.get.call(null,c,new cljs.core.Keyword(null,"include-rts?","include-rts?",2144811844));d=mastodon_bot.core.twitter_client.call(null,d);e=cljs.core.seq.call(null,e);for(var f=null,g=0,h=0;;)if(h<g){var k=
|
||||
cljs.core._nth.call(null,f,h);d.get("statuses/user_timeline",{screen_name:k,tweet_mode:"extended",include_rts:cljs.core.boolean$.call(null,c),exclude_replies:!cljs.core.boolean$.call(null,b)},mastodon_bot.core.post_tweets.call(null,a));h+=1}else if(e=cljs.core.seq.call(null,e))f=e,cljs.core.chunked_seq_QMARK_.call(null,f)?(e=cljs.core.chunk_first.call(null,f),h=cljs.core.chunk_rest.call(null,f),f=e,g=cljs.core.count.call(null,e),e=h):(e=cljs.core.first.call(null,f),d.get("statuses/user_timeline",
|
||||
{screen_name:e,tweet_mode:"extended",include_rts:cljs.core.boolean$.call(null,c),exclude_replies:!cljs.core.boolean$.call(null,b)},mastodon_bot.core.post_tweets.call(null,a)),e=cljs.core.next.call(null,f),f=null,g=0),h=0;else break}b=(new cljs.core.Keyword(null,"tumblr","tumblr",-1000454820)).cljs$core$IFn$_invoke$arity$1(mastodon_bot.core.config);if(cljs.core.truth_(b))for(d=null!=b&&(b.cljs$lang$protocol_mask$partition0$&64||cljs.core.PROTOCOL_SENTINEL===b.cljs$core$ISeq$)?cljs.core.apply.call(null,
|
||||
cljs.core.hash_map,b):b,b=cljs.core.get.call(null,d,new cljs.core.Keyword(null,"access-keys","access-keys",1664175776)),e=cljs.core.get.call(null,d,new cljs.core.Keyword(null,"accounts","accounts",-935308676)),c=cljs.core.get.call(null,d,new cljs.core.Keyword(null,"limit","limit",-1355822363)),cljs.core.get.call(null,d,new cljs.core.Keyword(null,"tumblr-oauth","tumblr-oauth",-1540343415)),d=cljs.core.seq.call(null,e),e=null,g=f=0;;)if(g<f)h=cljs.core._nth.call(null,e,g),mastodon_bot.core.tumblr_client.call(null,
|
||||
b,h).posts({limit:cljs.core.truth_(c)?c:5},mastodon_bot.core.post_tumblrs.call(null,a)),g+=1;else if(d=cljs.core.seq.call(null,d))e=d,cljs.core.chunked_seq_QMARK_.call(null,e)?(d=cljs.core.chunk_first.call(null,e),g=cljs.core.chunk_rest.call(null,e),e=d,f=cljs.core.count.call(null,d),d=g):(d=cljs.core.first.call(null,e),mastodon_bot.core.tumblr_client.call(null,b,d).posts({limit:cljs.core.truth_(c)?c:5},mastodon_bot.core.post_tumblrs.call(null,a)),d=cljs.core.next.call(null,e),e=null,f=0),g=0;else break;
|
||||
b=mastodon_bot.core.config;c=null==b?null:(new cljs.core.Keyword(null,"rss","rss",-1401556502)).cljs$core$IFn$_invoke$arity$1(b);if(cljs.core.truth_(c))for(b=new mastodon_bot.core.node$module$rss_parser,c=cljs.core.seq.call(null,c),d=null,g=f=0;;)if(g<f)e=cljs.core._nth.call(null,d,g),mastodon_bot.core.parse_feed.call(null,a,b,e),g+=1;else if(c=cljs.core.seq.call(null,c))d=c,cljs.core.chunked_seq_QMARK_.call(null,d)?(c=cljs.core.chunk_first.call(null,d),f=cljs.core.chunk_rest.call(null,d),d=c,e=cljs.core.count.call(null,
|
||||
c),c=f,f=e):(e=cljs.core.first.call(null,d),mastodon_bot.core.parse_feed.call(null,a,b,e),c=cljs.core.next.call(null,d),d=null,f=0),g=0;else return null;else return null});cljs.nodejs={};cljs.nodejs.require=require;cljs.nodejs.process=process;
|
||||
cljs.nodejs.enable_util_print_BANG_=function(){cljs.core._STAR_print_newline_STAR_=!1;cljs.core.set_print_fn_BANG_.call(null,function(){var a=function(a){return console.log.apply(console,cljs.core.into_array.call(null,a))},b=function(b){var c=null;if(0<arguments.length){c=0;for(var e=Array(arguments.length-0);c<e.length;)e[c]=arguments[c+0],++c;c=new cljs.core.IndexedSeq(e,0,null)}return a.call(this,c)};b.cljs$lang$maxFixedArity=0;b.cljs$lang$applyTo=function(b){b=cljs.core.seq(b);return a(b)};b.cljs$core$IFn$_invoke$arity$variadic=
|
||||
a;return b}());cljs.core.set_print_err_fn_BANG_.call(null,function(){var a=function(a){return console.error.apply(console,cljs.core.into_array.call(null,a))},b=function(b){var c=null;if(0<arguments.length){c=0;for(var e=Array(arguments.length-0);c<e.length;)e[c]=arguments[c+0],++c;c=new cljs.core.IndexedSeq(e,0,null)}return a.call(this,c)};b.cljs$lang$maxFixedArity=0;b.cljs$lang$applyTo=function(b){b=cljs.core.seq(b);return a(b)};b.cljs$core$IFn$_invoke$arity$variadic=a;return b}());return null};cljs.nodejscli={};COMPILED&&(goog.global=global);cljs.core.fn_QMARK_.call(null,cljs.core._STAR_main_cli_fn_STAR_)&&cljs.core.apply.call(null,cljs.core._STAR_main_cli_fn_STAR_,cljs.core.drop.call(null,2,goog.object.get(process,"argv")));
|
||||
"pubDate",1669529099));cljs.core.get.ca
|
Reference in a new issue