mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
refactor: typings using ReturnType (#2105)
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
This commit is contained in:
co-authored by
LTS20050703
parent
da29ff294d
commit
a0a1554756
+22
-22
@@ -3,54 +3,54 @@ import {
|
||||
Bot,
|
||||
Collection,
|
||||
CreateMessage,
|
||||
DiscordenoChannel,
|
||||
DiscordenoMember,
|
||||
DiscordenoMessage,
|
||||
Channel,
|
||||
Member,
|
||||
Message,
|
||||
FinalHelpers,
|
||||
ListGuildMembers,
|
||||
ModifyThread,
|
||||
} from "./deps.ts";
|
||||
import { cloneChannel } from "./src/channels.ts";
|
||||
import { sendAutocompleteChoices } from "./src/sendAutoCompleteChoices.ts";
|
||||
import { sendDirectMessage } from "./src/sendDirectMessage.ts";
|
||||
import { suppressEmbeds } from "./src/suppressEmbeds.ts";
|
||||
import { archiveThread, editThread, lockThread, unarchiveThread, unlockThread } from "./src/threads.ts";
|
||||
import { archiveThread, editThread, lockThread, ModifyThread, unarchiveThread, unlockThread } from "./src/threads.ts";
|
||||
import { disconnectMember } from "./src/disconnectMember.ts";
|
||||
import { getMembersPaginated } from "./src/getMembersPaginated.ts";
|
||||
import { moveMember } from "./src/moveMember.ts";
|
||||
import { fetchAndRetrieveMembers } from "./src/fetchAndRetrieveMembers.ts";
|
||||
import { BotWithCache } from "../cache/src/addCacheCollections.ts";
|
||||
import { sendTextMessage } from "./src/sendTextMessage.ts";
|
||||
|
||||
export interface BotWithHelpersPlugin extends Bot {
|
||||
helpers: FinalHelpers & {
|
||||
fetchAndRetrieveMembers: (
|
||||
guildId: bigint,
|
||||
) => Promise<Collection<bigint, DiscordenoMember>>;
|
||||
) => Promise<Collection<bigint, Member>>;
|
||||
sendDirectMessage: (
|
||||
userId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => Promise<DiscordenoMessage>;
|
||||
) => Promise<Message>;
|
||||
sendTextMessage: (
|
||||
channelId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => Promise<DiscordenoMessage>;
|
||||
) => Promise<Message>;
|
||||
suppressEmbeds: (
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
) => Promise<DiscordenoMessage>;
|
||||
archiveThread: (threadId: bigint) => Promise<DiscordenoChannel>;
|
||||
unarchiveThread: (threadId: bigint) => Promise<DiscordenoChannel>;
|
||||
lockThread: (threadId: bigint) => Promise<DiscordenoChannel>;
|
||||
unlockThread: (threadId: bigint) => Promise<DiscordenoChannel>;
|
||||
) => Promise<Message>;
|
||||
archiveThread: (threadId: bigint) => Promise<Channel>;
|
||||
unarchiveThread: (threadId: bigint) => Promise<Channel>;
|
||||
lockThread: (threadId: bigint) => Promise<Channel>;
|
||||
unlockThread: (threadId: bigint) => Promise<Channel>;
|
||||
editThread: (
|
||||
threadId: bigint,
|
||||
options: ModifyThread,
|
||||
reason?: string,
|
||||
) => Promise<DiscordenoChannel>;
|
||||
) => Promise<Channel>;
|
||||
cloneChannel: (
|
||||
channel: DiscordenoChannel,
|
||||
channel: Channel,
|
||||
reason?: string,
|
||||
) => Promise<DiscordenoChannel>;
|
||||
) => Promise<Channel>;
|
||||
sendAutocompleteChoices: (
|
||||
interactionId: bigint,
|
||||
interactionToken: string,
|
||||
@@ -59,16 +59,16 @@ export interface BotWithHelpersPlugin extends Bot {
|
||||
disconnectMember: (
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
) => Promise<DiscordenoMember>;
|
||||
) => Promise<Member>;
|
||||
getMembersPaginated: (
|
||||
guildId: bigint,
|
||||
options: ListGuildMembers & { memberCount: number },
|
||||
) => Promise<Collection<bigint, DiscordenoMember>>;
|
||||
options: ListGuildMembers,
|
||||
) => Promise<Collection<bigint, Member>>;
|
||||
moveMember: (
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
channelId: bigint,
|
||||
) => Promise<DiscordenoMember>;
|
||||
) => Promise<Member>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin {
|
||||
options: ModifyThread,
|
||||
reason?: string,
|
||||
) => editThread(bot, threadId, options, reason);
|
||||
bot.helpers.cloneChannel = (channel: DiscordenoChannel, reason?: string) => cloneChannel(bot, channel, reason);
|
||||
bot.helpers.cloneChannel = (channel: Channel, reason?: string) => cloneChannel(bot, channel, reason);
|
||||
bot.helpers.sendAutocompleteChoices = (
|
||||
interactionId: bigint,
|
||||
interactionToken: string,
|
||||
@@ -105,7 +105,7 @@ export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin {
|
||||
bot.helpers.disconnectMember = (guildId: bigint, memberId: bigint) => disconnectMember(bot, guildId, memberId);
|
||||
bot.helpers.getMembersPaginated = (
|
||||
guildId: bigint,
|
||||
options: ListGuildMembers & { memberCount: number },
|
||||
options: ListGuildMembers,
|
||||
) => getMembersPaginated(bot, guildId, options);
|
||||
bot.helpers.moveMember = (
|
||||
guildId: bigint,
|
||||
|
||||
@@ -8,14 +8,14 @@ import { Bot, Collection, DiscordenoMember, GuildMemberWithUser, ListGuildMember
|
||||
export async function getMembersPaginated(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
options: ListGuildMembers & { memberCount: number },
|
||||
options: ListGuildMembers,
|
||||
) {
|
||||
const members = new Collection<bigint, DiscordenoMember>();
|
||||
|
||||
let membersLeft = options?.limit ?? options.memberCount;
|
||||
let membersLeft = options?.limit ?? 1000;
|
||||
let loops = 1;
|
||||
while (
|
||||
(options?.limit ?? options.memberCount) > members.size &&
|
||||
(options?.limit ?? 1000) > members.size &&
|
||||
membersLeft > 0
|
||||
) {
|
||||
bot.events.debug("Running while loop in getMembers function.");
|
||||
@@ -57,7 +57,6 @@ export async function getMembersPaginated(
|
||||
options = {
|
||||
limit: options?.limit,
|
||||
after: discordenoMembers[discordenoMembers.length - 1].id.toString(),
|
||||
memberCount: options.memberCount,
|
||||
};
|
||||
|
||||
membersLeft -= 1000;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot, Channel, ModifyThread } from "../deps.ts";
|
||||
import { Bot, DiscordChannel } from "../deps.ts";
|
||||
|
||||
/** Sets a thread channel to be archived. */
|
||||
export async function archiveThread(bot: Bot, threadId: bigint) {
|
||||
@@ -22,7 +22,7 @@ export async function unlockThread(bot: Bot, threadId: bigint) {
|
||||
|
||||
/** Update a thread's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||
export async function editThread(bot: Bot, threadId: bigint, options: ModifyThread, reason?: string) {
|
||||
const result = await bot.rest.runMethod<Channel>(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(threadId), {
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(threadId), {
|
||||
name: options.name,
|
||||
archived: options.archived,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
@@ -36,3 +36,19 @@ export async function editThread(bot: Bot, threadId: bigint, options: ModifyThre
|
||||
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/channel#modify-channel-json-params-thread */
|
||||
export interface ModifyThread {
|
||||
/** 1-100 character thread name */
|
||||
name?: string;
|
||||
/** Whether the thread is archived */
|
||||
archived?: boolean;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
|
||||
/** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */
|
||||
locked?: boolean;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available on private threads */
|
||||
invitable?: boolean;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `MANAGE_MESSAGES`, `MANAGE_THREAD` or `MANAGE_CHANNEL` are unaffected */
|
||||
rateLimitPerUser?: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user