Skip to content

Commit

Permalink
3.6.0-dev-3
Browse files Browse the repository at this point in the history
Added a welcome message when join to guild.
Fixed bug in /setprefix, when value output is interpolated.
Fixed bug when song history is not deleted when bot leaves the guild/server.
Fixed minor localization bugs.
  • Loading branch information
AlexInCube committed Aug 11, 2024
1 parent 8183b69 commit f7152a1
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BOT_VERBOSE_LOGGING=false
BOT_FFMPEG_LOGGING=false

BOT_COMMAND_PREFIX=//
BOT_COMMAND_PREFIX=$
BOT_LANGUAGE=en

BOT_MAX_SONGS_IN_QUEUE=500
Expand Down
5 changes: 4 additions & 1 deletion src/commands/admin/setPrefix.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ async function changePrefixTo(guild: Guild, prefix: string): Promise<string> {
return i18next.t('commands:set_prefix_restrict_prefixes', { prefixes: '/ @ #' }) as string;
if (prefix.length > 2) return i18next.t('commands:set_prefix_length_error') as string;
await setGuildOptionPrefix(guild.id, prefix);
return i18next.t('commands:set_prefix_success_change', { prefix: prefix }) as string;
return i18next.t('commands:set_prefix_success_change', {
prefix,
interpolation: { escapeValue: false }
}) as string;
}
10 changes: 5 additions & 5 deletions src/events/interactionHandlers/slashCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function slashCommandHandler(interaction: Interaction) {
if (command.guild_data?.guild_only) {
if (!interaction.guild) {
await interaction.reply({
embeds: [generateErrorEmbed(i18next.t('commandshandlers:command_only_in_guilds'))],
embeds: [generateErrorEmbed(i18next.t('commandsHandlers:command_only_in_guilds'))],
ephemeral: true
});
return;
Expand All @@ -44,7 +44,7 @@ export async function slashCommandHandler(interaction: Interaction) {

if (!checkMemberInVoice(<GuildMember>interaction.member)) {
await interaction.reply({
embeds: [generateErrorEmbed(i18next.t('commandshandlers:command_only_in_voice'))],
embeds: [generateErrorEmbed(i18next.t('commandsHandlers:command_only_in_voice'))],
ephemeral: true
});
return;
Expand All @@ -58,9 +58,9 @@ export async function slashCommandHandler(interaction: Interaction) {
await interaction.reply({
embeds: [
generateErrorEmbed(
`:no_entry: ${i18next.t('commandshandlers:bot_not_enough_permissions_1')} :no_entry:.\n` +
`${i18next.t('commandshandlers:bot_not_enough_permissions_2')} \n` +
`${i18next.t('commandshandlers:bot_not_enough_permissions_3')}`
`:no_entry: ${i18next.t('commandsHandlers:bot_not_enough_permissions_1')} :no_entry:.\n` +
`${i18next.t('commandsHandlers:bot_not_enough_permissions_2')} \n` +
`${i18next.t('commandsHandlers:bot_not_enough_permissions_3')}`
)
],
ephemeral: true
Expand Down
14 changes: 7 additions & 7 deletions src/events/messageHandlers/textCommandsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function textCommandsHandler(client: Client, message: Message) {
// If command allowed only in guild, check voice_required and voice_with_bot_only properties
if (!message.guild) {
await message.reply({
embeds: [generateErrorEmbed(i18next.t('commandshandlers:command_only_in_guilds'))]
embeds: [generateErrorEmbed(i18next.t('commandsHandlers:command_only_in_guilds'))]
});
return;
}
Expand All @@ -82,7 +82,7 @@ export async function textCommandsHandler(client: Client, message: Message) {

if (!checkMemberInVoice(message.member!)) {
await message.reply({
embeds: [generateErrorEmbed(i18next.t('commandshandlers:command_only_in_voice'))]
embeds: [generateErrorEmbed(i18next.t('commandsHandlers:command_only_in_voice'))]
});
return;
}
Expand All @@ -96,9 +96,9 @@ export async function textCommandsHandler(client: Client, message: Message) {
await message.reply({
embeds: [
generateErrorEmbed(
`:no_entry: ${i18next.t('commandshandlers:bot_not_enough_permissions_1')} :no_entry:.\n` +
`${i18next.t('commandshandlers:bot_not_enough_permissions_2')} \n` +
`${i18next.t('commandshandlers:bot_not_enough_permissions_3')}`
`:no_entry: ${i18next.t('commandsHandlers:bot_not_enough_permissions_1')} :no_entry:.\n` +
`${i18next.t('commandsHandlers:bot_not_enough_permissions_2')} \n` +
`${i18next.t('commandsHandlers:bot_not_enough_permissions_3')}`
)
]
});
Expand All @@ -110,7 +110,7 @@ export async function textCommandsHandler(client: Client, message: Message) {
if (member) {
if (!CheckMemberPermissions(member, command.user_permissions)) {
await message.reply({
embeds: [generateErrorEmbed(i18next.t('commandshandlers:user_not_enough_permissions'))]
embeds: [generateErrorEmbed(i18next.t('commandsHandlers:user_not_enough_permissions'))]
});
return;
}
Expand All @@ -120,6 +120,6 @@ export async function textCommandsHandler(client: Client, message: Message) {
await command.text_data.execute(message, args);
} catch (e) {
if (ENV.BOT_VERBOSE_LOGGING)
loggerError(`commandshandlers:text_command_error: ${e}`, loggerPrefixCommandHandler);
loggerError(`Error when executing text command: ${e}`, loggerPrefixCommandHandler);
}
}
20 changes: 19 additions & 1 deletion src/events/onGuildCreate.event.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { BotEvent } from '../DiscordTypes.js';
import { Client, Guild } from 'discord.js';
import {
Client,
Guild,
GuildBasedChannel,
GuildTextBasedChannel,
PermissionsBitField
} from 'discord.js';
import { getOrCreateGuildSettings } from '../schemas/SchemaGuild.js';
import { Events } from 'discord.js';
import { CheckBotPermissions } from '../utilities/checkPermissions.js';
import { generateNewGuildEmbed } from '../utilities/generateNewGuildEmbed.js';

const event: BotEvent = {
name: Events.GuildCreate,
execute: async (client: Client, guild: Guild) => {
await getOrCreateGuildSettings(guild.id);

// Send a welcome message
const channel: GuildBasedChannel | undefined = guild.channels.cache.find(
(channel) =>
// Channel type zero is Text channel
channel.type === 0 && CheckBotPermissions(channel, [PermissionsBitField.Flags.SendMessages])
);

if (!channel) return;
(channel as GuildTextBasedChannel).send({ embeds: [generateNewGuildEmbed()] });
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/locales/Locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export default async function loadLocale() {
fallbackLng: 'en',
ns: [
'mongodb',
'commandshandlers',
'commandsHandlers',
'commands',
'commandsGroups',
'general',
'permissions',
'audioplayer'
'audioplayer',
'welcomeMessage'
],
backend: {
loadPath: join(getDirName(import.meta.url), '../locales/{{lng}}/{{ns}}.json')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"text_command_error": "Error when executing text command",
"slash_command_error": "Error when executing slash command",
"bot_not_enough_permissions_1": "BOT has not enough permissions on this server or channel",
"bot_not_enough_permissions_2": "Write /help (command name), to see the missing permissions",
"bot_not_enough_permissions_3": "And also ask the server administration to give them to the bot",
Expand Down
7 changes: 7 additions & 0 deletions src/locales/en/welcomeMessage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Hello everyone!",
"row_1": "My main purpose is alcotest, to check yourself write /alcotest",
"row_2": "All jokes aside, I'm an advanced music bot that can play music from almost anywhere.",
"row_3": "Write /play (slash command) or {{prefix}}play (text command) to begin **magic**",
"row_4": "If you have any questions, write /help"
}
File renamed without changes.
7 changes: 7 additions & 0 deletions src/locales/ru/welcomeMessage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Всем привет!",
"row_1": "Моя основная функция это алкотест, чтобы проверить себя напишите /alcotest",
"row_2": "А если отбросить шутки, то я продвинутый музыкальный бот который умеет играть музыку почти откуда угодно",
"row_3": "Напиши /play (слеш команда) или {{prefix}}play (текстовая команда) чтобы началась **магия**",
"row_4": "Если у тебя есть вопросы, то напиши /help"
}
2 changes: 1 addition & 1 deletion src/schemas/SchemaSongsHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function getOrCreateGuildSongsHistory(guildID: string) {

export async function deleteGuildSongsHistory(guildID: string) {
const guild: GuildModelClass = await getOrCreateGuildSettings(guildID);
await guild.songsHistory.deleteOne();
await SongsHistoryListModelClass.deleteOne({ _id: guild.songsHistory });
}

export async function addSongToGuildSongsHistory(
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/checkMemberInVoiceWithBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function checkMemberInVoiceWithBot(
return response;
}
} else {
response.errorMessage = i18next.t('commandshandlers:voice_join_in_any_channel');
response.errorMessage = i18next.t('commandsHandlers:voice_join_in_any_channel');
return response;
}

Expand All @@ -29,7 +29,7 @@ export async function checkMemberInVoiceWithBot(
.then((channel) => {
if (channel) {
if (channel instanceof VoiceChannel) {
response.errorMessage = `${i18next.t('commandshandlers:voice_join_in_channel')} ${channel.name}`;
response.errorMessage = `${i18next.t('commandsHandlers:voice_join_in_channel')} ${channel.name}`;
}
}
});
Expand Down
24 changes: 24 additions & 0 deletions src/utilities/generateNewGuildEmbed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Colors, EmbedBuilder } from 'discord.js';
import { ENV } from '../EnvironmentVariables.js';
import i18next from 'i18next';

export function generateNewGuildEmbed(): EmbedBuilder {
return new EmbedBuilder()
.setTitle(i18next.t('welcomeMessage:title'))
.setDescription(
i18next.t('welcomeMessage:row_1') +
'\n\n' +
i18next.t('welcomeMessage:row_2') +
'\n\n' +
i18next.t('welcomeMessage:row_3', {
prefix: ENV.BOT_COMMAND_PREFIX,
interpolation: { escapeValue: false }
}) +
'\n\n' +
i18next.t('welcomeMessage:row_4')
)
.setColor(Colors.Yellow)
.setImage(
'https://github.com/AlexInCube/AlCoTest/blob/master/icons/repository-social.png?raw=true'
);
}

0 comments on commit f7152a1

Please sign in to comment.