mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 22:01:54 +02:00
Currency Converter
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const request = require('superagent');
|
||||
const codes = require('./codes');
|
||||
|
||||
module.exports = class CurrencyCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'currency',
|
||||
group: 'random',
|
||||
memberName: 'currentUser',
|
||||
description: 'Converts from one currency to another.',
|
||||
details: `**Codes:** ${codes.join(', ')}`,
|
||||
args: [
|
||||
{
|
||||
key: 'base',
|
||||
prompt: 'What currency code do you want to use as the base?',
|
||||
type: 'string',
|
||||
validate: base => {
|
||||
if(codes[base.toUpperCase()])
|
||||
return true;
|
||||
return `${base} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
|
||||
},
|
||||
parse: base => base.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'to',
|
||||
prompt: 'What currency code do you want to convert to?',
|
||||
type: 'string',
|
||||
validate: to => {
|
||||
if(codes[to.toUpperCase()])
|
||||
return true;
|
||||
return `${to} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
|
||||
},
|
||||
parse: code => code.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How much money should be converted? Do not use symbols.',
|
||||
type: 'integer'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
const { base, to, amount } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://api.fixer.io/latest?base=${base}`);
|
||||
const rate = body[to];
|
||||
const converted = rate * amount;
|
||||
return msg.say(`${amount} ${base} is ${converted} ${to}.`);
|
||||
} catch(err) {
|
||||
return msg.say('An Unknown Error Occurred.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
[
|
||||
"AUD",
|
||||
"BGN",
|
||||
"BRL",
|
||||
"CAD",
|
||||
"CHF",
|
||||
"CNY",
|
||||
"CZK",
|
||||
"DKK",
|
||||
"GBP",
|
||||
"HKD",
|
||||
"HRK",
|
||||
"HUF",
|
||||
"IDR",
|
||||
"ILS",
|
||||
"INR",
|
||||
"JPY",
|
||||
"KRW",
|
||||
"MXN",
|
||||
"MYR",
|
||||
"NOK",
|
||||
"NZD",
|
||||
"PHP",
|
||||
"PLN",
|
||||
"RON",
|
||||
"RUB",
|
||||
"SEK",
|
||||
"SGD",
|
||||
"THB",
|
||||
"TRY",
|
||||
"ZAR",
|
||||
"EUR"
|
||||
]
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "18.1.1",
|
||||
"version": "18.2.0",
|
||||
"description": "A Discord Bot",
|
||||
"main": "shardingmanager.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user