Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
refactor: remove voice hooks
Browse files Browse the repository at this point in the history
The voice hooks were added to have a channel only visible when people
joined a voice channel. For a year or so, this has been a native feature
in Discord, so this voice role is actually not needed anymore.
  • Loading branch information
danirod committed Oct 29, 2023
1 parent 3964a8b commit ec8f59d
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 236 deletions.
1 change: 0 additions & 1 deletion docs/development/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ Esta es una lista de las funciones y los prototipos de referencia:
* `onGuildMemberUpdate(prev, next)`: Se ejecuta cuando un miembro actualiza algo sobre ello. Depende mucho del evento que dispara la API de Discord. Te proporciona el estado anterior del usuario y el nuevo estado del usuario y ya es cosa tuya hacer el diff y detectar qué ha cambiado.
* `onGuildMemberLeave(member)`: Se ejecuta cuando un miembro abandona el servidor. El `member` podría ser parcial. Cuidado con hacer un `fetch()`, porque el evento se puede recibir en cuentas que se eliminan (por ejemplo, el usuario borra su cuenta de Discord, o se trata de una cuenta temporal que Discord borra). En ese caso, hacer un `fetch()` provocará un error HTTP 404 en la API de Discord.
* `onBuildMemberBan(ban)`: se ejecuta cuando un miembro es baneado. La información está disponible a través del objeto `ban`.
* `onVoiceStateUpdate(oldState, newState)`: se ejecuta cuando un miembro interactúa con un canal de voz: conectándose, desconectándose, cambiando de canal, actualizando su estado (mute, deafen...). Cuando se conecta a un canal de voz, `oldState` vale null. Cuando se desconecta de cualquier canal de voz, `newState` vale null. Cuando salta de un canal a otro, puedes comparar el viejo canal con el nuevo canal mirando ambas variables para ver de dónde ha saltado. Lo mismo si apaga o enciende su micrófono o si silencia sus auriculares o quita el silencio.
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"datetoken": "^1.1.1",
"discord-api-types": "^0.32.0",
"discord.js": "^13.6.0",
"discordjs-voicerole": "^3.0.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"follow-redirects": ">=1.15.1",
Expand Down
1 change: 0 additions & 1 deletion src/Makibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default class Makibot extends Client {
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
],
partials: ["MESSAGE", "REACTION", "GUILD_MEMBER"],
});
Expand Down
52 changes: 0 additions & 52 deletions src/hooks/voicerole.ts

This file was deleted.

69 changes: 0 additions & 69 deletions src/interactions/commands/bitrate.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/lib/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
PartialMessageReaction,
PartialUser,
User,
VoiceState,
} from "discord.js";
import Makibot from "../Makibot";
import logger from "./logger";
Expand Down Expand Up @@ -44,8 +43,6 @@ export interface Hook {
onGuildMemberUpdate?: (prev: GuildMember, next: GuildMember) => Promise<void>;
onGuildMemberLeave?: (member: GuildMember | PartialGuildMember) => Promise<void>;
onGuildMemberBan?: (ban: GuildBan) => Promise<void>;

onVoiceStateUpdate?: (oldStatus: VoiceState, newStatus: VoiceState) => Promise<void>;
}

type HookConstructor = {
Expand Down Expand Up @@ -113,7 +110,6 @@ export class HookManager {
client.on("guildMemberRemove", this.onGuildMemberRemove.bind(this));
client.on("guildMemberUpdate", this.onGuildMemberUpdate.bind(this));
client.on("guildBanAdd", this.onGuildMemberBan.bind(this));
client.on("voiceStateUpdate", this.onVoiceStateUpdate.bind(this));
}

/**
Expand Down Expand Up @@ -252,14 +248,6 @@ export class HookManager {
}
}

async onVoiceStateUpdate(oldState: VoiceState, newState: VoiceState): Promise<void> {
const handlers = this.filterServices("onVoiceStateUpdate");
for (const handler of handlers) {
logger.debug(`[hooks] processing ${handler.name}(onVoiceStateUpdate)`);
await handler.onVoiceStateUpdate(oldState, newState);
}
}

restart(name: string): void {
logger.debug(`[hooks] restarting service ${name}...`);
this.watchdog[name]?.restart();
Expand Down
2 changes: 0 additions & 2 deletions src/lib/http/middlewares/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import memberMiddleware from "./member";
import providerMiddleware from "./provider";
import threadOnlyChannels from "./thread";
import trustedRoles from "./trusted";
import voiceRoleMiddleware from "./voiceroles";

export interface MiddlewareLocals {
guild: Guild;
Expand Down Expand Up @@ -36,7 +35,6 @@ export default function guildMiddleware(makibot: Makibot): express.Router {
});

router.use("/members/:member", memberMiddleware(makibot));
router.use("/roles/voices", voiceRoleMiddleware(makibot));
router.use("/roles/trusted", trustedRoles());

router.use("/channels/threadonly", threadOnlyChannels());
Expand Down
80 changes: 0 additions & 80 deletions src/lib/http/middlewares/voiceroles.ts

This file was deleted.

0 comments on commit ec8f59d

Please sign in to comment.