Added URL checking

This commit is contained in:
Chris Plaatjes 2023-02-22 22:25:16 -05:00
parent 40ef5a4c81
commit 3ad4c11a4e

View File

@ -5,11 +5,16 @@ import {
RustSdkCryptoStorageProvider RustSdkCryptoStorageProvider
} from "matrix-bot-sdk"; } from "matrix-bot-sdk";
//Import
import { VidDownload } from "./ttDownloader";
let downloader = new VidDownload;
//import config data //import config data
import settings from "./config/config.Dev.json"; import settings from "./config/config.Dev.json";
const homeserverUrl = settings.matrixAddress; const homeserverUrl = settings.matrixAddress;
const accessToken = settings.accessToken; const accessToken = settings.accessToken;
const ptInstance = settings.ptInstance;
const storage = new SimpleFsStorageProvider("./config/bot.json"); const storage = new SimpleFsStorageProvider("./config/bot.json");
const cryptoProvider = new RustSdkCryptoStorageProvider("./config/crypto"); const cryptoProvider = new RustSdkCryptoStorageProvider("./config/crypto");
@ -17,6 +22,9 @@ const cryptoProvider = new RustSdkCryptoStorageProvider("./config/crypto");
const client = new MatrixClient(homeserverUrl, accessToken, storage, cryptoProvider); const client = new MatrixClient(homeserverUrl, accessToken, storage, cryptoProvider);
AutojoinRoomsMixin.setupOnClient(client); AutojoinRoomsMixin.setupOnClient(client);
// Test logs, remove later
console.log("Your active homeserver is: " + homeserverUrl);
client.on("room.message", handleCommand); client.on("room.message", handleCommand);
@ -29,8 +37,17 @@ async function handleCommand(roomId: string, event: any) {
// Check to ensure that the `!hello` command is being run // Check to ensure that the `!hello` command is being run
const body = event['content']['body']; const body = event['content']['body'];
if (!body?.startsWith("!hello")) return; //if (!body?.startsWith("!hello")) return;
// Now that we've passed all the checks, we can actually act upon the command if(body?.includes("tiktok.com") && downloader.isValidUrl(body)) {
await client.replyNotice(roomId, event, "Hello world!"); await client.replyNotice(roomId, event, "You sent a valid TikTok URL");
}
if(body?.includes("vm.tiktok.com")) {
console.log("Short form TikTok URL detected... Unshortening...");
downloader.UnshortenUrl(body);
}
}
else {
await client.replyNotice(roomId, event, "You did not send a valid URL");
}
}