Added URL checking
This commit is contained in:
		
							
								
								
									
										23
									
								
								index.ts
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								index.ts
									
									
									
									
									
								
							@@ -5,11 +5,16 @@ import {
 | 
			
		||||
    RustSdkCryptoStorageProvider
 | 
			
		||||
} from "matrix-bot-sdk";
 | 
			
		||||
 | 
			
		||||
//Import 
 | 
			
		||||
import { VidDownload } from "./ttDownloader";
 | 
			
		||||
let downloader = new VidDownload;
 | 
			
		||||
 | 
			
		||||
//import config data
 | 
			
		||||
import settings from "./config/config.Dev.json";
 | 
			
		||||
 | 
			
		||||
const homeserverUrl = settings.matrixAddress;
 | 
			
		||||
const accessToken = settings.accessToken;
 | 
			
		||||
const ptInstance = settings.ptInstance;
 | 
			
		||||
 | 
			
		||||
const storage = new SimpleFsStorageProvider("./config/bot.json");
 | 
			
		||||
const cryptoProvider = new RustSdkCryptoStorageProvider("./config/crypto");
 | 
			
		||||
@@ -17,6 +22,9 @@ const cryptoProvider = new RustSdkCryptoStorageProvider("./config/crypto");
 | 
			
		||||
const client = new MatrixClient(homeserverUrl, accessToken, storage, cryptoProvider);
 | 
			
		||||
AutojoinRoomsMixin.setupOnClient(client);
 | 
			
		||||
 | 
			
		||||
// Test logs, remove later
 | 
			
		||||
console.log("Your active homeserver is: " + homeserverUrl);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
    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
 | 
			
		||||
    await client.replyNotice(roomId, event, "Hello world!");
 | 
			
		||||
    if(body?.includes("tiktok.com") && downloader.isValidUrl(body)) {
 | 
			
		||||
        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");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user