feat(fediverse): add twitter crossblog [kakashi]

chore(config): update maintained nitter instances
This commit is contained in:
vulet 2023-09-04 17:56:31 +08:00
parent 12c422c324
commit 17c7f819ac
3 changed files with 16 additions and 6 deletions

View file

@ -63,19 +63,25 @@ const getInstance = (domain, config) =>
timeout: 10 * 1000,
});
const run = async (roomId, userInput) => {
const run = async (roomId, userInput, fedi) => {
const cfg = config.nitter;
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 {
const url = new URL(userInput);
const { redirect, original } = config.nitter.domains;
if (!redirect.includes(url.hostname) && !original.includes(url.hostname)) throw '';
if (!/^\/[^/]+\/status\/\d+\/?$/.test(url.pathname)) throw '';
return await run(roomId, url.pathname);
return await run(roomId, url.pathname, fedi);
} catch (e) {
return matrixClient.sendHtmlNotice(roomId, 'Sad!', '<strong>Sad!</strong>').catch(() => {});
}

View file

@ -33,8 +33,8 @@ module.exports = {
nitter: {
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)',
domains: {
redirect: [ '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' ]
redirect: [ 'nitter.unixfox.eu', 'nitter.cz', 'nitter.privacydev.net', 'nitter.poast.org', 'nitter.fdn.fr', 'nitter.snopyta.org', 'nitter.net' ],
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: '(✅)',
},

View file

@ -64,6 +64,10 @@ const eventHandler = (args, roomId, command, event) => {
});
command = 'post';
break;
case 'crossblog':
args.push(roomId, event, userInput, true);
command = 'nitter'
break;
case 'proxy': case 'p':
try {
const url = new URL(userInput);