refactor: rename *ID to *Id (#710)

* refactor: rename *ID to *Id

* Update src/helpers/commands/delete_slash_command.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/delete_slash_command.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/delete_slash_response.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/edit_slash_response.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/get_slash_command.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/send_interaction_response.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/upsert_slash_command.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/edit_widget.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/get_widget.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/get_widget.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/get_widget_image_url.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/get_widget_image_url.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/guilds/get_widget_settings.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update .gitignore

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update LICENSE

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/members/edit_bot_profile.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/members/edit_bot_profile.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/webhooks/create_webhook.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/webhooks/delete_webhook.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/webhooks/edit_webhook.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/webhooks/execute_webhook.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/webhooks/get_webhook.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/rest/cache.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/rest/request.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/helpers/commands/delete_slash_response.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/constants.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/util/utils.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Revert docs file

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
ayntee
2021-03-29 21:03:46 +04:00
committed by GitHub
parent 618d30b65d
commit eaff54f90f
138 changed files with 895 additions and 908 deletions
+4 -4
View File
@@ -13,22 +13,22 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
if (guild) {
return Promise.all(guild.voiceStates.map(async (vs, key) => {
if (vs.channelID !== payload.id) return;
if (vs.channelId !== payload.id) return;
// Since this channel was deleted all voice states for this channel should be deleted
guild.voiceStates.delete(key);
const member = await cacheHandlers.get("members", vs.userID);
const member = await cacheHandlers.get("members", vs.userId);
if (!member) return;
eventHandlers.voiceChannelLeave?.(member, vs.channelID);
eventHandlers.voiceChannelLeave?.(member, vs.channelId);
}));
}
}
await cacheHandlers.delete("channels", payload.id);
cacheHandlers.forEach("messages", (message) => {
if (message.channelID === payload.id) {
if (message.channelId === payload.id) {
cacheHandlers.delete("messages", message.id);
}
});
+5 -5
View File
@@ -6,7 +6,7 @@ import { basicShards } from "../../ws/shard.ts";
export async function handleGuildCreate(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
const payload = data.d as DiscordGuild;
// When shards resume they emit GUILD_CREATE again.
@@ -14,16 +14,16 @@ export async function handleGuildCreate(
const guildStruct = await structures.createGuildStruct(
data.d,
shardID,
shardId,
);
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);
const shard = basicShards.get(shardID);
const shard = basicShards.get(shardId);
if (shard?.unavailableGuildIDs.has(payload.id)) {
if (shard?.unavailableGuildIds.has(payload.id)) {
await cacheHandlers.delete("unavailableGuilds", payload.id);
shard.unavailableGuildIDs.delete(payload.id);
shard.unavailableGuildIds.delete(payload.id);
}
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
+5 -5
View File
@@ -5,7 +5,7 @@ import { basicShards } from "../../ws/shard.ts";
export async function handleGuildDelete(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
const payload = data.d as DiscordUnavailableGuild;
@@ -15,8 +15,8 @@ export async function handleGuildDelete(
await cacheHandlers.delete("guilds", payload.id);
if (payload.unavailable) {
const shard = basicShards.get(shardID);
if (shard) shard.unavailableGuildIDs.add(payload.id);
const shard = basicShards.get(shardId);
if (shard) shard.unavailableGuildIds.add(payload.id);
await cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
}
@@ -24,13 +24,13 @@ export async function handleGuildDelete(
eventHandlers.guildDelete?.(guild);
cacheHandlers.forEach("messages", (message) => {
if (message.guildID === payload.id) {
if (message.guildId === payload.id) {
cacheHandlers.delete("messages", message.id);
}
});
cacheHandlers.forEach("channels", (channel) => {
if (channel.guildID === payload.id) {
if (channel.guildId === payload.id) {
cacheHandlers.delete("channels", channel.id);
}
});
+4 -4
View File
@@ -6,14 +6,14 @@ import {
export function handleInviteDelete(payload: DiscordGatewayPayload) {
const {
channel_id: channelID,
guild_id: guildID,
channel_id: channelId,
guild_id: guildId,
...rest
} = payload.d as DiscordInviteDelete;
eventHandlers.inviteDelete?.({
...rest,
channelID,
guildID,
channelId,
guildId,
});
}
+3 -3
View File
@@ -44,16 +44,16 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
}
const roleIDs = guildMember?.roles || [];
const roleIds = guildMember?.roles || [];
roleIDs.forEach((id) => {
roleIds.forEach((id) => {
if (!payload.roles.includes(id)) {
eventHandlers.roleLost?.(guild, memberStruct, id);
}
});
payload.roles.forEach((id) => {
if (!roleIDs.includes(id)) {
if (!roleIds.includes(id)) {
eventHandlers.roleGained?.(guild, memberStruct, id);
}
});
+1 -1
View File
@@ -6,7 +6,7 @@ import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleMessageCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (channel) channel.lastMessageID = payload.id;
if (channel) channel.lastMessageId = payload.id;
const guild = payload.guild_id
? await cacheHandlers.get("guilds", payload.guild_id)
@@ -1,4 +1,4 @@
import { botID, eventHandlers } from "../../bot.ts";
import { botId, eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
@@ -21,7 +21,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
else {
const newReaction = {
count: 1,
me: payload.user_id === botID,
me: payload.user_id === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions
@@ -46,8 +46,8 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
const uncachedOptions = {
...payload,
id: payload.message_id,
channelID: payload.channel_id,
guildID: payload.guild_id || "",
channelId: payload.channel_id,
guildId: payload.guild_id || "",
};
eventHandlers.reactionAdd?.(
@@ -1,4 +1,4 @@
import { botID, eventHandlers } from "../../bot.ts";
import { botId, eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
@@ -23,7 +23,7 @@ export async function handleMessageReactionRemove(
else {
const newReaction = {
count: 1,
me: payload.user_id === botID,
me: payload.user_id === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions
@@ -48,8 +48,8 @@ export async function handleMessageReactionRemove(
const uncachedOptions = {
...payload,
id: payload.message_id,
channelID: payload.channel_id,
guildID: payload.guild_id,
channelId: payload.channel_id,
guildId: payload.guild_id,
};
eventHandlers.reactionRemove?.(
+23 -23
View File
@@ -1,8 +1,8 @@
import {
eventHandlers,
lastShardID,
setApplicationID,
setBotID,
lastShardId,
setApplicationId,
setBotId,
} from "../../bot.ts";
import { cache, cacheHandlers } from "../../cache.ts";
import { initialMemberLoadQueue } from "../../structures/guild.ts";
@@ -13,30 +13,30 @@ import { allowNextShard, basicShards } from "../../ws/mod.ts";
export async function handleReady(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
// The bot has already started, the last shard is resumed, however.
if (cache.isReady) return;
const payload = data.d as DiscordReady;
setBotID(payload.user.id);
setApplicationID(payload.application.id);
setBotId(payload.user.id);
setApplicationId(payload.application.id);
// Triggered on each shard
eventHandlers.shardReady?.(shardID);
eventHandlers.shardReady?.(shardId);
// Save when the READY event was received to prevent infinite load loops
const now = Date.now();
const shard = basicShards.get(shardID);
const shard = basicShards.get(shardId);
if (!shard) return;
// Set ready to false just to go sure
shard.ready = false;
// All guilds are unavailable at first
shard.unavailableGuildIDs = new Set(payload.guilds.map((g) => g.id));
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
// Start ready check in 2 seconds
setTimeout(() => checkReady(payload, shardID, now), 2000);
setTimeout(() => checkReady(payload, shardId, now), 2000);
// Wait 5 seconds to spawn next shard
await delay(5000);
@@ -45,48 +45,48 @@ export async function handleReady(
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
/** This function checks if the shard is fully loaded */
function checkReady(payload: DiscordReady, shardID: number, now: number) {
const shard = basicShards.get(shardID);
function checkReady(payload: DiscordReady, shardId: number, now: number) {
const shard = basicShards.get(shardId);
if (!shard) return;
// Check if all guilds were loaded
if (shard.unavailableGuildIDs.size) {
if (shard.unavailableGuildIds.size) {
if (Date.now() - now > 10000) {
eventHandlers.shardFailedToLoad?.(shardID, shard.unavailableGuildIDs);
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
// Force execute the loaded function to prevent infinite loop
loaded(shardID);
loaded(shardId);
} else {
// Not all guilds were loaded but 10 seconds haven't passed so check again
setTimeout(() => checkReady(payload, shardID, now), 2000);
setTimeout(() => checkReady(payload, shardId, now), 2000);
}
} else {
// All guilds were loaded
loaded(shardID);
loaded(shardId);
}
}
async function loaded(shardID: number) {
const shard = basicShards.get(shardID);
async function loaded(shardId: number) {
const shard = basicShards.get(shardId);
if (!shard) return;
shard.ready = true;
// If it is the last shard we can go full ready
if (shardID === lastShardID - 1) {
if (shardId === lastShardId - 1) {
// Still some shards are loading so wait another 2 seconds for them
if (basicShards.some((shard) => !shard.ready)) {
setTimeout(() => loaded(shardID), 2000);
setTimeout(() => loaded(shardId), 2000);
} else {
cache.isReady = true;
eventHandlers.ready?.();
// All the members that came in on guild creates should now be processed 1 by 1
for (const [guildID, members] of initialMemberLoadQueue.entries()) {
for (const [guildId, members] of initialMemberLoadQueue.entries()) {
await Promise.allSettled(
members.map(async (member) => {
const memberStruct = await structures.createMemberStruct(
member,
guildID,
guildId,
);
return cacheHandlers.set(
+9 -9
View File
@@ -20,10 +20,10 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
guild.voiceStates.set(payload.user_id, {
...payload,
guildID: payload.guild_id,
channelID: payload.channel_id || "",
userID: payload.user_id,
sessionID: payload.session_id,
guildId: payload.guild_id,
channelId: payload.channel_id || "",
userId: payload.user_id,
sessionId: payload.session_id,
selfDeaf: payload.self_deaf,
selfMute: payload.self_mute,
selfStream: payload.self_stream || false,
@@ -31,22 +31,22 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
await cacheHandlers.set("guilds", payload.guild_id, guild);
if (cachedState?.channelID !== payload.channel_id) {
if (cachedState?.channelId !== payload.channel_id) {
// Either joined or moved channels
if (payload.channel_id) {
if (cachedState?.channelID) { // Was in a channel before
if (cachedState?.channelId) { // Was in a channel before
eventHandlers.voiceChannelSwitch?.(
member,
payload.channel_id,
cachedState.channelID,
cachedState.channelId,
);
} else { // Was not in a channel before so user just joined
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
}
} // Left the channel
else if (cachedState?.channelID) {
else if (cachedState?.channelId) {
guild.voiceStates.delete(payload.user_id);
eventHandlers.voiceChannelLeave?.(member, cachedState.channelID);
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
}
}