Skip to content

Commit

Permalink
feat: Temporary Cloudflare Bypass Hack - Will be replaced soon™
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Angelo <[email protected]>
  • Loading branch information
angeloanan committed Jul 17, 2020
1 parent 453fde9 commit 5125a19
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ BOTLISTSPACE_TOKEN=
# InfluxDB 2.0 Logging
INFLUX_TOKEN=
INFLUX_ORG=
INFLUX_BUCKET=
INFLUX_BUCKET=

# Cloudflare I'm Under Attack Bypass Hack
CF_CLEARANCE=
13 changes: 12 additions & 1 deletion api/genius/scrapeLyrics.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* eslint-disable quote-props */
// Goal: Genius URL => Lyrics
// Things that can go wrong: Lyrics is empty

import fetch from 'node-fetch'
import cheerio from 'cheerio'
require('dotenv').config()

// Genius scraping is very unreliable
// Sometimes, Genius doesn't display the selected tag
// Limiting this to 5 because 2 tries should be enough to get the lyrics
// Might wanna to move to a glitch.me API, using cheerio to get the lyrics
export async function scrapeUntilSuccess (url: string): Promise<string> {
return fetch(url)
return fetch(url, {
headers: {
'Cookie': [
`cf_clearance=${process.env.CF_CLEARANCE}`
].join('; '),
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.64'
}
})
.then(res => res.text())
.then(async res => {
// Using Cheerio to parse HTML, accessible using JQuery syntax
Expand Down
4 changes: 2 additions & 2 deletions events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const presenceData: PresenceData = {
status: 'dnd',
afk: false,
activity: {
type: 'PLAYING',
name: 'Maintenance mode'
type: 'WATCHING',
name: `for ~!help | ${version}`
}
}

Expand Down
23 changes: 5 additions & 18 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,19 @@ bot.on('message', async (message) => {
case 'help':
require('./commands/help').exec(bot, message)
break

// case 's':
// case 'search':
// case 'lyrics':
// require('./commands/search').search(bot, message)
// break
// case 'np':
// case 'nowplaying':
// require('./commands/search').nowPlaying(bot, message)
// break
// case 'autosearch':
// case 'auto':
// require('./commands/autosearch').exec(bot, message)
// break

// Only if Maintenance
case 's':
case 'search':
case 'lyrics':
require('./commands/search').search(bot, message)
break
case 'np':
case 'nowplaying':
require('./commands/search').nowPlaying(bot, message)
break
case 'autosearch':
case 'auto':
require('./utils/maintenance').exec(bot, message)
require('./commands/autosearch').exec(bot, message)
break

case 'support':
message.channel.send('**Support the bot (and the creator) here**: https://lyrics-finder.angeloanan.xyz/support')
break
Expand Down

0 comments on commit 5125a19

Please sign in to comment.