chore(config): tidy up

This commit is contained in:
vulet 2020-06-28 15:07:58 +08:00
parent dc0a6ff922
commit f013eb1c98
18 changed files with 76 additions and 62 deletions

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, registrar) { exports.runQuery = function (matrixClient, room, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`, url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { status: `@10grans@fedi.cc beg` }, data: { status: `@10grans@fedi.cc beg` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/unfavourite`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/unfavourite`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/favourite`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/favourite`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/reblog`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/reblog`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',

View file

@ -5,8 +5,8 @@ exports.runQuery = function (matrixClient, room, registrar) {
setInterval(() => { setInterval(() => {
axios({ axios({
method: 'GET', method: 'GET',
url: `${registrar.config.fediverse}/api/v1/timelines/home`, url: `${registrar.config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((events) => { }).then((events) => {
const event = fs.readFileSync('timeline.json', 'utf8'); const event = fs.readFileSync('timeline.json', 'utf8');
fs.writeFileSync('timeline.json', events.data[0].created_at, 'utf8'); fs.writeFileSync('timeline.json', events.data[0].created_at, 'utf8');
@ -14,7 +14,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
if (events.data[0].reblog === null) { if (events.data[0].reblog === null) {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/notice/${events.data[0].id}">${events.data[0].account.acct}</a> `<b><a href="${registrar.config.fediverse.domain}/notice/${events.data[0].id}">${events.data[0].account.acct}</a>
<blockquote><i>${events.data[0].content}<br> <blockquote><i>${events.data[0].content}<br>
${events.data[0].media_attachments.map(media => ${events.data[0].media_attachments.map(media =>
`<a href="${media.remote_url}">`+`${media.description}`+'</a>' `<a href="${media.remote_url}">`+`${media.description}`+'</a>'
@ -24,9 +24,9 @@ exports.runQuery = function (matrixClient, room, registrar) {
} else { } else {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/${events.data[0].account.id}"> `<b><a href="${registrar.config.fediverse.domain}/${events.data[0].account.id}">
${events.data[0].account.acct}</a> ${events.data[0].account.acct}</a>
<font color="#7886D7">has <a href="${registrar.config.fediverse}/notice/${events.data[0].id}">repeated</a>: <font color="#7886D7">has <a href="${registrar.config.fediverse.domain}/notice/${events.data[0].id}">repeated</a>:
<blockquote><a href="${events.data[0].reblog.account.url}">${events.data[0].reblog.account.acct}</a></blockquote> <blockquote><a href="${events.data[0].reblog.account.url}">${events.data[0].reblog.account.acct}</a></blockquote>
<blockquote>${events.data[0].content}<br> <blockquote>${events.data[0].content}<br>
${events.data[0].media_attachments.map(media => ${events.data[0].media_attachments.map(media =>

View file

@ -1,17 +1,17 @@
const axios = require('axios'); const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios.get(`${registrar.config.fediverse}/api/v1/accounts/${userInput}`).then((findUID) => { axios.get(`${registrar.config.fediverse.domain}/api/v1/accounts/${userInput}`).then((findUID) => {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/accounts/${findUID.data.id}/follow`, url: `${registrar.config.fediverse.domain}/api/v1/accounts/${findUID.data.id}/follow`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}) })
.then((response) => { .then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`Subscribed: `Subscribed:
<blockquote>${registrar.config.fediverse}/${response.data.id}`); <blockquote>${registrar.config.fediverse.domain}/${response.data.id}`);
}); });
}).catch((e) => { }).catch((e) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -12,7 +12,13 @@ exports.runQuery = function (matrixClient, room) {
+ '+clap [post id] : favorite<br>' + '+clap [post id] : favorite<br>'
+ '+boo [post id] : unfavorite</blockquote>' + '+boo [post id] : unfavorite</blockquote>'
+ '<blockquote><b>channel commands<br>' + '<blockquote><b>channel commands<br>'
+ '+flood : turn on timeline<br>' + '+flood : turn on timeline in channel<br>'
+ '+notify : show notifications</b></blockquote>' + '+notify : show notifications in channel</b>'
+ '+archive [URL] : archive content<br>'
+ '+rearchive [URL] : re-archive content<br>'
+ '+nitter [status URL] : redirect twitter to nitter, also embed tweet<br>'
+ '+invidious [video URL] : redirect youtube to invidious, also embed description<br></blockquote>'
+ '<blockquote><b>--- <i>contributors🐱</i> ---</b>'
+ '--- <i>cryptomooners</i> ---</blockquote>'
+ '<blockquote><b>--- <i>docs by lint</i> ---</b></blockquote>'); + '<blockquote><b>--- <i>docs by lint</i> ---</b></blockquote>');
}; };

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`, url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { data: {
status: `@mordekai ${userInput}`, status: `@mordekai ${userInput}`,
content_type: `text/markdown`, content_type: `text/markdown`,

View file

@ -5,8 +5,8 @@ exports.runQuery = function (matrixClient, room, registrar) {
setInterval(() => { setInterval(() => {
axios({ axios({
method: 'GET', method: 'GET',
url: `${registrar.config.fediverse}/api/v1/notifications`, url: `${registrar.config.fediverse.domain}/api/v1/notifications`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((notifications) => { }).then((notifications) => {
const event = fs.readFileSync('notification.json', 'utf8'); const event = fs.readFileSync('notification.json', 'utf8');
fs.writeFileSync('notification.json', notifications.data[0].created_at, 'utf8'); fs.writeFileSync('notification.json', notifications.data[0].created_at, 'utf8');
@ -15,14 +15,14 @@ exports.runQuery = function (matrixClient, room, registrar) {
if (notifications.data[0].type === 'follow') { if (notifications.data[0].type === 'follow') {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/${notifications.data[0].account.id}"> `<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
${notifications.data[0].account.acct}</a></b> ${notifications.data[0].account.acct}</a></b>
<font color="#03b381"><b>has followed you.</b></font> <font color="#03b381"><b>has followed you.</b></font>
<br><i>${notifications.data[0].account.note}</i>`); <br><i>${notifications.data[0].account.note}</i>`);
} else if (notifications.data[0].type === 'favourite') { } else if (notifications.data[0].type === 'favourite') {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/${notifications.data[0].account.id}"> `<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
${notifications.data[0].account.acct}</a></b> ${notifications.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">favorited</a> <font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">favorited</a>
your post:</b></font> your post:</b></font>
@ -30,7 +30,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
} else if (notifications.data[0].type === 'mention') { } else if (notifications.data[0].type === 'mention') {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/${notifications.data[0].account.id}"> `<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
${notifications.data[0].account.acct}</a></b> ${notifications.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">mentioned</a> <font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">mentioned</a>
you:</b></font><br><blockquote><i><b>${notifications.data[0].status.content} you:</b></font><br><blockquote><i><b>${notifications.data[0].status.content}
@ -39,7 +39,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
} else if (notifications.data[0].type === 'reblog') { } else if (notifications.data[0].type === 'reblog') {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`<b><a href="${registrar.config.fediverse}/${notifications.data[0].account.id}"> `<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
${notifications.data[0].account.acct}</a></b> ${notifications.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">repeated</a> <font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">repeated</a>
your post:</b></font><br> your post:</b></font><br>

View file

@ -3,13 +3,13 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/pin`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/pin`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`Pinned: `Pinned:
<blockquote><i><a href="${registrar.config.fediverse}/notice/${response.data.id}"> <blockquote><i><a href="${registrar.config.fediverse.domain}/notice/${response.data.id}">
${response.data.content}</a></i> ${response.data.content}</a></i>
</blockquote>`); </blockquote>`);
}) })

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`, url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { status: userInput, content_type: `text/markdown` }, data: { status: userInput, content_type: `text/markdown` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'DELETE', method: 'DELETE',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, address, flaggedInput, registrar) { exports.runQuery = function (matrixClient, room, address, flaggedInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`, url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { status: flaggedInput, in_reply_to_id: address, content_type: `text/markdown` }, data: { status: flaggedInput, in_reply_to_id: address, content_type: `text/markdown` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -3,8 +3,8 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, address, flaggedInput, registrar) { exports.runQuery = function (matrixClient, room, address, flaggedInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`, url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { status: `@10grans@fedi.cc tip `+ flaggedInput + ` to `+address }, data: { status: `@10grans@fedi.cc tip `+ flaggedInput + ` to `+address },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -1,17 +1,17 @@
const axios = require('axios'); const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios.get(`${registrar.config.fediverse}/api/v1/accounts/${userInput}`).then((findUID) => { axios.get(`${registrar.config.fediverse.domain}/api/v1/accounts/${userInput}`).then((findUID) => {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/accounts/${findUID.data.id}/unfollow`, url: `${registrar.config.fediverse.domain}/api/v1/accounts/${findUID.data.id}/unfollow`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}) })
.then((response) => { .then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`Unsubscribed: `Unsubscribed:
<blockquote>${registrar.config.fediverse}/${response.data.id}`); <blockquote>${registrar.config.fediverse.domain}/${response.data.id}`);
}); });
}).catch((e) => { }).catch((e) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,

View file

@ -3,13 +3,13 @@ const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) { exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({ axios({
method: 'POST', method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/unpin`, url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/unpin`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((response) => { }).then((response) => {
matrixClient.sendHtmlNotice(room.roomId, matrixClient.sendHtmlNotice(room.roomId,
'', '',
`Unpinned: `Unpinned:
<blockquote><i><a href="${registrar.config.fediverse}/notice/${response.data.id}"> <blockquote><i><a href="${registrar.config.fediverse.domain}/notice/${response.data.id}">
${response.data.content}</a></i> ${response.data.content}</a></i>
</blockquote>`); </blockquote>`);
}) })

View file

@ -1,10 +1,13 @@
module.exports = { module.exports = {
matrixServer: 'https://server.com', matrix: {
userId: '@matrixUser:server.com', domain: 'https://your_homeserver.com',
matrixUser: 'hello', user: 'your_user',
matrixPass: 'password', password: 'your_password',
fediverse: 'https://server.com', },
fediverseToken: 'access_token', fediverse: {
domain: 'https://your_federation.com',
token: 'your_federation_token',
},
archive: { archive: {
domain: 'archive.is', domain: 'archive.is',
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)' userAgent: 'Mozilla/4.0 (compatible; Beep Boop)'
@ -12,7 +15,7 @@ module.exports = {
nitter: { nitter: {
domain: 'nitter.net', domain: 'nitter.net',
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)', userAgent: 'Mozilla/4.0 (compatible; Beep Boop)',
domains: [ 'nitter.net', 'www.nitter.net', 'twitter.com', 'www.twitter.com' ] domains: [ 'nitter.net', 'www.nitter.net', 'twitter.com', 'wwww.twitter.com' ]
}, },
invidious: { invidious: {
domain: 'invidio.us', domain: 'invidio.us',

23
main.js
View file

@ -4,36 +4,41 @@ const registrar = require('./registrar.js');
const auth = { const auth = {
type: 'm.login.password', type: 'm.login.password',
user: registrar.config.matrixUser, user: registrar.config.matrix.user,
password: registrar.config.matrixPass, password: registrar.config.matrix.password,
}; };
axios.post(`${registrar.config.matrixServer}/_matrix/client/r0/login`, auth).then((response) => { axios.post(`${registrar.config.matrix.domain}/_matrix/client/r0/login`, auth).then((response) => {
CreateClient(response.data.access_token); CreateClient(response.data.access_token, response.data.user_id);
}).catch((e) => { }).catch((e) => {
console.log(e); console.log(e);
}); });
let CreateClient = (token) => { let CreateClient = (token, user_id) => {
const matrixClient = sdk.createClient({ const matrixClient = sdk.createClient({
baseUrl: registrar.config.matrixServer, baseUrl: registrar.config.matrix.domain,
accessToken: token, accessToken: token,
userId: registrar.config.userId, userId: user_id,
timelineSupport: true, timelineSupport: true,
}); });
matrixClient.on('RoomMember.membership', (event, member) => { matrixClient.on('RoomMember.membership', (event, member) => {
if (member.membership === 'invite' && member.userId === registrar.config.userId) { if (member.membership === 'invite' && member.userId === matrixClient.credentials.userId) {
matrixClient.joinRoom(member.roomId).done(() => { matrixClient.joinRoom(member.roomId).done(() => {
console.log('Auto-joined %s', member.roomId); console.log('Auto-joined %s', member.roomId);
}); });
} }
if (member.membership === 'leave' && member.userId === matrixClient.credentials.userId) {
matrixClient.forget(member.roomId).then(() => {
console.log('Kicked %s', member.roomId);
});
}
}); });
matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => { matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
if (toStartOfTimeline) return; if (toStartOfTimeline) return;
if (event.getType() !== 'm.room.message') return; if (event.getType() !== 'm.room.message') return;
if (event.getSender() === registrar.config.userId) return; if (event.getSender() === matrixClient.credentials.userId) return;
if (event.event.unsigned.age > 10000) return; if (event.event.unsigned.age > 10000) return;
if (event.event.content.body.charAt(0) === '+') { if (event.event.content.body.charAt(0) === '+') {
console.log(`Logs: ${event.event.sender} - ${event.event.content.body}`); console.log(`Logs: ${event.event.sender} - ${event.event.content.body}`);