From bb330559469a9a7e733a5dbab98106de2487b12d Mon Sep 17 00:00:00 2001 From: Levi Date: Mon, 26 Sep 2022 17:43:48 +0200 Subject: [PATCH] TikTok support --- README.md | 5 +- index.js | 152 +++++++++++++++++++++++++++++---------------------- package.json | 54 +++++++++--------- 3 files changed, 114 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 51f7f78..d51ab82 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,12 @@ Example: "port": "4000", -You can change which service to use for parsing Twitter and Instagram links. By default fxtwitter and ddinstagram are used, but you can change this to any of your choosing. +You can change which service to use for parsing links, simply edit the corresponding values with a service that offers the functionality. Example: "tweetParser": "https://twittpr.com/", - "instaParser": "https://ddinstagram.com/" + "instaParser": "https://ddinstagram.com/", + "tiktokParser": "https://www.vxtiktok.com/" It's important the full base url is in the string, like the example above, otherwise you may run into issues. diff --git a/index.js b/index.js index 06540e9..7027e1f 100644 --- a/index.js +++ b/index.js @@ -1,92 +1,112 @@ -const { Client, GatewayIntentBits } = require('discord.js'); const { - token, - port, - tweetParser, - instaParser, - tiktokParser, + Client, + GatewayIntentBits +} = require('discord.js'); +const { + token, + port, + tweetParser, + instaParser, + tiktokParser, } = require('./config.json'); const http = require('http'); // Create a new client instance const client = new Client({ - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - ], + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + ], }); - http.createServer((req, res) => { - res.writeHead(200, { 'Content-type': 'text/plain' }); - res.write('Hey'); - res.end(); + res.writeHead(200, { + 'Content-type': 'text/plain' + }); + res.write('Hey'); + res.end(); }).listen(port); - // When the client is ready, run this code (only once) client.once('ready', () => { - console.log('Ready!'); + console.log('Ready!'); }); - // Response client.on('messageCreate', async message => { - if (message.content.startsWith('https://twitter.com/')) { - const tweetURL = message.content.substring(20, message.content.length); - message.suppressEmbeds(true); - - const newmsg = tweetParser + tweetURL; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://twitter.com/')) { + const tweetURL = message.content.substring(20, message.content.length); + message.suppressEmbeds(true); + const newmsg = tweetParser + tweetURL; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - client.on('messageCreate', async message => { - if (message.content.startsWith('https://mobile.twitter.com/')) { - const mobiletweetURL = message.content.substring(27, message.content.length); - message.suppressEmbeds(true); - - const newmsg = tweetParser + mobiletweetURL; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://mobile.twitter.com/')) { + const mobiletweetURL = message.content.substring(27, message.content.length); + message.suppressEmbeds(true); + const newmsg = tweetParser + mobiletweetURL; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - client.on('messageCreate', async message => { - if (message.content.startsWith('https://instagram.com/')) { - const instaURL = message.content.substring(22, message.content.length); - message.suppressEmbeds(true); - - const newmsg = instaParser + instaURL; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://instagram.com/')) { + const instaURL = message.content.substring(22, message.content.length); + message.suppressEmbeds(true); + const newmsg = instaParser + instaURL; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - client.on('messageCreate', async message => { - if (message.content.startsWith('https://www.instagram.com/')) { - const instaURL2 = message.content.substring(26, message.content.length); - message.suppressEmbeds(true); - - const newmsg = instaParser + instaURL2; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://www.instagram.com/')) { + const instaURL2 = message.content.substring(26, message.content.length); + message.suppressEmbeds(true); + const newmsg = instaParser + instaURL2; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - client.on('messageCreate', async message => { - if (message.content.startsWith('https://tiktok.com/')) { - const tiktokURL = message.content.substring(19, message.content.length); - message.suppressEmbeds(true); - - const newmsg = tiktokParser + tiktokURL; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://tiktok.com/')) { + const tiktokURL = message.content.substring(19, message.content.length); + message.suppressEmbeds(true); + const newmsg = tiktokParser + tiktokURL; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - client.on('messageCreate', async message => { - if (message.content.startsWith('https://www.tiktok.com/')) { - const tiktokURL2 = message.content.substring(23, message.content.length); - message.suppressEmbeds(true); - - const newmsg = tiktokParser + tiktokURL2; - message.reply({ content: newmsg, allowedMentions: { repliedUser: false } }); - } + if(message.content.startsWith('https://www.tiktok.com/')) { + const tiktokURL2 = message.content.substring(23, message.content.length); + message.suppressEmbeds(true); + const newmsg = tiktokParser + tiktokURL2; + message.reply({ + content: newmsg, + allowedMentions: { + repliedUser: false + } + }); + } }); - // Login to Discord with your client's token client.login(token); \ No newline at end of file diff --git a/package.json b/package.json index 8268881..9fa6ab8 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,26 @@ { - "name": "mediafixer", - "version": "1.2.5", - "description": "Fixes broken twitter embeds by replying with a reformatted link.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/LeviSnoot/MediaFixer.git" - }, - "keywords": [ - "discord", - "twitter", - "embeds" - ], - "author": "Yber0 & LeviSnoot", - "license": "ISC", - "dependencies": { - "discord.js": "^14.4.0" - }, - "bugs": { - "url": "https://github.com/LeviSnoot/MediaFixer/issues" - }, - "homepage": "https://github.com/LeviSnoot/MediaFixer#readme", - "devDependencies": { - "eslint": "^8.23.1" - } -} + "name": "mediafixer", + "version": "1.2.5", + "description": "Fixes broken twitter embeds by replying with a reformatted link.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/LeviSnoot/MediaFixer.git" + }, + "keywords": ["discord", "twitter", "embeds"], + "author": "Yber0 & LeviSnoot", + "license": "ISC", + "dependencies": { + "discord.js": "^14.4.0" + }, + "bugs": { + "url": "https://github.com/LeviSnoot/MediaFixer/issues" + }, + "homepage": "https://github.com/LeviSnoot/MediaFixer#readme", + "devDependencies": { + "eslint": "^8.23.1" + } +} \ No newline at end of file