enable spoilers & content warning crossposting
This commit is contained in:
parent
4fdd9f0634
commit
76970fe793
6 changed files with 37 additions and 5 deletions
|
@ -22,12 +22,14 @@ npm install
|
||||||
- Replace "API_KEY" on line 1 with the Access Token you retrieved in the previous step
|
- Replace "API_KEY" on line 1 with the Access Token you retrieved in the previous step
|
||||||
- Replace "API_URL" on line 2 with your Mastodon instance's API URL
|
- Replace "API_URL" on line 2 with your Mastodon instance's API URL
|
||||||
- This will look like "https://mastodon.social/api/v1/", replacing "mastodon.social" with the domain you registered your account through
|
- This will look like "https://mastodon.social/api/v1/", replacing "mastodon.social" with the domain you registered your account through
|
||||||
|
- Replace "CONTENT_WARNING_PREFIX" on line 3 with your preferred spoiler/content warning prefix if you plan to use this feature
|
||||||
|
- commonly used prefixes include "CW//", "TW//", and "SPOILER//"
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
node ./TwitToMast.js [-htqrpmbc] [-u username] [-n tweetcount] [-d debuglevel] [-w timeout]
|
node ./TwitToMast.js [-htqrspmbc] [-u username] [-n tweetcount] [-d debuglevel] [-w timeout]
|
||||||
node ./multi.js [-htqrpmbc] [-n tweetcount] [-d debuglevel] [-w timeout]
|
node ./multi.js [-htqrspmbc] [-n tweetcount] [-d debuglevel] [-w timeout]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
|
@ -44,6 +46,8 @@ node ./multi.js [-htqrpmbc] [-n tweetcount] [-d debuglevel] [-w timeout]
|
||||||
-q: - quote tweets will be included in the scan
|
-q: - quote tweets will be included in the scan
|
||||||
-r: - Link to quoted tweet will appear in the header, preceded by "re: "
|
-r: - Link to quoted tweet will appear in the header, preceded by "re: "
|
||||||
- default behavior posts link at bottom preceded by "Quoting "
|
- default behavior posts link at bottom preceded by "Quoting "
|
||||||
|
-s: - Enable content warning prefixes
|
||||||
|
- tweets beginning with a certain string (defined in config.txt) will use following text on the same line as Mastodon content warning
|
||||||
-p: - enable/disable posting to Mastodon
|
-p: - enable/disable posting to Mastodon
|
||||||
-m: - include user's name, handle, and link to tweet
|
-m: - include user's name, handle, and link to tweet
|
||||||
-b: - display browser (disable headless mode)
|
-b: - display browser (disable headless mode)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
API_KEY
|
API_KEY
|
||||||
API_URL
|
API_URL
|
||||||
|
CONTENT_WARNING_PREFIX
|
|
@ -15,6 +15,7 @@ class Args {
|
||||||
this.enableQuotes = this.getFlag("q"); //enable cross-posting quote tweets
|
this.enableQuotes = this.getFlag("q"); //enable cross-posting quote tweets
|
||||||
this.enableThreads = this.getFlag("t"); //enable cross-posting thread tweets
|
this.enableThreads = this.getFlag("t"); //enable cross-posting thread tweets
|
||||||
this.reQuotes = this.getFlag("r"); //put links to quote tweets at top of mastodon posts
|
this.reQuotes = this.getFlag("r"); //put links to quote tweets at top of mastodon posts
|
||||||
|
this.warnings = this.getFlag("s");
|
||||||
|
|
||||||
var userNamePreFormat = this.getArgument("-u","Twitter",false);
|
var userNamePreFormat = this.getArgument("-u","Twitter",false);
|
||||||
this.userName = userNamePreFormat.replace('@','')
|
this.userName = userNamePreFormat.replace('@','')
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const webdriver = require('selenium-webdriver');
|
const webdriver = require('selenium-webdriver');
|
||||||
const By = webdriver.By;
|
const By = webdriver.By;
|
||||||
|
const fs = require('fs');
|
||||||
//const { format } = require('fast-csv');
|
//const { format } = require('fast-csv');
|
||||||
|
|
||||||
const elements = require('../functions/elements.js'); //link support.js
|
const elements = require('../functions/elements.js'); //link support.js
|
||||||
|
@ -45,6 +46,7 @@ class Tweets {
|
||||||
//body
|
//body
|
||||||
this.hasBody = false;
|
this.hasBody = false;
|
||||||
this.body = "";
|
this.body = "";
|
||||||
|
this.spoiler = "";
|
||||||
this.hasLinks = false;
|
this.hasLinks = false;
|
||||||
this.links = "";
|
this.links = "";
|
||||||
|
|
||||||
|
@ -164,7 +166,20 @@ class Tweets {
|
||||||
debuglog("Found emoji!",2);
|
debuglog("Found emoji!",2);
|
||||||
//this.threadLength = elements.length;
|
//this.threadLength = elements.length;
|
||||||
});*/
|
});*/
|
||||||
const bodyText = await elements.getText(driver,this.x.tweetText);//SET TWEET BODY TO TEXT OF TWEET
|
var bodyText = await elements.getText(driver,this.x.tweetText);//SET TWEET BODY TO TEXT OF TWEET
|
||||||
|
if (args.warnings) {
|
||||||
|
const WarningPrefix = fs.readFileSync("./config.txt").toString().split(/[\r\n]+/)[2];
|
||||||
|
var cwRegexText = new RegExp(`(?<=^${WarningPrefix}[^\\n]*)[\\w].+`, "g");
|
||||||
|
debuglog(cwRegexText);
|
||||||
|
debuglog("content warning text:")
|
||||||
|
debuglog(bodyText.match(cwRegexText));
|
||||||
|
this.spoiler = bodyText.match(cwRegexText)[0];
|
||||||
|
var cwRegexPref = new RegExp(`^${WarningPrefix}.+\\n(\\s)+`, "g");
|
||||||
|
debuglog(cwRegexPref);
|
||||||
|
debuglog("content warning text w pref:")
|
||||||
|
debuglog(bodyText.match(cwRegexPref));
|
||||||
|
bodyText = bodyText.replace(cwRegexPref,"");
|
||||||
|
}
|
||||||
this.appendSection(bodyText,'body');
|
this.appendSection(bodyText,'body');
|
||||||
debuglog(`Tweet Body:\r\n${this.body}`);
|
debuglog(`Tweet Body:\r\n${this.body}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ async function postStatus(tweet,file,csvc){
|
||||||
debuglog("reply to: " + tweet.prompt,2)
|
debuglog("reply to: " + tweet.prompt,2)
|
||||||
Object.assign(params, { in_reply_to_id: tweet.prompt });
|
Object.assign(params, { in_reply_to_id: tweet.prompt });
|
||||||
}
|
}
|
||||||
|
if (tweet.spoiler != "") {//POST IS A REPLY
|
||||||
|
debuglog("spoiler: " + tweet.spoiler,2)
|
||||||
|
Object.assign(params, { sensitive: true });
|
||||||
|
Object.assign(params, { spoiler_text: tweet.spoiler });
|
||||||
|
}
|
||||||
await M.post('statuses', params, (err, data) => {
|
await M.post('statuses', params, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
debuglog(format.error(`Post to Mastodon failed with error: ${err}`), 1);
|
debuglog(format.error(`Post to Mastodon failed with error: ${err}`), 1);
|
||||||
|
|
10
usage.txt
10
usage.txt
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
{Usage}
|
{Usage}
|
||||||
{node ./TwitToMast.js} [{-htqrpmbc}] [{-u} ~username~] [{-n} ~tweetcount~] [{-d} ~debuglevel~] [{-w} ~timeout~]
|
{node ./TwitToMast.js} [{-htqrspmbc}] [{-u} ~username~] [{-n} ~tweetcount~] [{-d} ~debuglevel~] [{-w} ~timeout~]
|
||||||
{node ./multi.js} [{-htqrpmbc}] [{-n} ~tweetcount~] [{-d} ~debuglevel~] [{-w} ~timeout~]
|
{node ./multi.js} [{-htqrspmbc}] [{-n} ~tweetcount~] [{-d} ~debuglevel~] [{-w} ~timeout~]
|
||||||
|
|
||||||
{Arguments}
|
{Arguments}
|
||||||
{-h:} - show help screen (you made it here!)
|
{-h:} - show help screen (you made it here!)
|
||||||
|
@ -15,6 +15,8 @@
|
||||||
{-q:} - quote tweets will be included in the scan
|
{-q:} - quote tweets will be included in the scan
|
||||||
{-r:} - Link to quoted tweet will appear in the header, preceded by "re: "
|
{-r:} - Link to quoted tweet will appear in the header, preceded by "re: "
|
||||||
- default behavior posts link at bottom of Mastodon post preceded by "Quoting "
|
- default behavior posts link at bottom of Mastodon post preceded by "Quoting "
|
||||||
|
{-s:} - Enable content warning/spoiler prefixes
|
||||||
|
- tweets beginning with a certain string (defined in config.txt) will use following text on the same line as Mastodon content warning
|
||||||
{-p:} - enable/disable posting to Mastodon
|
{-p:} - enable/disable posting to Mastodon
|
||||||
{-m:} - include user's name, handle, and link to tweet
|
{-m:} - include user's name, handle, and link to tweet
|
||||||
{-b:} - display browser (disable headless mode)
|
{-b:} - display browser (disable headless mode)
|
||||||
|
@ -33,6 +35,10 @@
|
||||||
- Your Access Token obtained from Mastodon > Preferences > Development > Application
|
- Your Access Token obtained from Mastodon > Preferences > Development > Application
|
||||||
{Line 2: API_URL}
|
{Line 2: API_URL}
|
||||||
- https://~your mastodon server url~/api/v1/
|
- https://~your mastodon server url~/api/v1/
|
||||||
|
{Line 3: CONTENT_WARNING_PREFIX}
|
||||||
|
- if enabled, tweets beginning with this string will use following text on the same line as Mastodon content warning
|
||||||
|
- Commonly used content warning prefixes on twitter are "CW//", "TW//", and "SPOILER//"
|
||||||
|
- Starting a tweet with "SPOILER// Endgame Spoilers" with hide the contents of the crossposted toot behind a warning reading "Endgame Spoilers"
|
||||||
|
|
||||||
{Examples}
|
{Examples}
|
||||||
{Scrape 10 most recent tweets, quote tweets, and thread tweets from @twitter account, and post to Mastodon}
|
{Scrape 10 most recent tweets, quote tweets, and thread tweets from @twitter account, and post to Mastodon}
|
||||||
|
|
Reference in a new issue