Compare commits
2 Commits
7ebc2b93b8
...
689821dd02
Author | SHA1 | Date |
---|---|---|
Thibaut Broggi | 689821dd02 | |
Thibaut Broggi | 81c9127153 |
|
@ -36,8 +36,24 @@ class GuildsManager {
|
||||||
if (!this.#guilds[guild_id]?.[guild_action.target]?.[guild_action.action]) {
|
if (!this.#guilds[guild_id]?.[guild_action.target]?.[guild_action.action]) {
|
||||||
message.channel.send(`The command ${guild_action.target} ${guild_action.action} is not implemented yet`)
|
message.channel.send(`The command ${guild_action.target} ${guild_action.action} is not implemented yet`)
|
||||||
} else {
|
} else {
|
||||||
const output = await this.#guilds[guild_id][guild_action.target][guild_action.action](guild_action)
|
try {
|
||||||
return output
|
const output = await this.#guilds[guild_id][guild_action.target][guild_action.action](guild_action)
|
||||||
|
return output
|
||||||
|
} catch (e) {
|
||||||
|
const error_message = await message.channel.send(":warning: Something went wrong. React with :eyes: to get more information about this error.")
|
||||||
|
error_message.react("👀")
|
||||||
|
error_message.awaitReactions((r, u) => r.emoji.name === "👀" && u.id !== error_message.author.id, {max: 1})
|
||||||
|
.then(() => {
|
||||||
|
message.channel.send(`Target manager: **${guild_action.target}** Action: **${guild_action.action}** Parameters: **${guild_action.params.join(', ')}**`
|
||||||
|
+ "\n"
|
||||||
|
+ `Original message: \`${guild_action.message}\``
|
||||||
|
+ "\n"
|
||||||
|
+ "```js\n"
|
||||||
|
+ e.stack
|
||||||
|
+ "\n```")
|
||||||
|
})
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,26 +15,21 @@ class Youtube {
|
||||||
* @return {Track[]} An array of objects representing the search results. <code>source</code> is set to <code>"youtube"</code>
|
* @return {Track[]} An array of objects representing the search results. <code>source</code> is set to <code>"youtube"</code>
|
||||||
*/
|
*/
|
||||||
async search_track(search) {
|
async search_track(search) {
|
||||||
try {
|
const req = await fetch('https://www.youtube.com/results?search_query='
|
||||||
const req = await fetch('https://www.youtube.com/results?search_query='
|
+ encodeURIComponent(search))
|
||||||
+ encodeURIComponent(search))
|
const body = await req.text()
|
||||||
const body = await req.text()
|
const json = JSON.parse(body.match(/ytInitialData = (.*);<\/script>/)[1])
|
||||||
const json = JSON.parse(body.match(/ytInitialData = (.*);<\/script>/)[1])
|
const results = json.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents[0].itemSectionRenderer.contents
|
||||||
const results = json.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents[0].itemSectionRenderer.contents
|
return results
|
||||||
return results
|
.filter(e => e.videoRenderer)
|
||||||
.filter(e => e.videoRenderer)
|
.map(e => {
|
||||||
.map(e => {
|
return new Track({
|
||||||
return new Track({
|
url: 'https://www.youtube.com/watch?v=' + e.videoRenderer.videoId,
|
||||||
url: 'https://www.youtube.com/watch?v=' + e.videoRenderer.videoId,
|
title: e.videoRenderer.title.runs[0].text,
|
||||||
title: e.videoRenderer.title.runs[0].text,
|
length: e.videoRenderer.lengthText.simpleText,
|
||||||
length: e.videoRenderer.lengthText.simpleText,
|
source: 'youtube',
|
||||||
source: 'youtube',
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
} catch(e) {
|
})
|
||||||
console.error(e)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue