mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Remove guess-song :(
This commit is contained in:
@@ -39,8 +39,6 @@ GOV_KEY=
|
||||
IDIOT_URL=
|
||||
REMOVEBG_KEY=
|
||||
SAUCENAO_KEY=
|
||||
SPOTIFY_KEY=
|
||||
SPOTIFY_SECRET=
|
||||
THECATAPI_KEY=
|
||||
THEDOGAPI_KEY=
|
||||
WEBSTER_KEY=
|
||||
|
||||
@@ -72,7 +72,6 @@ Only if you want to use the DECTalk command.
|
||||
* `IDIOT_URL` is a URL, ideally to the [Wikipedia page of an idiot](https://en.wikipedia.org/wiki/Donald_Trump). By default, it will reply with "_Stares at you._"
|
||||
* `REMOVEBG_KEY` is your API key for remove.bg. You can get one [here](https://www.remove.bg/api).
|
||||
* `SAUCENAO_KEY` is your API key for SauceNAO. Register, login, and click [here](https://saucenao.com/user.php?page=search-api) to get one.
|
||||
* `SPOTIFY_KEY` and `SPOTIFY_SECRET` are your key and secret for the Spotify API. You can get one by [following these instructions](https://developer.spotify.com/documentation/web-api).
|
||||
* `THECATAPI_KEY` is your API key for The Cat API. You can get one [here](https://thecatapi.com/).
|
||||
* `THEDOGAPI_KEY` is your API key for The Dog API. You can get one [here](https://thedogapi.com/).
|
||||
* `WEBSTER_KEY` is your API key for Merriam-Webster. You can get one [here](https://dictionaryapi.com/).
|
||||
@@ -102,7 +101,7 @@ Only if you want to use the DECTalk command.
|
||||
18. Start Xiao up!
|
||||
|
||||
## Commands
|
||||
Total: 518
|
||||
Total: 517
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -343,7 +342,6 @@ Total: 518
|
||||
* **chance:** Attempt to win with a 1 in 1000 (or your choice) chance of winning.
|
||||
* **doors:** Open the right door, and you win the money! Make the wrong choice, and you get the fire!
|
||||
* **google-feud:** Attempt to determine the top suggestions for a Google search.
|
||||
* **guess-song:** Guess what song is playing.
|
||||
* **hangman:** Prevent a man from being hanged by guessing a word as fast as you can.
|
||||
* **hearing-test:** Test your hearing.
|
||||
* **horse-info:** Responds with detailed information on a horse.
|
||||
@@ -1017,8 +1015,6 @@ Total: 518
|
||||
* **google-feud:**
|
||||
- [Google](https://www.google.com/) (Autofill API)
|
||||
- [Google Feud](http://www.googlefeud.com/) (Original Game)
|
||||
* **guess-song:**
|
||||
- [Spotify](https://www.spotify.com/us/) ([API](https://developer.spotify.com/))
|
||||
* **hangman:**
|
||||
- [Grady Ward](https://en.wikipedia.org/wiki/Grady_Ward) ([Moby Word Lists](http://www.gutenberg.org/ebooks/3201))
|
||||
- [Merriam-Webster's Collegiate® Dictionary](https://www.merriam-webster.com/) ([API](https://dictionaryapi.com/products/api-collegiate-dictionary))
|
||||
|
||||
@@ -104,10 +104,6 @@ client.on('clientReady', async () => {
|
||||
client.registry.commands.get('apod').disable();
|
||||
client.logger.info('[DISABLED] No GOV_KEY in env. apod has been disabled.');
|
||||
}
|
||||
if (!process.env.SPOTIFY_KEY || !process.env.SPOTIFY_SECRET) {
|
||||
client.registry.commands.get('guess-song').disable();
|
||||
client.logger.info('[DISABLED] No SPOTIFY_KEY or SPOTIFY_SECRET in env. guess-song has been disabled.');
|
||||
}
|
||||
if (!process.env.THECATAPI_KEY) {
|
||||
client.registry.commands.get('cat').disable();
|
||||
client.logger.info('[DISABLED] No THECATAPI_KEY in env. cat has been disabled.');
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"global": "37i9dQZEVXbNG2KDcFcKOF",
|
||||
"us": "37i9dQZEVXbLp5XoPON0wI",
|
||||
"uk": "37i9dQZEVXbMwmF30ppw50",
|
||||
"jp": "37i9dQZEVXbKqiTGXuCOsB",
|
||||
"kr": "37i9dQZEVXbJZGli0rRP3r",
|
||||
"es": "37i9dQZEVXbKUoIkUXteF6",
|
||||
"50s": "37i9dQZF1DWSV3Tk4GO2fq",
|
||||
"60s": "37i9dQZF1DXaKIA8E7WcJj",
|
||||
"70s": "37i9dQZF1DWTJ7xPn4vNaz",
|
||||
"80s": "37i9dQZF1DX4UtSsGT1Sbe",
|
||||
"90s": "37i9dQZF1DXbTxeAdrVG2l",
|
||||
"2000s": "37i9dQZF1DX4o1oenSJRJd",
|
||||
"anime": "10FdtvubPhN5FsHPPJ5Cut",
|
||||
"swift": "37i9dQZF1DX5KpP2LN299J",
|
||||
"beethoven": "37i9dQZF1DX12YIlzNkccL",
|
||||
"weezer": "37i9dQZF1DZ06evO1VmDYs",
|
||||
"owlcity": "37i9dQZF1DZ06evO00faq4",
|
||||
"fadedpaperfigures": "37i9dQZF1DZ06evO1dk4k8"
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { PermissionFlagsBits } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const cheerio = require('cheerio');
|
||||
const { Readable } = require('stream');
|
||||
const { reactIfAble, base64, list } = require('../../util/Util');
|
||||
const playlists = require('../../assets/json/guess-song');
|
||||
const demaster = /(\s(\(|-\s+))((199\d|20[0-2]\d)\s+)?(Remast|Live|Mono|From|Feat|Original|Motion|Deluxe).*/i;
|
||||
const { SPOTIFY_KEY, SPOTIFY_SECRET } = process.env;
|
||||
|
||||
module.exports = class GuessSongCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'guess-song',
|
||||
aliases: ['song-guess', 'song-game', 'music-guess', 'guess-music', 'music-game'],
|
||||
group: 'games-sp',
|
||||
description: 'Guess what song is playing.',
|
||||
throttling: {
|
||||
usages: 2,
|
||||
duration: 15
|
||||
},
|
||||
guildOnly: true,
|
||||
userPermissions: [PermissionFlagsBits.Connect, PermissionFlagsBits.Speak],
|
||||
clientPermissions: [PermissionFlagsBits.AttachFiles],
|
||||
game: true,
|
||||
credit: [
|
||||
{
|
||||
name: 'Spotify',
|
||||
url: 'https://www.spotify.com/us/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://developer.spotify.com/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'chart',
|
||||
type: 'string',
|
||||
oneOf: Object.keys(playlists),
|
||||
parse: chart => chart.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.token = null;
|
||||
this.charts = new Map();
|
||||
this.cache = new Map();
|
||||
}
|
||||
|
||||
async run(msg, { chart }) {
|
||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||
if (!connection) {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
|
||||
if (!this.token) await this.fetchToken();
|
||||
const data = await this.fetchRandomSong(chart);
|
||||
const { body: previewBody } = await request.get(data.preview);
|
||||
connection.play(Readable.from([previewBody]));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
await msg.reply('**You have 30 seconds, what song is this?**');
|
||||
const msgs = await msg.channel.awaitMessages({
|
||||
filter: res => res.author.id === msg.author.id,
|
||||
max: 1,
|
||||
time: 30000
|
||||
});
|
||||
connection.stop();
|
||||
if (!msgs.size) return msg.reply(`Time! It's **${data.name}** by **${data.artist}**!`);
|
||||
const guess = msgs.first().content.toLowerCase();
|
||||
if (!guess.includes(data.name.toLowerCase()) && !guess.includes(data.shortName.toLowerCase())) {
|
||||
return msg.reply(`Nope! It's **${data.name}** by **${data.artist}**!`);
|
||||
}
|
||||
return msg.reply(`Nice! It's **${data.name}** by **${data.artist}**!`);
|
||||
}
|
||||
|
||||
async fetchCharts(playlist) {
|
||||
if (this.charts.has(playlist)) return this.charts.get(playlist);
|
||||
const { body } = await request
|
||||
.get(`https://api.spotify.com/v1/playlists/${playlists[playlist]}/tracks`)
|
||||
.set({ Authorization: `Bearer ${this.token}` })
|
||||
.query({
|
||||
market: 'US',
|
||||
fields: 'items(track(id))',
|
||||
limit: 100
|
||||
});
|
||||
const songList = body.items.map(item => item.track.id);
|
||||
this.charts.set(playlist, songList);
|
||||
setTimeout(() => this.charts.delete(playlist), 4.32e+7);
|
||||
return songList;
|
||||
}
|
||||
|
||||
async fetchRandomSong(playlist) {
|
||||
const songs = await this.fetchCharts(playlist);
|
||||
const choice = songs[Math.floor(Math.random() * songs.length)];
|
||||
return this.fetchSongPreview(choice);
|
||||
}
|
||||
|
||||
async fetchSongPreview(id) {
|
||||
if (this.cache.has(id)) return this.cache.get(id);
|
||||
const { body } = await request
|
||||
.get(`https://api.spotify.com/v1/tracks/${id}`)
|
||||
.set({ Authorization: `Bearer ${this.token}` })
|
||||
.query({ market: 'US' });
|
||||
let previewURL = body.preview_url;
|
||||
if (!body.preview_url) previewURL = await this.fetchAlternativePreview(id);
|
||||
const result = {
|
||||
id,
|
||||
name: body.name,
|
||||
shortName: body.name.replace(demaster, ''),
|
||||
artist: list(body.artists.map(artist => artist.name)),
|
||||
preview: previewURL
|
||||
};
|
||||
this.cache.set(id, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
async fetchAlternativePreview(id) {
|
||||
const { text } = await request.get(`https://open.spotify.com/embed/track/${id}`);
|
||||
const $ = cheerio.load(text);
|
||||
const body = JSON.parse(decodeURIComponent($('script[id="__NEXT_DATA__"]')[0].children[0].data));
|
||||
return body.props.pageProps.state.data.entity.audioPreview.url;
|
||||
}
|
||||
|
||||
async fetchToken() {
|
||||
const { body } = await request
|
||||
.post('https://accounts.spotify.com/api/token')
|
||||
.set({
|
||||
Authorization: `Basic ${base64(`${SPOTIFY_KEY}:${SPOTIFY_SECRET}`)}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
.send('grant_type=client_credentials');
|
||||
this.token = body.access_token;
|
||||
setTimeout(() => { this.token = null; }, body.expires_in * 1000);
|
||||
return body;
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "156.0.0",
|
||||
"version": "157.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user