Skip to content

Commit

Permalink
feat - update language dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
jaga-live committed Jan 13, 2024
1 parent 8b2ec7c commit 684f007
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/common/dto/action-config.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiscordActions } from '../enum/discord-action.enum';
import { DiscordActionTypes } from '../enum/discord-action.enum';

interface ActionMessageConfig {
channelId?: string;
Expand All @@ -10,6 +10,6 @@ interface ActionMessageConfig {
}

export class ActionConfigDto {
action: DiscordActions;
action: DiscordActionTypes;
messageConfig: ActionMessageConfig;
}
2 changes: 1 addition & 1 deletion src/common/enum/discord-action.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum DiscordActions {
export enum DiscordActionTypes {
MESSAGE_CREATE = 'messageCreate',
MESSAGE_REACT = 'messageReact',
MESSAGE_REPLY = 'messageReply',
Expand Down
12 changes: 6 additions & 6 deletions src/common/services/discord-action.service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { injectable } from 'inversify';
import { IGuild } from '../interface/shared.interface';
import { liveClient } from '../../modules/app';
import { DiscordActions } from '../enum/discord-action.enum';
import { DiscordActionTypes } from '../enum/discord-action.enum';

@injectable()
export class DiscordActionService {
async actionFactory(action: DiscordActions, guild: IGuild, config: any) {
async actionFactory(action: DiscordActionTypes, guild: IGuild, config: any) {
switch (action) {
case DiscordActions.MESSAGE_CREATE: {
case DiscordActionTypes.MESSAGE_CREATE: {
await this.createMessage(guild, config);

break;
}

case DiscordActions.MESSAGE_REACT:
case DiscordActionTypes.MESSAGE_REACT:
await this.react(guild, config);
break;

case DiscordActions.MESSAGE_REPLY:
case DiscordActionTypes.MESSAGE_REPLY:
await this.reply(guild, config);
break;

case DiscordActions.MESSAGE_DELETE:
case DiscordActionTypes.MESSAGE_DELETE:
await this.deleteMessage(guild);
break;

Expand Down
4 changes: 2 additions & 2 deletions src/modules/auto-sail/auto-sail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject, injectable } from 'inversify';
import { AutoSailConfigDto } from './dto/auto-sail-config.dto';
import { TYPES } from '../../core/inversify.types';
import { DiscordActionService } from '../../common/services/discord-action.service';
import { DiscordActions } from '../../common/enum/discord-action.enum';
import { DiscordActionTypes } from '../../common/enum/discord-action.enum';
import { AutoSailConstraintsService } from './auto-sail-constraints.service';

@injectable()
Expand Down Expand Up @@ -39,7 +39,7 @@ export class AutoSailService {

for (const action of config.actionConfig) {
await this.discordActionService.actionFactory(
action.action as DiscordActions,
action.action as DiscordActionTypes,
payload,
action.messageConfig,
);
Expand Down
10 changes: 2 additions & 8 deletions src/modules/language/dto/language-filter.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionConfigDto } from '../../../common/dto/action-config.dto';
import { FeatureDefault } from '../../../common/dto/features-default.dto';
import { LanguageAction } from '../enum/language-filter.enum';

export interface LanguageFilterDto extends FeatureDefault {
languageFilterConfig: LanguageFilterConfigDto[];
Expand All @@ -8,11 +8,5 @@ export interface LanguageFilterDto extends FeatureDefault {
export interface LanguageFilterConfigDto {
isActive: boolean;
languageLibId: string;
actionConfig: LanguageFilterTriggerAction;
}

interface LanguageFilterTriggerAction {
action: LanguageAction;
emoji: string;
plainMessage: string;
actionConfig: ActionConfigDto[];
}
10 changes: 2 additions & 8 deletions src/modules/language/dto/strong-language.dto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { ActionConfigDto } from '../../../common/dto/action-config.dto';
import { FeatureDefault } from '../../../common/dto/features-default.dto';
import { LanguageAction } from '../enum/language-filter.enum';
import { StrongLanguageCodes } from '../enum/strong-language.enum';

interface StrongLanguageTriggerAction {
action: LanguageAction;
emoji: string;
plainMessage: string;
}

export interface StrongLanguageConfig {
language: StrongLanguageCodes;
whitelistLib: string;
}
export interface StrongLanguage extends FeatureDefault {
languageConfig: StrongLanguageConfig[];
actionConfig: StrongLanguageTriggerAction;
actionConfig: ActionConfigDto[];
}
4 changes: 0 additions & 4 deletions src/modules/language/enum/language-filter.enum.ts

This file was deleted.

18 changes: 10 additions & 8 deletions src/modules/language/language-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ export class LanguageFilter {
);

if (detected) {
await this.discordActionService.actionFactory(
actionConfig.action,
guild,
actionConfig,
);
for (const config of actionConfig) {
await this.discordActionService.actionFactory(
config.action,
guild,
config.messageConfig,
);
}
}
}
});
Expand All @@ -97,13 +99,13 @@ export class LanguageFilter {
);

if (detected) {
const actionConfig = config.actionConfig as any;
const actionConfigs = config.actionConfig as any;

if (detected) {
for (const actionConfig of actionConfigs) {
await this.discordActionService.actionFactory(
actionConfig.action,
guild,
actionConfig,
actionConfig.messageConfig,
);
}
}
Expand Down

0 comments on commit 684f007

Please sign in to comment.