70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
const sdk = require("matrix-js-sdk");
|
|
const matrixcs = require("matrix-js-sdk/lib/matrix");
|
|
const request = require('request');
|
|
matrixcs.request(request);
|
|
|
|
const startupTime = Date.now();
|
|
|
|
const myUserId = "@glowy:glowers.club"
|
|
const myAccessToken = "syt_TotallyMyRealAccessTokenAndNotAFake";
|
|
const matrixClient = sdk.createClient({
|
|
baseUrl: "https://glowers.club",
|
|
accessToken: myAccessToken,
|
|
userId: myUserId
|
|
});
|
|
|
|
const uploadMatrixClient = sdk.createClient({
|
|
baseUrl: "https://midov.pl",
|
|
accessToken: "syt_AnotherRealAccessTokenDoNotCommit",
|
|
userId: "@upload_leech:midov.pl"
|
|
});
|
|
|
|
const Searx = require('./index.js');
|
|
const searx = new Searx(matrixClient)
|
|
searx.setUploadMatrixClient(uploadMatrixClient);
|
|
searx.setBlacklistedImgRooms(["!wehateimagesearching:matrix.org", "!wehateittoo:nerdsin.space"]);
|
|
searx.setBlacklistedUimgRooms(["!sfw:matrix.org", "!church:nerdsin.space"]);
|
|
searx.setCooldownImmuneUsers(["@q:glowers.club","@midov:midov.pl"]);
|
|
searx.setRoomCooldowns(new Map([
|
|
["!sCbWouzHiLEyfOAaSJ:midov.pl",30000]
|
|
]));
|
|
searx.setSearxInstance("https://searx.example.com");
|
|
searx.setSearxParameters("disabled_engines=flickr__images");
|
|
|
|
searxng.setRoomUserWhitelists(new Map([
|
|
["!blahblahblah:midov.pl",
|
|
[
|
|
"@q:glowers.club",
|
|
"@midek:midov.pl"
|
|
]
|
|
]
|
|
]));
|
|
|
|
matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) {
|
|
if (event.getTs() >= startupTime && event.getType() == "m.room.message" && event.getContent().body != null) {
|
|
|
|
if (event.getContent().body.indexOf("!help") == 0) {
|
|
const helpMessage = "Commands:\n"+searx.getHelp();
|
|
const formattedHelpMessage = "Commands:<br />"+searx.getFormattedHelp();
|
|
|
|
const content = {
|
|
"format": "org.matrix.custom.html",
|
|
"body": helpMessage,
|
|
"formatted_body": formattedHelpMessage,
|
|
"msgtype": "m.text"
|
|
};
|
|
matrixClient.sendEvent(room.roomId, "m.room.message", content, "", (err, res) => {
|
|
if (err != null) {
|
|
console.error(err);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
|
|
searx.handleMessage(event, room);
|
|
}
|
|
});
|
|
|
|
searx.startUploadMatrixClient();
|
|
matrixClient.startClient();
|