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:
Skillz4Killz
2022-03-14 22:11:22 -04:00
committed by GitHub
parent da29ff294d
commit a0a1554756
505 changed files with 5647 additions and 7106 deletions
@@ -1,10 +1,6 @@
import { Bot } from "../../../bot.ts";
import {
CreateScheduledEvent,
ScheduledEvent,
ScheduledEventEntityType,
ScheduledEventPrivacyLevel,
} from "../../../types/guilds/scheduledEvents.ts";
import { DiscordScheduledEvent } from "../../../types/discord.ts";
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../types/shared.ts";
/** Create a guild scheduled event in the guild. A guild can have a maximum of 100 events with `SCHEDULED` or `ACTIVE` status at any time. */
export async function createScheduledEvent(bot: Bot, guildId: bigint, options: CreateScheduledEvent) {
@@ -30,7 +26,7 @@ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: C
throw new Error("Cannot schedule event to end before starting.");
}
const event = await bot.rest.runMethod<ScheduledEvent>(
const event = await bot.rest.runMethod<DiscordScheduledEvent>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId),
@@ -49,3 +45,23 @@ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: C
return bot.transformers.scheduledEvent(bot, event);
}
export interface CreateScheduledEvent {
/** the channel id of the scheduled event. */
channelId?: bigint;
/** location of the event */
location?: string;
/** the name of the scheduled event */
name: string;
/** the description of the scheduled event */
description: string;
/** the time the scheduled event will start */
scheduledStartTime: number;
/** the time the scheduled event will end if it does end. */
scheduledEndTime?: number;
/** the privacy level of the scheduled event */
privacyLevel?: ScheduledEventPrivacyLevel;
/** the type of hosting entity associated with a scheduled event */
entityType: ScheduledEventEntityType;
reason?: string;
}
@@ -1,5 +1,6 @@
import { Bot } from "../../../bot.ts";
import { EditScheduledEvent, ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
import { DiscordScheduledEvent } from "../../../types/discord.ts";
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus } from "../../../types/shared.ts";
/** Modify a guild scheduled event. To start or end an event, use this endpoint to modify the event's status. */
export async function editScheduledEvent(
@@ -21,7 +22,7 @@ export async function editScheduledEvent(
throw new Error("Cannot schedule event to end before starting.");
}
const event = await bot.rest.runMethod<ScheduledEvent>(
const event = await bot.rest.runMethod<DiscordScheduledEvent>(
bot.rest,
"patch",
bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId),
@@ -41,3 +42,25 @@ export async function editScheduledEvent(
return bot.transformers.scheduledEvent(bot, event);
}
export interface EditScheduledEvent {
/** the channel id of the scheduled event. null if switching to external event. */
channelId: bigint | null;
/** location of the event */
location: string;
/** the name of the scheduled event */
name: string;
/** the description of the scheduled event */
description: string;
/** the time the scheduled event will start */
scheduledStartTime: number;
/** the time the scheduled event will end if it does end. */
scheduledEndTime?: number;
/** the privacy level of the scheduled event */
privacyLevel: ScheduledEventPrivacyLevel;
/** the type of hosting entity associated with a scheduled event */
entityType: ScheduledEventEntityType;
/** the status of the scheduled event */
status: ScheduledEventStatus;
reason?: string;
}
@@ -1,5 +1,5 @@
import { Bot } from "../../../bot.ts";
import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
import { DiscordScheduledEvent } from "../../../types/discord.ts";
/** Get a guild scheduled event. */
export async function getScheduledEvent(
@@ -8,7 +8,7 @@ export async function getScheduledEvent(
eventId: bigint,
options?: { withUserCount?: boolean },
) {
const event = await bot.rest.runMethod<ScheduledEvent>(
const event = await bot.rest.runMethod<DiscordScheduledEvent>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId),
@@ -1,8 +1,6 @@
import { Bot } from "../../../bot.ts";
import { DiscordenoMember, DiscordenoUser } from "../../../transformers/member.ts";
import { GetScheduledEventUsers } from "../../../types/guilds/scheduledEvents.ts";
import { GuildMember } from "../../../types/members/guildMember.ts";
import { User } from "../../../types/users/user.ts";
import { Member, User } from "../../../transformers/member.ts";
import { DiscordMember, DiscordUser } from "../../../types/discord.ts";
import { Collection } from "../../../util/collection.ts";
export async function getScheduledEventUsers(
@@ -10,24 +8,22 @@ export async function getScheduledEventUsers(
guildId: bigint,
eventId: bigint,
options?: GetScheduledEventUsers & { withMember?: false },
): Promise<Collection<bigint, DiscordenoUser>>;
): Promise<Collection<bigint, User>>;
export async function getScheduledEventUsers(
bot: Bot,
guildId: bigint,
eventId: bigint,
options?: GetScheduledEventUsers & { withMember: true },
): Promise<Collection<bigint, { user: DiscordenoUser; member: DiscordenoMember }>>;
): Promise<Collection<bigint, { user: User; member: Member }>>;
export async function getScheduledEventUsers(
bot: Bot,
guildId: bigint,
eventId: bigint,
options?: GetScheduledEventUsers,
): Promise<
Collection<bigint, DiscordenoUser> | Collection<bigint, { user: DiscordenoUser; member: DiscordenoMember }>
Collection<bigint, User> | Collection<bigint, { user: User; member: Member }>
> {
// TODO: is the guild member omit user
const result = await bot.rest.runMethod<{ user: User; member?: GuildMember }[]>(
const result = await bot.rest.runMethod<{ user: DiscordUser; member?: DiscordMember }[]>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId),
@@ -55,3 +51,14 @@ export async function getScheduledEventUsers(
}),
);
}
export interface GetScheduledEventUsers {
/** number of users to return (up to maximum 100), defaults to 100 */
limit?: number;
/** whether to also have member objects provided, defaults to false */
withMember?: boolean;
/** consider only users before given user id */
before?: bigint;
/** consider only users after given user id */
after?: bigint;
}
@@ -1,11 +1,11 @@
import { Bot } from "../../../bot.ts";
import { DiscordenoScheduledEvent } from "../../../transformers/scheduledEvent.ts";
import { GetScheduledEvents, ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts";
import { DiscordScheduledEvent } from "../../../types/discord.ts";
import { Collection } from "../../../util/collection.ts";
/** Get a list of guild scheduled event for the given guild. */
export async function getScheduledEvents(bot: Bot, guildId: bigint, options?: GetScheduledEvents) {
const events = await bot.rest.runMethod<ScheduledEvent[]>(
const events = await bot.rest.runMethod<DiscordScheduledEvent[]>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId),
@@ -14,10 +14,15 @@ export async function getScheduledEvents(bot: Bot, guildId: bigint, options?: Ge
},
);
return new Collection<bigint, DiscordenoScheduledEvent>(
return new Collection<bigint, ScheduledEvent>(
events.map((e) => {
const event = bot.transformers.scheduledEvent(bot, e);
return [event.id, event];
}),
);
}
export interface GetScheduledEvents {
/** include number of users subscribed to each event */
withUserCount?: boolean;
}