-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
featfix: converter dev, textpro fix, misc feats
- Fixing TextPro returning 403, by adding spoofed user agent - Development of IG & TikTok downloader, not launch to prod because still have some bugs - Adding new command : .request (to request a feature and saves it to JSON) - Adding new command : .botinfo (to know the bot information) - Adding new entity in the env.ts : ownerName
- Loading branch information
1 parent
a41eac8
commit a2cab83
Showing
12 changed files
with
190 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { MessageMedia } from 'whatsapp-web.js'; | ||
import { Executor } from '@/command-hive'; | ||
import axios, { AxiosError } from 'axios'; | ||
import * as wweb from '@utils/wweb'; | ||
import * as logger from '@utils/logger'; | ||
import * as cheerio from 'cheerio'; | ||
import config from '@/env'; | ||
|
||
const IG_DOWNLOADER_URL = 'https://v3.igdownloader.app/api/ajaxSearch'; | ||
const SPOOFED_USER_AGENT = 'Mozilla (Firefox Inc.)'; | ||
|
||
type InstagramDom = { | ||
status: string, | ||
v?: string, | ||
data: string | ||
} | ||
|
||
type InstagramMedia = string | undefined; | ||
|
||
const retrieveInstagramDom = async (instagramUrl: string) => { | ||
const response = await axios.post(IG_DOWNLOADER_URL, { | ||
q: instagramUrl, | ||
}, { | ||
withCredentials: true, | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded', | ||
'User-Agent': SPOOFED_USER_AGENT | ||
} | ||
}); | ||
|
||
return response.data; | ||
} | ||
|
||
const processInstagramDom = (instagramDom: InstagramDom) => { | ||
if (instagramDom.v === undefined) return undefined; | ||
|
||
const $ = cheerio.load(instagramDom.data); | ||
const instagramMediaUrl: InstagramMedia = $('.download-items__btn').find('a.abutton').attr('href'); | ||
|
||
return instagramMediaUrl; | ||
} | ||
|
||
const downloadMedia = async (instagramMediaUrl: string) => { | ||
const response = await axios.get(instagramMediaUrl, { | ||
responseType: 'arraybuffer', | ||
headers: { | ||
'User-Agent': SPOOFED_USER_AGENT | ||
} | ||
}); | ||
|
||
return { | ||
media: Buffer.from(response.data, 'binary').toString('base64'), | ||
mime_type: response.headers['content-type'] | ||
}; | ||
} | ||
|
||
const instagramDownloader: Executor = async (client, message) => { | ||
const instagramUrl = message.body.split(' ')[1]; | ||
|
||
if (instagramUrl == undefined) { | ||
wweb.replyMessage(message, `${config.botShortName} tidak melihat adanya URL video IG kamu :(.\n\nGunakan format: \`.ig [URL video IG]\` ya!`); | ||
return 0; | ||
} | ||
|
||
try { | ||
const instagramDom: InstagramDom = await retrieveInstagramDom(instagramUrl); | ||
const instagramMediaUrl: InstagramMedia = processInstagramDom(instagramDom); | ||
|
||
if (instagramMediaUrl === undefined) { | ||
wweb.replyMessage(message, `${config.botShortName} tidak dapat memproses link IG kamu, coba salin ulang lagi dari Instagram nya ya !`); | ||
return 0; | ||
} | ||
|
||
wweb.replyMessage(message, `Tunggu sebentar ya, ${config.botShortName} sedang memproses link IG kamu...`); | ||
// const instagramMedia = await downloadMedia(instagramMediaUrl); | ||
|
||
downloadMedia(instagramMediaUrl).then(instagramMedia => { | ||
wweb.replyMessage(message, new MessageMedia(instagramMedia.mime_type, instagramMedia.media)); | ||
}); | ||
} catch (error) { | ||
|
||
const err = error as AxiosError; | ||
const contact = await message.getContact(); | ||
logger.logError('instagramDownloader - ' + err.cause ?? err.message + ' by ' + contact?.pushname ?? 'unknown'); | ||
wweb.replyMessage(message, `Maaf, ${config.botShortName} mengalami kegagalan saat memprosesnya. Silahkan coba kembali nanti ya! 🙏`); | ||
} | ||
} | ||
|
||
export { | ||
instagramDownloader | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Executor } from '@/command-hive'; | ||
import * as wweb from '@utils/wweb'; | ||
import config from '@/env'; | ||
|
||
const botInfo: Executor = async (client, message) => { | ||
const informationArray = [ | ||
`⚡Informasi tentang ${config.botName}⚡`, | ||
`Nama: ${config.botName}`, | ||
`Nama Panggilan: ${config.botShortName}`, | ||
`Owner: ${config.ownerName}\n`, | ||
|
||
'Tahun Rilis:' + 2024, | ||
'Versi Saat Ini:' + '1.3.0', | ||
'Teknologi Digunakan :', | ||
'- NodeJS', | ||
'- TypeScript', | ||
'- whatsapp-web.js (wwebjs.dev)', | ||
]; | ||
wweb.sendMessage(client, message.from, informationArray.join('\n')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Executor } from '@/command-hive'; | ||
import * as wweb from '@utils/wweb'; | ||
import fs from 'fs/promises'; | ||
|
||
const requestInfo: Executor = async (client, message) => { | ||
let request = message.body.split(' ').slice(1).join(' '); | ||
|
||
if (request == '') { | ||
wweb.replyMessage(message, 'Request/sarannya apa nih 😥?') | ||
return 0; | ||
} | ||
|
||
const contact = await message.getContact(); | ||
request = request + ' | oleh ' + contact?.pushname ?? 'unknown' | ||
await recordRequest(request) | ||
wweb.replyMessage(message, 'Terimakasih ! 😁'); | ||
} | ||
|
||
const recordRequest = async (text: string) => { | ||
fs.readFile('assets/feature-request.json', 'utf-8') | ||
.then(data => { | ||
const records = JSON.parse(data); | ||
records.push(text) | ||
fs.writeFile('assets/feature-request.json', JSON.stringify(records), 'utf-8') | ||
}) | ||
} | ||
|
||
export { | ||
requestInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters