Skip to content

Commit

Permalink
Fixed talking upon action
Browse files Browse the repository at this point in the history
  • Loading branch information
keybraker committed Nov 5, 2024
1 parent ac2099a commit a44bd62
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 35 deletions.
15 changes: 5 additions & 10 deletions src/blueprints/attribute.blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import {
OverwriteType,
Role
} from 'discord.js';

import { getKeyFromEnum, isMod } from '../libraries/help.library';
import { updateGuild, updateMember, updatePortal, updateVoice } from '../libraries/mongo.library';
import { PGuild } from '../types/classes/PGuild.class';
import { PMember } from '../types/classes/PMember.class';
import { PChannel } from '../types/classes/PPortalChannel.class';
import { Blueprint, ReturnPromise } from '../types/classes/PTypes.interface';
import { PVoiceChannel } from '../types/classes/PVoiceChannel.class';
import { AuthType } from '../types/enums/Admin.enum';
import { Locale, LocaleList } from '../types/enums/Locales.enum';
import { ProfanityLevel, ProfanityLevelList } from '../types/enums/ProfanityLevel.enum';
import { RankSpeed } from '../types/enums/RankSpeed.enum';
import { PMember } from '../types/classes/PMember.class';

function getResponse(response: boolean, category: string[], attribute: string, value: string | number) {
const responseValue = response
Expand Down Expand Up @@ -1105,9 +1106,7 @@ export const AttributeBlueprints: Blueprint[] = [
if (locale === undefined) {
return {
result: false,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(
', '
)}**`,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(', ')}**`,
};
}

Expand Down Expand Up @@ -1164,9 +1163,7 @@ export const AttributeBlueprints: Blueprint[] = [
if (locale === undefined) {
return {
result: false,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(
', '
)}**`,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(', ')}**`,
};
}

Expand Down Expand Up @@ -1215,9 +1212,7 @@ export const AttributeBlueprints: Blueprint[] = [
if (locale === undefined) {
return {
result: false,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(
', '
)}**`,
value: `attribute ${category.join('.') + '.' + attribute} can only be **${LocaleList.join(', ')}**`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/noAuth/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export = {
};
}

clientTalk(interaction, pGuild, AnnouncementAction.join);
clientTalk(interaction, pGuild, AnnouncementAction.join, true);

return {
result: true,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/noAuth/leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export = {
};
}

clientTalk(interaction, pGuild, AnnouncementAction.leave);
clientTalk(interaction, pGuild, AnnouncementAction.leave, true);
setTimeout(function () {
voiceConnection.disconnect();
}, 4000);
Expand Down
4 changes: 2 additions & 2 deletions src/events/channelDelete.event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChannelType, DMChannel, GuildChannel, TextChannel, VoiceChannel } from 'discord.js';
import { handleChannelDeletion } from '../libraries/mongo.library';

import { PortalChannelType } from '../types/enums/PortalChannel.enum';

export default async function channelDelete(args: { channel: DMChannel | GuildChannel }): Promise<string> {
Expand All @@ -18,7 +19,6 @@ export default async function channelDelete(args: { channel: DMChannel | GuildCh
}

return deletedChannelPortalType > 0
? `${PortalChannelType[deletedChannelPortalType].toString()} channel removed from ` +
`${deletedChannel.guild.name}|${deletedChannel.guild.id}`
? `${PortalChannelType[deletedChannelPortalType].toString()} channel removed from ${deletedChannel.guild.name}|${deletedChannel.guild.id}`
: `${deletedChannel.name} channel is not controlled by Portal`;
}
13 changes: 9 additions & 4 deletions src/events/ready.event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActivityOptions, ActivityType, Client, Guild, PresenceData } from 'discord.js';

import { removeDeletedChannels, removeEmptyVoiceChannels } from '../libraries/help.library';
import { getFunction } from '../libraries/localisation.library';
import { fetchGuildMembers, guildExists, insertGuild, insertMember, removeMember } from '../libraries/mongo.library';
Expand All @@ -17,16 +18,20 @@ export default async (args: { client: Client }): Promise<string> => {
url: 'https://github.com/keybraker',
};

const data: PresenceData = { activities: [activitiesOptions], status: 'online', afk: false };
const data: PresenceData = {
activities: [activitiesOptions],
status: 'online',
afk: false
};

args.client.user.setPresence(data);

let index = 0;
args.client.guilds.cache.forEach((guild: Guild) => {
logger.info(`${index++}. logged onto guild ${guild} (${guild.id})`);

addGuildAgain(guild, args.client).catch((e) => {
return `failed to add guild again: ${e}`;
});
addGuildAgain(guild, args.client)
.catch((e) => logger.warn(`failed to add guild ${guild.name} [${guild.id}] (${e})`));

removeDeletedChannels(guild);
removeEmptyVoiceChannels(guild);
Expand Down
29 changes: 12 additions & 17 deletions src/libraries/localisation.library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,11 @@ export const consoleText: LocalisationConsoleOption[] = [
},
];

function isAnnouncementAction(value: AnnouncementAction | string): value is AnnouncementAction {
return Object.values(AnnouncementAction).includes(value);
}

function isEventAction(value: EventAction | string): value is EventAction {
return Object.values(EventAction).includes(value);
}

export function clientTalk(
interaction: ChatInputCommandInteraction,
pGuild: PGuild,
context: AnnouncementAction | EventAction
context: AnnouncementAction | EventAction,
isAction: boolean
): boolean {
if (!interaction.guild) {
return false;
Expand Down Expand Up @@ -276,28 +269,30 @@ export function clientTalk(
[EventAction.userDisconnected]: 'user_disconnected',
};

for (const p of pGuild.pChannels) {
for (const v of p.pVoiceChannels) {
if (isAnnouncementAction(context.toString())&& !isEventAction(context.toString()) && v.annAnnounce) {
for (let i = 0; i < pGuild.pChannels.length; i++) {
for (let j = 0; j < pGuild.pChannels[i].pVoiceChannels.length; j++) {
const v = pGuild.pChannels[i].pVoiceChannels[j];

if (isAction) {
const locale = localeToString[v.locale];
const contextAsAction = AnnouncementActionToString[context];
const random = Math.floor(Math.random() * 3);

const resource = createAudioResource(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}${random}.mp3`);
logger.info(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}${random}.mp3, ${!!resource}`);
const resource = createAudioResource(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}_${random}.mp3`);
logger.info(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}_${random}.mp3, ${!!resource}`);

player.play(resource);
voiceConnection.subscribe(player);

return true;
} else if (!isAnnouncementAction(context.toString()) && isEventAction(context.toString()) && v.annUser) {
} else {
const locale = localeToString[v.locale];
const contextAsAction = EventActionToString[context as EventAction];

const random = Math.floor(Math.random() * 3);

const resource = createAudioResource(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}${random}.mp3`);
logger.info(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}${random}.mp3, ${!!resource}`);
const resource = createAudioResource(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}_${random}.mp3`);
logger.info(`src/assets/mp3s/${locale}/${contextAsAction}/${contextAsAction}_${random}.mp3, ${!!resource}`);

player.play(resource);
voiceConnection.subscribe(player);
Expand Down

0 comments on commit a44bd62

Please sign in to comment.