Skip to content

Commit

Permalink
new embed method
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-apprentice committed Jul 16, 2022
2 parents bf0ef66 + b26fba4 commit 7d09bdc
Show file tree
Hide file tree
Showing 11 changed files with 2,920 additions and 3,513 deletions.
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"coverage/"
],
"legacyWatch": true,
"exec": "npx etsc && node ./dist/index.js"
"exec": "npm run clearDistDirectory && npx etsc && node ./dist/index.js"
}
6,154 changes: 2,740 additions & 3,414 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"typescript": "^4.4.2"
},
"engines": {
Expand All @@ -57,7 +58,6 @@
"morgan": "^1.10.0",
"nodemon": "^2.0.12",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"typedi": "^0.10.0",
"winston": "^3.3.3",
Expand Down
1 change: 0 additions & 1 deletion src/commands/Base.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Message, Client as Context } from 'discord.js';
import { CommandResponse } from '../utils/command.utils';

export class BaseCommand {
async ready(_ctx: Context) {
Expand Down
76 changes: 76 additions & 0 deletions src/commands/dolar.command.ts
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();
37 changes: 20 additions & 17 deletions src/commands/game.command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Client as Context, Message } from 'discord.js';
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 { GameService } from '../services/index';
import { defaultEmbedData } from '../config/message.config';
import { setDefaultEmbedFooter } from '../config/message.config';

/**
* @description Bot command games are created in this file
Expand All @@ -29,22 +29,25 @@ class GameCommand implements BaseCommand {
command: 'iq',
},
];
const messageUtils = new MessageUtils();
const embed = messageUtils.buildEmbed({
title: 'Mensaje de ayuda',
fields: [
...commandList.map((v) => {
return {
name: v.command,
value: v.description,
inline: false,
};
}),
],
...defaultEmbedData,
});
/**
* @description Construct the embed message
*/

await messageUtils.sendMessageToChannel(embed, _msg.channelId);
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
Expand Down
34 changes: 34 additions & 0 deletions src/commands/main.command.ts
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);
}
}
77 changes: 12 additions & 65 deletions src/commands/rant.command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Client as Context, Message } from 'discord.js';
import { Client as Context, Message, MessageEmbed } from 'discord.js';
import { Command, Ready } from '../decorators';
import { CommandExecute } from '../decorators/command.decorator';
import { RantService } from '../services/rant.service';
import { CommandError } from '../utils/error.utils';
import { MessageUtils } from '../utils/message.utils';
import { BaseCommand } from './Base.command';
import { UserUtils } from '../utils/user.utils';
import { defaultEmbedData } from '../config/message.config';
import { setDefaultEmbedFooter } from '../config/message.config';
export class RantCommand implements BaseCommand {

@Command({ name: 'rant help', description: 'Muestra la lista de comandos del modulo' })
Expand All @@ -22,31 +22,23 @@ export class RantCommand implements BaseCommand {
description: 'La concha de tu madre AllBoys',
command: 'rant lcdtmAb',
},
{
name: 'list',
description: 'Muestra la lista de comandos del modulo',
command: 'rant list',
},
{
name: 'say',
description: 'Hace que el bot te salude en el canal actual',
command: 'rant say',
},
];
const messageUtils = new MessageUtils();
const embed = messageUtils.buildEmbed({
title: 'Mensaje de ayuda',
fields: [
...commandList.map(v => {
return {
name: v.command,
value: v.description,
inline: false,
};
}),
],
...defaultEmbedData,
});
const embed = new MessageEmbed();
embed.setTitle('Mensaje de ayuda');
embed.setFields(...commandList.map(v => {
return {
name: v.command,
value: v.description,
inline: false,
};
}));
setDefaultEmbedFooter(embed);

await messageUtils.sendMessageToChannel(embed, _msg.channelId);
}
Expand All @@ -73,51 +65,6 @@ export class RantCommand implements BaseCommand {
}
}

// TODO: Mover esto a donde corresponda
@Command({ name: 'rant list', description: 'Lista de comandos' })
async list(ctx: Context, msg: Message) {
const commandList = [];
CommandExecute.forEach((v) => {
commandList.push({
name: v.name,
description: v.description,
prefix: v.prefix,
});
});
const messageUtils = new MessageUtils();
const embed = messageUtils.buildEmbed({
isEmbed: true,
title: 'Lista de comandos',
fields: [
...commandList.map((v) => {
return {
name: `${v.prefix}${v.name}`,
value: v.description || 'Sin descripcion',
inline: false,
};
}),
{
name: 'Para mas informacion',
value: 'Para ver la descripcion de un comando use `<comando> help`',
inline: true,
},
],
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',
});
messageUtils.sendMessageToChannel(embed, msg.channel.id);
}

@Command({ name: 'rant say', description: 'Hace que el bot te salude en el canal actual' })
say(ctx: Context, msg: Message) {
const messageUtils = new MessageUtils();
Expand Down
21 changes: 7 additions & 14 deletions src/config/message.config.ts
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');
};
28 changes: 28 additions & 0 deletions src/services/dolar/dolar.service.ts
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();
1 change: 1 addition & 0 deletions src/services/index.ts
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';

0 comments on commit 7d09bdc

Please sign in to comment.