Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
mqtt events
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasptsch committed Oct 9, 2022
1 parent 39c92c6 commit 7cef73b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/classes/Aliases.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import type DynamicaAlias from './Alias';
import MQTT from './MQTT';

export default class Aliases {
private static aliases: DynamicaAlias[] = [];

public static mqtt = MQTT.getInstance();

public static add(alias: DynamicaAlias) {
this.aliases.push(alias);
if (this.mqtt) {
this.mqtt.publish('dynamica/aliases', this.aliases.length.toString());
}
}

public static remove(activity: string, guildId: string) {
this.aliases = this.aliases.filter(
(alias) => !(alias.activity === activity && alias.guildId === guildId)
);
if (this.mqtt) {
this.mqtt.publish('dynamica/aliases', this.aliases.length.toString());
}
}

public static get(activity: string, guildId: string) {
Expand Down
6 changes: 6 additions & 0 deletions src/classes/Events.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Client, ClientEvents } from 'discord.js';
import type Event from './Event';
import MQTT from './MQTT';

export default class Events {
public static events: Event<keyof ClientEvents>[] = [];

public static mqtt = MQTT.getInstance();

public static register(event: Event<keyof ClientEvents>): void {
this.events.push(event);
if (this.mqtt) {
this.mqtt.publish('dynamica/events', this.events.length.toString());
}
}

public static registerListeners(client: Client<false>): void {
Expand Down
9 changes: 9 additions & 0 deletions src/classes/Guilds.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import type DynamicaGuild from './Guild';
import MQTT from './MQTT';

export default class Guilds {
private static guilds: DynamicaGuild[] = [];

public static mqtt = MQTT.getInstance();

public static getGuilds(): DynamicaGuild[] {
return this.guilds;
}

public static add(guild: DynamicaGuild) {
this.guilds.push(guild);
if (this.mqtt) {
this.mqtt.publish('dynamica/guilds', this.guilds.length.toString());
}
}

public static remove(guildId: string) {
this.guilds = this.guilds.filter((guild) => guild.id !== guildId);
if (this.mqtt) {
this.mqtt.publish('dynamica/guilds', this.guilds.length.toString());
}
}

public static get(guildId: string) {
Expand Down
9 changes: 9 additions & 0 deletions src/classes/Primaries.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import MQTT from './MQTT';
import type DynamicaPrimary from './Primary';

export default class Primaries {
public static primaries: DynamicaPrimary[] = [];

public static mqtt = MQTT.getInstance();

public static add(primary: DynamicaPrimary) {
this.primaries.push(primary);
if (this.mqtt) {
this.mqtt.publish('dynamica/primaries', this.primaries.length.toString());
}
}

public static remove(id: string) {
this.primaries = this.primaries.filter((primary) => primary.id !== id);
if (this.mqtt) {
this.mqtt.publish('dynamica/primaries', this.primaries.length.toString());
}
}

public static get(id: string | undefined) {
Expand Down
15 changes: 15 additions & 0 deletions src/classes/Secondaries.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import MQTT from './MQTT';
import type DynamicaSecondary from './Secondary';

export default class Secondaries {
public static secondaries: DynamicaSecondary[] = [];

public static mqtt = MQTT.getInstance();

public static add(secondary: DynamicaSecondary) {
this.secondaries.push(secondary);
if (this.mqtt) {
this.mqtt.publish(
'dynamica/secondaries',
this.secondaries.length.toString()
);
}
}

public static remove(id: string) {
this.secondaries = this.secondaries.filter(
(secondary) => secondary.id !== id
);
if (this.mqtt) {
this.mqtt.publish(
'dynamica/secondaries',
this.secondaries.length.toString()
);
}
}

public static get(id: string) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/AliasCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default class AliasCommand extends Command {
)
);

// eslint-disable-next-line class-methods-use-this
response = async (interaction: ChatInputCommandInteraction<CacheType>) => {
const subcommand = interaction.options.getSubcommand(true);
// console.log({ subcommand });
Expand Down
1 change: 1 addition & 0 deletions src/commands/BitrateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class BitrateCommand extends Command {
.setName('bitrate')
);

// eslint-disable-next-line class-methods-use-this
response = async (interaction: ChatInputCommandInteraction<CacheType>) => {
const bitrate = interaction.options.getInteger('bitrate');
const guildMember = await interaction.guild.members.cache.get(
Expand Down
1 change: 1 addition & 0 deletions src/commands/CreateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class CreateCommand extends Command {
.setRequired(false)
);

// eslint-disable-next-line class-methods-use-this
response = async (interaction: ChatInputCommandInteraction<CacheType>) => {
const section = interaction.options.getChannel(
'section'
Expand Down
1 change: 1 addition & 0 deletions src/commands/GeneralCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class GeneralCommand extends Command {
.setRequired(true)
);

// eslint-disable-next-line class-methods-use-this
response = async (interaction: ChatInputCommandInteraction<CacheType>) => {
const name = interaction.options.getString('name', true);
const channel = interaction.options.getString('primary', true);
Expand Down

0 comments on commit 7cef73b

Please sign in to comment.