fm: Add the possibility to specify period
This commit is contained in:
parent
e5862a323b
commit
3c7d0a6c28
2 changed files with 20 additions and 2 deletions
|
@ -21,7 +21,9 @@ module.exports = {
|
||||||
break;
|
break;
|
||||||
case "toptracks":
|
case "toptracks":
|
||||||
case "tt":
|
case "tt":
|
||||||
|
args.shift();
|
||||||
sendText = await getTopTracks(message.author.id, args);
|
sendText = await getTopTracks(message.author.id, args);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,30 @@
|
||||||
|
|
||||||
const getFmUsername = require("./getFmUsername")
|
const getFmUsername = require("./getFmUsername")
|
||||||
|
|
||||||
module.exports = async function (userID, options) {
|
module.exports = async function (userID, option) {
|
||||||
let lastfmUsername = await getFmUsername(userID);
|
let lastfmUsername = await getFmUsername(userID);
|
||||||
let sendText = "";
|
let sendText = "";
|
||||||
let tracks = [];
|
let tracks = [];
|
||||||
|
const options = {
|
||||||
|
"alltime": "overall",
|
||||||
|
"weekly": "7day",
|
||||||
|
"monthly": "1month",
|
||||||
|
"quarterly": "3month",
|
||||||
|
"halfyear": "6month",
|
||||||
|
"yearly": "12month",
|
||||||
|
undefined: "7day"
|
||||||
|
}
|
||||||
|
if(option.length === 0){
|
||||||
|
option[0] = "weekly"
|
||||||
|
}else {
|
||||||
|
option[0] = options[option[0]];
|
||||||
|
if(option[0] === undefined)
|
||||||
|
option[0] = options[option[0]];
|
||||||
|
}
|
||||||
const apiKey = process.env.LAST_FM_API_KEY;
|
const apiKey = process.env.LAST_FM_API_KEY;
|
||||||
if(lastfmUsername != undefined){
|
if(lastfmUsername != undefined){
|
||||||
tracks = await new Promise ((resolve, reject) => {
|
tracks = await new Promise ((resolve, reject) => {
|
||||||
fetch(`https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=${lastfmUsername}&api_key=${apiKey}&format=json`)
|
fetch(`https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=${lastfmUsername}&period${option[0]}&api_key=${apiKey}&format=json`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
for(let i = 0; i < 10; i++){
|
for(let i = 0; i < 10; i++){
|
||||||
|
|
Loading…
Add table
Reference in a new issue