Haha-Yes/commands/utility/wallpaper.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-02-18 18:50:29 +01:00
const { Command } = require('discord-akairo');
const fetch = require('node-fetch');
class wallpaperCommand extends Command {
constructor() {
super('wallpaper', {
aliases: ['wallpaper'],
category: 'utility',
2020-02-18 18:50:29 +01:00
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
args: [
{
id: 'region',
type: 'string',
match: 'rest',
}
],
2020-02-18 18:50:29 +01:00
description: {
content: 'Show the Bing wallpaper of the day, can use any of the following region: zh-CN, en-US, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA',
usage: '[region]',
examples: ['', 'zh-CN']
2020-02-18 18:50:29 +01:00
}
});
}
async exec(message, args) {
let mkt = args.region;
2020-02-18 19:49:47 +01:00
if (!args.region) mkt = 'en-US';
if (!['zh-CN', 'en-US', 'ja-JP', 'en-AU', 'en-UK', 'de-DE', 'en-NZ', 'en-CA'].includes(mkt)) return message.channel.send('Please choose a valid region settings: zh-CN, en-US, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA');
fetch(`https://bing.biturl.top/?mkt=${mkt}`)
2020-02-18 18:50:29 +01:00
.then(res => {
return res.json();
})
.then(res => {
const wallpaperEmbed = this.client.util.embed()
.setColor(message.member.displayHexColor)
.setTitle('Bing wallpaper of the day')
.addField('Copyright', `[${res.copyright}](${res.copyright_link})`)
2020-02-21 15:17:07 +01:00
.setDescription(`[1366](https://bing.biturl.top/?resolution=1366&format=image&mkt=${mkt}) | [1920](https://bing.biturl.top/?resolution=1920&format=image&mkt=${mkt})`)
2020-02-18 18:50:29 +01:00
.setImage(res.url);
return message.channel.send(wallpaperEmbed);
});
}
}
module.exports = wallpaperCommand;