2021-02-14 10:57:35 +03:00
|
|
|
exports.runQuery = async function (roomId, event, userInput) {
|
|
|
|
const loadingString = `Searching for ${userInput}...`;
|
|
|
|
const original = await matrixClient.sendHtmlNotice(roomId, `${loadingString}`, `<code>${loadingString}</code>`);
|
|
|
|
const found = [];
|
|
|
|
const suggest = [];
|
|
|
|
axios({
|
|
|
|
method: 'GET',
|
2024-09-29 20:53:07 +03:00
|
|
|
url: `https://${fediverse.auth[event.getSender()].domain}/api/v2/search?q=${userInput}&type=accounts`,
|
|
|
|
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
2021-02-14 10:57:35 +03:00
|
|
|
}).then((findUserId) => {
|
|
|
|
const results = findUserId.data.accounts;
|
|
|
|
const len = results.length;
|
|
|
|
for (let i = 0; i < len; i++) results[i].acct !== userInput ? suggest.push(results[i].acct) : found.push(results[i]);
|
|
|
|
if (found.length > 0) return fediverse.utils.unfollow(roomId, found, event, original);
|
|
|
|
if (suggest.length > 0) msg = `<code>${userInput} was not found, suggesting:</code><blockquote>${suggest.join('<br>')}</blockquote>`;
|
|
|
|
if (suggest.length === 0) msg = `<code>No results found for: ${userInput}.</code>`;
|
|
|
|
return matrix.utils.editNoticeHTML(roomId, original, msg);
|
2019-07-04 00:27:39 +03:00
|
|
|
});
|
|
|
|
};
|