Skip to content

Commit

Permalink
refactor: use base embed from client
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhermeasper committed Mar 31, 2024
1 parent 53b65cd commit 17a347a
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 56 deletions.
12 changes: 3 additions & 9 deletions src/bot/commands/slashCommands/anom.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
SlashCommandBuilder,
EmbedBuilder,
ChannelType,
TextChannel,
} from 'discord.js';
import { SlashCommandBuilder, ChannelType, TextChannel } from 'discord.js';

import { SlashCommand } from '@marquinhos/types';

Expand All @@ -29,11 +24,10 @@ export const anom: SlashCommand = {
execute: async (interaction) => {
const channel = interaction.options.get('canal')?.channel as TextChannel;
const message = interaction.options.get('mensagem')?.value as string;
const anomEmbed = interaction.client.baseEmbed();
channel.send({
embeds: [
new EmbedBuilder()
.setDescription(message)
.setTitle('👀 Alguém disse isso:'),
anomEmbed.setTitle('👀 Alguém disse isso:').setDescription(message),
],
});
},
Expand Down
7 changes: 3 additions & 4 deletions src/bot/commands/slashCommands/audio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder } from 'discord.js';
import { join } from 'path';
import { readdirSync } from 'fs';

Expand Down Expand Up @@ -39,12 +39,11 @@ export const audio: SlashCommand = {
execute: (interaction) => {
const channel = voiceChannelPresence(interaction);
const file = interaction.options.get('audio');
const audioEmbed = interaction.client.baseEmbed();
playAudio(interaction, channel, file?.value as string);
interaction.reply({
embeds: [
new EmbedBuilder().setDescription(
`Reproduzindo ${file?.value as string}`
),
audioEmbed.setDescription(`Reproduzindo ${file?.value as string}`),
],
});
},
Expand Down
13 changes: 2 additions & 11 deletions src/bot/commands/slashCommands/balance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlashCommandBuilder, EmbedBuilder, GuildMember } from 'discord.js';
import { SlashCommandBuilder, GuildMember } from 'discord.js';

import { SlashCommand } from '@marquinhos/types';
import { getCoinBalance } from '@marquinhos/services/coinBalanceManager';
Expand All @@ -13,16 +13,7 @@ export const balance: SlashCommand = {
interaction.guild?.id ?? ''
);

const balanceEmbed = new EmbedBuilder();

balanceEmbed
.setColor('#0099ff')
.setThumbnail(interaction.user.displayAvatarURL())
.setTimestamp()
.setFooter({
text: 'Marquinhos Bot ™️',
iconURL: interaction.client.user?.displayAvatarURL(),
});
const balanceEmbed = interaction.client.baseEmbed();

if (balance === null) {
balanceEmbed
Expand Down
13 changes: 3 additions & 10 deletions src/bot/commands/slashCommands/balanceOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import {
} from '@marquinhos/services/coinBalanceManager';
import { BalanceChangeStatus, BalanceOperationType } from '@marquinhos/types';
import {
BaseInteraction,
CommandInteraction,
CommandInteractionOptionResolver,
EmbedBuilder,
PermissionsBitField,
} from 'discord.js';

Expand Down Expand Up @@ -88,14 +86,9 @@ export const balanceOperation = {

const amount = interaction.options.get('valor')?.value as number;

const baseEmbed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Operação no saldo')
.setTimestamp()
.setFooter({
text: 'Marquinhos Bot ™️',
iconURL: interaction.client.user?.displayAvatarURL(),
});
const baseEmbed = interaction.client
.baseEmbed()
.setTitle('Operação no saldo');

let operationResult: BalanceChangeStatus & {
operationType: BalanceOperationType | null;
Expand Down
4 changes: 3 additions & 1 deletion src/bot/commands/slashCommands/checkIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const checkIn: SlashCommand = {
const guildName = interaction.guild?.name as string;
interaction.reply({
embeds: [
new EmbedBuilder().setDescription(checkInReply(member, guildName)),
interaction.client
.baseEmbed()
.setDescription(checkInReply(member, guildName)),
],
});
},
Expand Down
9 changes: 4 additions & 5 deletions src/bot/commands/slashCommands/configRoles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder } from 'discord.js';

import { SlashCommand } from '@marquinhos/types';
import GuildModel from '@schemas/guild';
Expand Down Expand Up @@ -30,12 +30,11 @@ export const configRoles: SlashCommand = {
const roleType = interaction.options.get('tipo_do_cargo');
const role = interaction.options.get('cargo');
const guildId = interaction.guild?.id;
const configRolesEmbed = interaction.client.baseEmbed();

if (!roleType || !role || !guildId) {
return interaction.reply({
embeds: [
new EmbedBuilder().setDescription(`Falha ao configurar cargo`),
],
embeds: [configRolesEmbed.setDescription(`Falha ao configurar cargo`)],
});
}
const roleId = role.value as string;
Expand All @@ -56,7 +55,7 @@ export const configRoles: SlashCommand = {

interaction.reply({
embeds: [
new EmbedBuilder().setDescription(
configRolesEmbed.setDescription(
`Cargo ${roleType.value} configurado como ${roleName}`
),
],
Expand Down
5 changes: 3 additions & 2 deletions src/bot/commands/slashCommands/disconnectAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const disconnectAll: SlashCommand = {
execute: async (interaction) => {
const member = interaction.member as GuildMember;
const voiceChannel = member?.voice.channel;
const disconnectAllEmbed = interaction.client.baseEmbed();
if (!voiceChannel) {
interaction.reply({
embeds: [
new EmbedBuilder().setDescription(
disconnectAllEmbed.setDescription(
'Você precisa estar em um canal de voz para usar esse comando'
),
],
Expand All @@ -28,7 +29,7 @@ export const disconnectAll: SlashCommand = {

interaction.reply({
embeds: [
new EmbedBuilder().setDescription(
disconnectAllEmbed.setDescription(
'Todos os usuários foram desconectados'
),
],
Expand Down
5 changes: 3 additions & 2 deletions src/bot/commands/slashCommands/getRoles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder } from 'discord.js';

import { SlashCommand } from '@marquinhos/types';
import GuildModel from '@schemas/guild';
Expand All @@ -12,6 +12,7 @@ export const getRoles: SlashCommand = {
const { externalRoleId, baseRoleId, vipRoleId } = await findRoles(
interaction.guild?.id as string
);
const getRolesEmbed = interaction.client.baseEmbed();

const externalRoleName = externalRoleId
? interaction.guild?.roles.cache.get(externalRoleId)?.name
Expand All @@ -24,7 +25,7 @@ export const getRoles: SlashCommand = {
: 'Não definido';
interaction.reply({
embeds: [
new EmbedBuilder().setDescription(
getRolesEmbed.setDescription(
`Cargo externo: ${externalRoleName}\n
Cargo base: ${baseRoleName}\n
Cargo VIP: ${vipRoleName}`
Expand Down
3 changes: 2 additions & 1 deletion src/bot/commands/slashCommands/lastfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export const lastfm: SlashCommand = {
.setName('lastfm')
.setDescription('Mostra informações sobre a integração com o last.fm'),
execute: (interaction) => {
const lastfmEmbed = interaction.client.baseEmbed();
interaction.reply({
embeds: [
new EmbedBuilder()
lastfmEmbed
.setThumbnail(
'https://play-lh.googleusercontent.com/VFmAfWqcuV3aReZG8MMQdHRSdKWx85IW22f4RQ5xhR5U-o1_u03P7TVwsnTYa26Q1No'
)
Expand Down
9 changes: 5 additions & 4 deletions src/bot/commands/slashCommands/minecraftStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export const minecraftStatus: SlashCommand = {
const ip = interaction.options.get('ip')?.value as string;
const port = interaction.options.get('port')?.value as number;
const guildID = interaction.guildId as string;
const minecraftStatusBaseEmbed = interaction.client.baseEmbed();

if (!guildID) {
await interaction.reply({
embeds: [
new EmbedBuilder()
minecraftStatusBaseEmbed
.setTitle(`Falha ao criar o monitoramento!`)
.setDescription(
`Não foi possível encontrar o ID do servidor de discord!`
Expand All @@ -57,7 +58,7 @@ export const minecraftStatus: SlashCommand = {
} catch (error) {
await interaction.reply({
embeds: [
new EmbedBuilder()
minecraftStatusBaseEmbed
.setTitle(`Falha ao criar o monitoramento!`)
.setDescription(
`Não foi possível conectar ao servidor de minecraft!`
Expand Down Expand Up @@ -96,7 +97,7 @@ export const minecraftStatus: SlashCommand = {
if (existingServer) {
await interaction.reply({
embeds: [
new EmbedBuilder()
minecraftStatusBaseEmbed
.setTitle(`Servidor já está sendo monitorado!`)
.setDescription(
`O servidor já tem status em <#${statusChannel.id}>`
Expand All @@ -123,7 +124,7 @@ export const minecraftStatus: SlashCommand = {

await interaction.reply({
embeds: [
new EmbedBuilder()
minecraftStatusBaseEmbed
.setTitle(`Monitoramento do servidor de minecraft criado!`)
.setDescription(
`Agora você pode ver o status do servidor de minecraft em tempo real em <#${statusChannel.id}>`
Expand Down
3 changes: 2 additions & 1 deletion src/bot/commands/slashCommands/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export const ping: SlashCommand = {
.setName('ping')
.setDescription("Shows the bot's ping"),
execute: (interaction) => {
const pingEmbed = interaction.client.baseEmbed();
interaction.reply({
embeds: [
new EmbedBuilder()
pingEmbed
.setAuthor({
name: interaction.user.username,
iconURL: interaction.user.avatarURL() ?? undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/bot/events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GuildModel from '@schemas/guild';
export const guildMemberAdd: BotEvent = {
name: 'guildMemberAdd',
execute: async (member: GuildMember) => {
const guildMemberAddEmbed = member.client.baseEmbed();
const guild = await GuildModel.findOne({ guildID: member.guild.id }).exec();
if (!guild) {
throw new Error('Guild not found');
Expand Down Expand Up @@ -78,7 +79,7 @@ export const guildMemberAdd: BotEvent = {

channel.send({
embeds: [
new EmbedBuilder()
guildMemberAddEmbed
.setThumbnail(member.user.avatarURL())
.setColor('#0099ff')
.setDescription(
Expand Down
7 changes: 4 additions & 3 deletions src/utils/lastfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const tempo = new TempoDataProvider();
const marquinhosApi = new MarquinhosApiService();

export const musicBotMessageHandler = async (message: Message) => {
const musicEmbed = message.client.baseEmbed();
if (!tempo.isHandleableMessage(message)) return;
const playbackData = await tempo.getPlaybackDataFromMessage(message);
if (playbackData) {
Expand All @@ -27,7 +28,7 @@ export const musicBotMessageHandler = async (message: Message) => {
);
await message.channel.send({
embeds: [
new EmbedBuilder()
musicEmbed
.setTitle('Erro ao adicionar a fila de scrobbling :cry:')
.setDescription(
`A música **${playbackData.title}** não foi adicionada a fila de scrobbling.`
Expand All @@ -46,7 +47,7 @@ export const musicBotMessageHandler = async (message: Message) => {
logger.error(`track: ${!!track}, scrobbleId: ${!!scrobbleId}`);
await message.channel.send({
embeds: [
new EmbedBuilder()
musicEmbed
.setTitle('Erro ao adicionar a fila de scrobbling :cry:')
.setDescription(
`A música **${playbackData.title}** não foi adicionada a fila de scrobbling.`
Expand Down Expand Up @@ -88,7 +89,7 @@ export const musicBotMessageHandler = async (message: Message) => {
`Added ${playbackData.title} to scrobble queue to ${scrobblesOnUsers.length} users`
);

const scrobbleEmbed = new EmbedBuilder()
const scrobbleEmbed = musicEmbed
.setTitle('Adicionado a fila de scrobbling :headphones:')
.setDescription(getOngoingScrobbleDescription(track, scrobblesOnUsers))
.setFooter({
Expand Down
5 changes: 3 additions & 2 deletions src/utils/minecraftServerStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export default class MinecraftServerStatus {
}

generateMinecraftStatusEmbed(status: util.FullQueryResponse | null) {
const minecraftStatusBaseEmbed = this._client.baseEmbed();
if (!status) {
return new EmbedBuilder()
return minecraftStatusBaseEmbed
.setTitle(`O servidor está offline!`)
.setThumbnail('https://i.imgur.com/TSai5Im.png')
.setColor('#ff0000')
Expand All @@ -114,7 +115,7 @@ export default class MinecraftServerStatus {
]);
}

return new EmbedBuilder()
return minecraftStatusBaseEmbed
.setTitle(`${status?.motd?.clean}`)
.setThumbnail('https://i.imgur.com/TSai5Im.png')

Expand Down

0 comments on commit 17a347a

Please sign in to comment.