forked from ScorpionConMate/matebotJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,920 additions
and
3,513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Client as Context, Message, MessageEmbed } from 'discord.js'; | ||
import { Command, Ready } from '../decorators'; | ||
import { MessageUtils } from '../utils/message.utils'; | ||
import { BaseCommand } from './Base.command'; | ||
import { DolarService } from '../services/index'; | ||
import { setDefaultEmbedFooter } from '../config/message.config'; | ||
|
||
/** | ||
* @description Bot command utils for currencies are created on this file | ||
*/ | ||
class DolarCommand implements BaseCommand { | ||
/** | ||
* @description Help command to know about this module | ||
* @param {Context} _ctx | ||
* @param {Message} _msg | ||
* @return {Promise<void>} | ||
*/ | ||
@Command({ name: 'dolar help', description: 'Muestra la lista de comandos del modulo' }) | ||
async help(_ctx: Context, _msg: Message): Promise<void> { | ||
const commandList = [ | ||
{ | ||
name: 'help', | ||
description: 'Muestra la lista de comandos del modulo', | ||
command: 'dolar help', | ||
}, | ||
{ | ||
name: 'dolarblue', | ||
description: 'Trae el valor del dolar blue, tomado de bluelytics', | ||
command: 'dolarblue', | ||
}, | ||
]; | ||
|
||
/** | ||
* @description Construct the embed message | ||
*/ | ||
|
||
const messageUtils = new MessageUtils(); | ||
const newEmbed = new MessageEmbed(); | ||
newEmbed.setTitle('Mensaje de ayuda'); | ||
newEmbed.setFields( | ||
...commandList.map((v) => { | ||
return { | ||
name: v.command, | ||
value: v.description, | ||
inline: false, | ||
}; | ||
}), | ||
); | ||
setDefaultEmbedFooter(newEmbed); | ||
/** Send message to the channel */ | ||
await messageUtils.sendMessageToChannel(newEmbed, _msg.channelId); | ||
} | ||
|
||
/** | ||
* @description When the bot is ready do something | ||
*/ | ||
@Ready() | ||
async ready(_ctx: Context) { | ||
console.log('Dolar ready!'); | ||
} | ||
/** | ||
* @param {Context} _ctx | ||
* @param {Message} msg | ||
* @description Returns a string with the average price of the ARS/USD pair | ||
* @return {Promise<void>} | ||
*/ | ||
@Command({ name: 'dolarblue' }) | ||
async dolarblue(_ctx: Context, msg: Message): Promise<void> { | ||
const newMessage = new MessageUtils(); | ||
const dolarAVG = await DolarService.getData(); | ||
/** Send message to the channel */ | ||
newMessage.sendMessageToChannel(dolarAVG, msg.channelId); | ||
} | ||
} | ||
|
||
export default new DolarCommand(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Client, Message, MessageEmbed } from 'discord.js'; | ||
import { setDefaultEmbedFooter } from '../config/message.config'; | ||
import { Command, Ready } from '../decorators'; | ||
import { CommandExecute } from '../decorators/command.decorator'; | ||
import { MessageUtils } from '../utils/message.utils'; | ||
import { BaseCommand } from './Base.command'; | ||
|
||
export class MainCommand implements BaseCommand { | ||
@Ready() | ||
async ready(_ctx: Client<boolean>): Promise<void> { | ||
console.log('Main command ready!'); | ||
} | ||
|
||
@Command({ name: 'help', description: 'Lista de todos los comandos disponibles' }) | ||
async help(_ctx: Client<boolean>, _msg: Message): Promise<void> { | ||
const commandList = []; | ||
CommandExecute.forEach((v) => { | ||
commandList.push({ | ||
name: v.name, | ||
description: v.description, | ||
prefix: v.prefix, | ||
}); | ||
}); | ||
const messageUtils = new MessageUtils(); | ||
const embed2 = new MessageEmbed(); | ||
embed2.setTitle('Lista de comandos'); | ||
embed2.setColor('#0099ff'); | ||
commandList.forEach(v=> { | ||
embed2.addField(`${v.prefix}${v.name}`, v.description || 'Sin descripcion', false); | ||
}); | ||
setDefaultEmbedFooter(embed2); | ||
messageUtils.sendMessageToChannel(embed2, _msg.channel.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
import { MessageEmbedCustom, MessageEmbedUser } from '../@types'; | ||
import { MessageEmbed } from 'discord.js'; | ||
|
||
export const defaultEmbedData: MessageEmbedCustom | MessageEmbedUser = { | ||
author: { | ||
name: 'Bondiol Bot Helper', | ||
iconURL: | ||
'https://scontent.faep4-3.fna.fbcdn.net/v/t1.6435-9/33791064_156169605239071_1345637335718428672_n.png?_nc_cat=103&ccb=1-7&_nc_sid=85a577&efg=eyJpIjoidCJ9&_nc_eui2=AeFpXBDaH5oJkRes3rd2RWjiWai0_5pKCOlZqLT_mkoI6dU4CD3NPLWkce68nEs1tpNWuJIPXDyQntfvE-iSS7KK&_nc_ohc=rlyBUrwsx6cAX_Dkh0f&_nc_ht=scontent.faep4-3.fna&oh=00_AT-WwRRIIjxVkqAGn7JYeK7Fl_fwtT-ZzC-zEb8k3_Lg8Q&oe=62F63DEB', | ||
}, | ||
footer: { | ||
text: 'Gracias por usar al Bondiol Bot Helper', | ||
}, | ||
image: 'https://pbs.twimg.com/media/D723tWPWsAA2jrP.png', | ||
color: [0, 194, 3], | ||
thumbnail: | ||
'https://scontent.faep4-3.fna.fbcdn.net/v/t1.6435-9/33791064_156169605239071_1345637335718428672_n.png?_nc_cat=103&ccb=1-7&_nc_sid=85a577&efg=eyJpIjoidCJ9&_nc_eui2=AeFpXBDaH5oJkRes3rd2RWjiWai0_5pKCOlZqLT_mkoI6dU4CD3NPLWkce68nEs1tpNWuJIPXDyQntfvE-iSS7KK&_nc_ohc=rlyBUrwsx6cAX_Dkh0f&_nc_ht=scontent.faep4-3.fna&oh=00_AT-WwRRIIjxVkqAGn7JYeK7Fl_fwtT-ZzC-zEb8k3_Lg8Q&oe=62F63DEB', | ||
export const setDefaultEmbedFooter = (embed: MessageEmbed) => { | ||
embed.setAuthor('Bondiol Bot Helper', 'https://scontent.faep4-3.fna.fbcdn.net/v/t1.6435-9/33791064_156169605239071_1345637335718428672_n.png?_nc_cat=103&ccb=1-7&_nc_sid=85a577&efg=eyJpIjoidCJ9&_nc_eui2=AeFpXBDaH5oJkRes3rd2RWjiWai0_5pKCOlZqLT_mkoI6dU4CD3NPLWkce68nEs1tpNWuJIPXDyQntfvE-iSS7KK&_nc_ohc=rlyBUrwsx6cAX_Dkh0f&_nc_ht=scontent.faep4-3.fna&oh=00_AT-WwRRIIjxVkqAGn7JYeK7Fl_fwtT-ZzC-zEb8k3_Lg8Q&oe=62F63DEB'); | ||
embed.setFooter('Gracias por usar al Bondiol Bot Helper'); | ||
embed.setImage('https://pbs.twimg.com/media/D723tWPWsAA2jrP.png'); | ||
embed.setColor([0, 194, 3]); | ||
embed.setThumbnail('https://scontent.faep4-3.fna.fbcdn.net/v/t1.6435-9/33791064_156169605239071_1345637335718428672_n.png?_nc_cat=103&ccb=1-7&_nc_sid=85a577&efg=eyJpIjoidCJ9&_nc_eui2=AeFpXBDaH5oJkRes3rd2RWjiWai0_5pKCOlZqLT_mkoI6dU4CD3NPLWkce68nEs1tpNWuJIPXDyQntfvE-iSS7KK&_nc_ohc=rlyBUrwsx6cAX_Dkh0f&_nc_ht=scontent.faep4-3.fna&oh=00_AT-WwRRIIjxVkqAGn7JYeK7Fl_fwtT-ZzC-zEb8k3_Lg8Q&oe=62F63DEB'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import axios from 'axios'; | ||
|
||
class DolarService { | ||
/** | ||
* @description Static messages for the service | ||
*/ | ||
private readonly baseURL: string = 'https://api.bluelytics.com.ar/v2/latest'; | ||
private readonly baseMessage: string = '💵 El precio average del dolar blue es '; | ||
private readonly sourceApi: string = 'El valor es tomado de -> https://bluelytics.com.ar/#!/'; | ||
|
||
/** | ||
* @description Get the avg price of the USD currency against the ARS | ||
* @returns {Promise<String>} Response for the channel in a template String | ||
*/ | ||
|
||
async getData(): Promise<string> { | ||
try { | ||
const response = await axios.get(this.baseURL); | ||
const data = await response.data; | ||
const price = data.blue?.value_avg; | ||
return `${this.baseMessage} ${price} 💵 \nℹ️ ${this.sourceApi}`; | ||
} catch (err) { | ||
throw new Error(err.message); | ||
} | ||
} | ||
} | ||
|
||
export default new DolarService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as GameService } from './game/game.service'; | ||
export { default as DolarService } from './dolar/dolar.service'; |