feat(fediverse): add twitter crossblog [kakashi]
chore(config): update maintained nitter instances
This commit is contained in:
parent
12c422c324
commit
17c7f819ac
3 changed files with 16 additions and 6 deletions
|
@ -63,19 +63,25 @@ const getInstance = (domain, config) =>
|
||||||
timeout: 10 * 1000,
|
timeout: 10 * 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const run = async (roomId, userInput) => {
|
const run = async (roomId, userInput, fedi) => {
|
||||||
const cfg = config.nitter;
|
const cfg = config.nitter;
|
||||||
const tweet = await matrix.utils.retryPromise(cfg.domains.redirect, domain => nitter(getInstance(domain, cfg), userInput));
|
const tweet = await matrix.utils.retryPromise(cfg.domains.redirect, domain => nitter(getInstance(domain, cfg), userInput));
|
||||||
return matrixClient.sendHtmlNotice(roomId, ' ', card(tweet, cfg.check, userInput));
|
const tweetCard = card(tweet, cfg.check, userInput);
|
||||||
|
return fedi ? axios({
|
||||||
|
method: 'POST',
|
||||||
|
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||||
|
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||||
|
data: { status: tweetCard, content_type: 'text/html' }
|
||||||
|
}) : matrixClient.sendHtmlNotice(roomId, ' ', tweetCard);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.runQuery = async (roomId, event, userInput) => {
|
exports.runQuery = async (roomId, event, userInput, fedi) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(userInput);
|
const url = new URL(userInput);
|
||||||
const { redirect, original } = config.nitter.domains;
|
const { redirect, original } = config.nitter.domains;
|
||||||
if (!redirect.includes(url.hostname) && !original.includes(url.hostname)) throw '';
|
if (!redirect.includes(url.hostname) && !original.includes(url.hostname)) throw '';
|
||||||
if (!/^\/[^/]+\/status\/\d+\/?$/.test(url.pathname)) throw '';
|
if (!/^\/[^/]+\/status\/\d+\/?$/.test(url.pathname)) throw '';
|
||||||
return await run(roomId, url.pathname);
|
return await run(roomId, url.pathname, fedi);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return matrixClient.sendHtmlNotice(roomId, 'Sad!', '<strong>Sad!</strong>').catch(() => {});
|
return matrixClient.sendHtmlNotice(roomId, 'Sad!', '<strong>Sad!</strong>').catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ module.exports = {
|
||||||
nitter: {
|
nitter: {
|
||||||
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)',
|
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)',
|
||||||
domains: {
|
domains: {
|
||||||
redirect: [ 'nitter.fdn.fr', 'nitter.snopyta.org', 'nitter.net' ],
|
redirect: [ 'nitter.unixfox.eu', 'nitter.cz', 'nitter.privacydev.net', 'nitter.poast.org', 'nitter.fdn.fr', 'nitter.snopyta.org', 'nitter.net' ],
|
||||||
original: [ 'nitter.net', 'www.nitter.net', 'twitter.com', 'www.twitter.com', 'mobile.twitter.com', 'm.twitter.com' ]
|
original: [ 'nitter.unixfox.eu', 'nitter.cz', 'nitter.privacydev.net', 'nitter.poast.org', 'nitter.net', 'www.nitter.net', 'twitter.com', 'www.twitter.com', 'mobile.twitter.com', 'm.twitter.com' ]
|
||||||
},
|
},
|
||||||
check: '(✅)',
|
check: '(✅)',
|
||||||
},
|
},
|
||||||
|
|
4
utils.js
4
utils.js
|
@ -64,6 +64,10 @@ const eventHandler = (args, roomId, command, event) => {
|
||||||
});
|
});
|
||||||
command = 'post';
|
command = 'post';
|
||||||
break;
|
break;
|
||||||
|
case 'crossblog':
|
||||||
|
args.push(roomId, event, userInput, true);
|
||||||
|
command = 'nitter'
|
||||||
|
break;
|
||||||
case 'proxy': case 'p':
|
case 'proxy': case 'p':
|
||||||
try {
|
try {
|
||||||
const url = new URL(userInput);
|
const url = new URL(userInput);
|
||||||
|
|
Loading…
Reference in a new issue