improve authorization
This commit is contained in:
parent
296cdc75a6
commit
73dac81f2d
30 changed files with 1265 additions and 316 deletions
12
commands/fediverse/auth.js
Normal file
12
commands/fediverse/auth.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
exports.runQuery = (roomId,event,userInput) => {
|
||||
|
||||
//matrixClient.sendHtmlNotice(roomId,"Проверка связи","Проверка связи");
|
||||
const link = auth.getFediverseLink(userInput)
|
||||
if(!link){
|
||||
matrixClient.sendHtmlNotice(roomId,"Не удалось получить ссылку")
|
||||
}else if(link == "nothing"){
|
||||
}else{
|
||||
authEvents.push(event.event_id)
|
||||
matrixClient.sendHtmlNotice(roomId,`Перейдите по ссылке для входа в аккаунт. Для завершения ответьте на это сообщение кодом (еще не готово, пж не переходе по ссылке): ${link}`)
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
exports.runQuery = function (roomId, event) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
data: { status: '@10grans@fedi.cc beg' },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.addReact(event, '❌');
|
||||
matrix.utils.sendError(event, roomId, e);
|
||||
});
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/unfavourite`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/unfavourite`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/favourite`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/favourite`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/reblog`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/reblog`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -12,11 +12,12 @@ exports.runQuery = function (roomId, disable) {
|
|||
intervalId = setInterval(() => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v1/timelines/home`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/timelines/home`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then((res) => {
|
||||
let past = JSON.parse(localStorage.getItem('timeline'));
|
||||
let timeline = JSON.parse(localStorage.getItem('timeline'));
|
||||
past = timeline[event.getSender()] || {}
|
||||
if (past.length === 0) past = res.data;
|
||||
const events = res.data;
|
||||
const len = events.length;
|
||||
|
@ -28,7 +29,8 @@ exports.runQuery = function (roomId, disable) {
|
|||
fediverse.utils.formatter(events[i], roomId);
|
||||
}
|
||||
}
|
||||
localStorage.setItem('timeline', JSON.stringify(events, null, 2));
|
||||
timeline[event.getSender()] = events
|
||||
localStorage.setItem('timeline', JSON.stringify(timeline, null, 2));
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.sendError(null, roomId, e);
|
||||
|
|
|
@ -5,8 +5,8 @@ exports.runQuery = async function (roomId, event, userInput) {
|
|||
const suggest = [];
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v2/search?q=${userInput}&type=accounts`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v2/search?q=${userInput}&type=accounts`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
}).then((findUserId) => {
|
||||
const results = findUserId.data.accounts;
|
||||
const len = results.length;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
exports.runQuery = async function (roomId, event, notice) {
|
||||
if (config.fediverse.tipping === false) return matrixClient.sendHtmlNotice(roomId, `Tipping is not enabled.`, `<code>Tipping is not enabled.</code>`);
|
||||
const loadingString = `Making it rain for notice: ${notice}...`;
|
||||
const original = await matrixClient.sendHtmlNotice(roomId, `${loadingString}`, `<code>${loadingString}</code>`);
|
||||
const findAllUsers = await fediverse.utils.getStatusMentions(notice, event, original);
|
||||
const exclude = "@10grans@fedi.cc";
|
||||
const users = findAllUsers.filter(users => !exclude.includes(findAllUsers));
|
||||
if (!users) return matrix.utils.editNoticeHTML(roomId, original, `<code>No eligible users found.</code>`);
|
||||
const rain = (users) => {
|
||||
amount = users.length * 0.00000001337 // by per user:
|
||||
if (users.length === 1) return amount * 100000 // 0.001337
|
||||
if (users.length <= 5) return amount * 10000 // 0.0001337
|
||||
if (users.length <= 10) return amount * 1000 // 0.00001337
|
||||
if (users.length <= 100) return amount * 100 // 0.000001337
|
||||
return amount
|
||||
}
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
data: { status: `@10grans@fedi.cc makeitrain ${rain(users)} to ${users.join(' ')}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
return matrix.utils.editNoticeHTML(roomId, original, `<code>Raining ${rain(users)} 10grans on: 🌧${users.join(', ')}🌧</code>`);
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.addReact(event, '❌');
|
||||
return matrix.utils.editNoticeHTML(roomId, original, `<code>${e}</code>`)
|
||||
});
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
data: {
|
||||
status: `@mordekai ${userInput}`,
|
||||
content_type: 'text/markdown',
|
||||
visibility: 'unlisted',
|
||||
expires_in: '7200',
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.addReact(event, '❌');
|
||||
matrix.utils.sendError(event, roomId, e);
|
||||
});
|
||||
};
|
|
@ -12,11 +12,12 @@ exports.runQuery = function (roomId, disable) {
|
|||
intervalId = setInterval(() => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v1/notifications`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/notifications`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then((res) => {
|
||||
let past = JSON.parse(localStorage.getItem('notifications'));
|
||||
let notifications = JSON.parse(localStorage.getItem('notifications'));
|
||||
let past = notifications[event.getSender()] || {}
|
||||
if (past.length === 0) past = res.data;
|
||||
const events = res.data;
|
||||
const len = events.length;
|
||||
|
@ -28,7 +29,8 @@ exports.runQuery = function (roomId, disable) {
|
|||
fediverse.utils.formatter(events[i], roomId);
|
||||
}
|
||||
}
|
||||
localStorage.setItem('notifications', JSON.stringify(events, null, 2));
|
||||
notifications[event.getSender()] = events
|
||||
localStorage.setItem('notifications', JSON.stringify(notifications, null, 2));
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.sendError(null, roomId, e);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/pin`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/pin`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -84,8 +84,8 @@ const mediaUpload = async ({ domain }, { data, filename, mimetype }) => {
|
|||
});
|
||||
const upload = await axios({
|
||||
method: 'POST',
|
||||
url: `${domain}/api/v1/media`,
|
||||
headers: form.getHeaders({ Authorization: `Bearer ${fediverse.auth.access_token}` }),
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/media`,
|
||||
headers: form.getHeaders({ Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` }),
|
||||
data: form,
|
||||
});
|
||||
if (upload.statusText !== 'OK') throw upload;
|
||||
|
@ -101,8 +101,8 @@ const run = async (roomId, event, content, replyId, mediaURL, subject, visibilit
|
|||
if (replyId) content = await fediverse.utils.getStatusMentions(replyId, event).then(m => m.concat(content).join(' '));
|
||||
const response = await axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}`, 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}`, 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
data: qs.stringify({
|
||||
status: content,
|
||||
content_type: 'text/markdown',
|
||||
|
@ -126,6 +126,7 @@ exports.runQuery = async (roomId, event, userInput, { isReply, hasMedia, hasSubj
|
|||
if (hasMedia) mediaURL = chunks.shift();
|
||||
return await run(roomId, event, chunks.join(' '), replyId, mediaURL, subject, visibility);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return matrixClient.sendHtmlNotice(roomId, 'Sad!', '<strong>Sad!</strong>').catch(() => {});
|
||||
}
|
||||
};
|
||||
|
|
4
commands/fediverse/react.js
vendored
4
commands/fediverse/react.js
vendored
|
@ -1,8 +1,8 @@
|
|||
const run = async (roomId, event, id, emoji, remove) => {
|
||||
axios({
|
||||
method: remove ? 'DELETE' : 'PUT',
|
||||
url: `${config.fediverse.domain}/api/v1/pleroma/statuses/${id}/reactions/${emoji}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/pleroma/statuses/${id}/reactions/${emoji}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'DELETE',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then((response) => {
|
||||
response.label = 'status';
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
exports.runQuery = function (roomId, event, address, flaggedInput) {
|
||||
if (config.fediverse.tipping === false) return matrixClient.sendHtmlNotice(roomId, `Tipping is not enabled.`, `<code>Tipping is not enabled.</code>`);
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
data: { status: `@10grans@fedi.cc tip ${flaggedInput} to ${address}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.addReact(event, '❌');
|
||||
matrix.utils.sendError(event, roomId, e);
|
||||
});
|
||||
};
|
|
@ -5,8 +5,8 @@ exports.runQuery = async function (roomId, event, userInput) {
|
|||
const suggest = [];
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v2/search?q=${userInput}&type=accounts`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v2/search?q=${userInput}&type=accounts`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
}).then((findUserId) => {
|
||||
const results = findUserId.data.accounts;
|
||||
const len = results.length;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/unpin`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/unpin`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${userInput}/unreblog`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${userInput}/unreblog`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
exports.runQuery = function (roomId, event, userInput) {
|
||||
const instance = axios.create({
|
||||
baseURL: config.fediverse.domain,
|
||||
baseURL: 'https://' + fediverse.auth[event.getSender()].domain,
|
||||
method: 'GET',
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
});
|
||||
instance.get(`/api/v1/statuses/${userInput}/context`)
|
||||
.then(async (response) => {
|
||||
|
|
|
@ -142,8 +142,8 @@ module.exports.formatter = (res, roomId, event) => {
|
|||
module.exports.follow = (roomId, account, event, original) => {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/accounts/${account[0].id}/follow`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${config.fediverse[event.getSender()].domain}/api/v1/accounts/${account[0].id}/follow`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
@ -158,8 +158,8 @@ module.exports.follow = (roomId, account, event, original) => {
|
|||
module.exports.unfollow = (roomId, account, event, original) => {
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/accounts/${account[0].id}/unfollow`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/accounts/${account[0].id}/unfollow`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
})
|
||||
.then(() => {
|
||||
matrix.utils.addReact(event, '✅');
|
||||
|
@ -174,8 +174,8 @@ module.exports.unfollow = (roomId, account, event, original) => {
|
|||
module.exports.getStatusMentions = (notice, event) => {
|
||||
const users = axios({
|
||||
method: 'GET',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses/${notice}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/statuses/${notice}`,
|
||||
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
||||
}).then((notice) => {
|
||||
const users = [];
|
||||
users.push('@' + notice.data.account.acct);
|
||||
|
|
|
@ -12,9 +12,6 @@ exports.runQuery = function (roomId) {
|
|||
+ '+copy [post id] : repeat/repost/retweet<br>'
|
||||
+ '+crossblog [status URL]: cross blog twitter post to fediverse post<br>'
|
||||
+ '+reply [post id] [content] : reply to post<br>'
|
||||
+ '+tip [@user@fedi.url] [amount] : tip 10grans<br>'
|
||||
+ '+makeitrain [post id] : make it rain 10grans<br>'
|
||||
+ '+beg : beg for 10grans<br>'
|
||||
+ '+clap [post id] : favorite<br>'
|
||||
+ '+boo [post id] : unfavorite</blockquote>'
|
||||
+ '<blockquote><b>channel commands<br>'
|
||||
|
@ -30,6 +27,7 @@ exports.runQuery = function (roomId) {
|
|||
+ `<blockquote><b>ligh7hau5 version ${require('../package.json').version}</b><br>`
|
||||
+ '<b>--- <i>Contributors🐱</i> ---</b><br>'
|
||||
+ '<b>CRYPTOMOONERS</b><br>'
|
||||
+ '<b>doesnm</b><br>'
|
||||
+ '<b><i>docs by LINT</i></b></blockquote>'
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
const msg = 'Invalid proxy domain!';
|
||||
exports.runQuery = (roomId, event, userInput) =>
|
||||
matrixClient.sendHtmlNotice(roomId, msg, `<b>${msg}</b>`).catch(() => {});
|
Loading…
Add table
Add a link
Reference in a new issue