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) {
axios({
method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` },
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: { status: `@10grans@fedi.cc beg` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,

View file

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

View file

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

View file

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

View file

@ -5,8 +5,8 @@ exports.runQuery = function (matrixClient, room, registrar) {
setInterval(() => {
axios({
method: 'GET',
url: `${registrar.config.fediverse}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` },
url: `${registrar.config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((events) => {
const event = fs.readFileSync('timeline.json', '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) {
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>
${events.data[0].media_attachments.map(media =>
`<a href="${media.remote_url}">`+`${media.description}`+'</a>'
@ -24,9 +24,9 @@ exports.runQuery = function (matrixClient, room, registrar) {
} else {
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>
<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>${events.data[0].content}<br>
${events.data[0].media_attachments.map(media =>

View file

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

View file

@ -12,7 +12,13 @@ exports.runQuery = function (matrixClient, room) {
+ '+clap [post id] : favorite<br>'
+ '+boo [post id] : unfavorite</blockquote>'
+ '<blockquote><b>channel commands<br>'
+ '+flood : turn on timeline<br>'
+ '+notify : show notifications</b></blockquote>'
+ '+flood : turn on timeline in channel<br>'
+ '+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>');
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

23
main.js
View file

@ -4,36 +4,41 @@ const registrar = require('./registrar.js');
const auth = {
type: 'm.login.password',
user: registrar.config.matrixUser,
password: registrar.config.matrixPass,
user: registrar.config.matrix.user,
password: registrar.config.matrix.password,
};
axios.post(`${registrar.config.matrixServer}/_matrix/client/r0/login`, auth).then((response) => {
CreateClient(response.data.access_token);
axios.post(`${registrar.config.matrix.domain}/_matrix/client/r0/login`, auth).then((response) => {
CreateClient(response.data.access_token, response.data.user_id);
}).catch((e) => {
console.log(e);
});
let CreateClient = (token) => {
let CreateClient = (token, user_id) => {
const matrixClient = sdk.createClient({
baseUrl: registrar.config.matrixServer,
baseUrl: registrar.config.matrix.domain,
accessToken: token,
userId: registrar.config.userId,
userId: user_id,
timelineSupport: true,
});
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(() => {
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) => {
if (toStartOfTimeline) 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.content.body.charAt(0) === '+') {
console.log(`Logs: ${event.event.sender} - ${event.event.content.body}`);