mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
feat: Stages, Scheduled events (#44)
Stages Intance and Guild Scheduled Events
This commit is contained in:
commit
6ad22bb44d
@ -16,6 +16,8 @@ import type {
|
|||||||
DiscordIntegration,
|
DiscordIntegration,
|
||||||
DiscordIntegrationDelete,
|
DiscordIntegrationDelete,
|
||||||
DiscordInteraction,
|
DiscordInteraction,
|
||||||
|
DiscordInviteCreate,
|
||||||
|
DiscordInviteDelete,
|
||||||
DiscordMemberWithUser,
|
DiscordMemberWithUser,
|
||||||
DiscordMessage,
|
DiscordMessage,
|
||||||
DiscordMessageDelete,
|
DiscordMessageDelete,
|
||||||
@ -25,24 +27,26 @@ import type {
|
|||||||
DiscordMessageReactionRemoveEmoji,
|
DiscordMessageReactionRemoveEmoji,
|
||||||
DiscordReady,
|
DiscordReady,
|
||||||
DiscordRole,
|
DiscordRole,
|
||||||
|
DiscordScheduledEvent,
|
||||||
|
DiscordScheduledEventUserAdd,
|
||||||
|
DiscordScheduledEventUserRemove,
|
||||||
// DiscordThreadMemberUpdate,
|
// DiscordThreadMemberUpdate,
|
||||||
// DiscordThreadMembersUpdate,
|
// DiscordThreadMembersUpdate,
|
||||||
DiscordThreadListSync,
|
DiscordThreadListSync,
|
||||||
DiscordTypingStart,
|
DiscordTypingStart,
|
||||||
DiscordUser,
|
DiscordUser,
|
||||||
DiscordWebhookUpdate,
|
DiscordWebhookUpdate,
|
||||||
DiscordInviteCreate,
|
|
||||||
DiscordInviteDelete
|
|
||||||
} from "../discordeno/mod.ts";
|
} from "../discordeno/mod.ts";
|
||||||
|
|
||||||
import type { Snowflake } from "./Snowflake.ts";
|
import type { Snowflake } from "./Snowflake.ts";
|
||||||
import type { Session } from "./Session.ts";
|
import type { Session } from "./Session.ts";
|
||||||
import type { Interaction } from "./structures/interactions/InteractionFactory.ts";
|
import type { Interaction } from "./structures/interactions/InteractionFactory.ts";
|
||||||
|
|
||||||
|
|
||||||
import { AutoModerationRule } from "./structures/AutoModerationRule.ts";
|
import { AutoModerationRule } from "./structures/AutoModerationRule.ts";
|
||||||
import { AutoModerationExecution } from "./structures/AutoModerationExecution.ts";
|
import { AutoModerationExecution } from "./structures/AutoModerationExecution.ts";
|
||||||
import { type Channel, ChannelFactory, GuildChannel, ThreadChannel } from "./structures/channels.ts";
|
import { type Channel, ChannelFactory, GuildChannel, ThreadChannel } from "./structures/channels.ts";
|
||||||
|
import { type DiscordStageInstance, StageInstance } from "./structures/StageInstance.ts";
|
||||||
|
import { ScheduledEvent } from "./structures/GuildScheduledEvent.ts";
|
||||||
|
|
||||||
import ThreadMember from "./structures/ThreadMember.ts";
|
import ThreadMember from "./structures/ThreadMember.ts";
|
||||||
import Member from "./structures/Member.ts";
|
import Member from "./structures/Member.ts";
|
||||||
@ -51,7 +55,7 @@ import User from "./structures/User.ts";
|
|||||||
import Integration from "./structures/Integration.ts";
|
import Integration from "./structures/Integration.ts";
|
||||||
import Guild from "./structures/guilds/Guild.ts";
|
import Guild from "./structures/guilds/Guild.ts";
|
||||||
import InteractionFactory from "./structures/interactions/InteractionFactory.ts";
|
import InteractionFactory from "./structures/interactions/InteractionFactory.ts";
|
||||||
import { NewInviteCreate, InviteCreate } from "./structures/Invite.ts";
|
import { InviteCreate, NewInviteCreate } from "./structures/Invite.ts";
|
||||||
|
|
||||||
export type RawHandler<T> = (...args: [Session, number, T]) => void;
|
export type RawHandler<T> = (...args: [Session, number, T]) => void;
|
||||||
export type Handler<T extends unknown[]> = (...args: T) => unknown;
|
export type Handler<T extends unknown[]> = (...args: T) => unknown;
|
||||||
@ -280,11 +284,59 @@ export const MESSAGE_REACTION_REMOVE_EMOJI: RawHandler<DiscordMessageReactionRem
|
|||||||
|
|
||||||
export const INVITE_CREATE: RawHandler<DiscordInviteCreate> = (session, _shardId, invite) => {
|
export const INVITE_CREATE: RawHandler<DiscordInviteCreate> = (session, _shardId, invite) => {
|
||||||
session.emit("inviteCreate", NewInviteCreate(session, invite));
|
session.emit("inviteCreate", NewInviteCreate(session, invite));
|
||||||
}
|
};
|
||||||
|
|
||||||
export const INVITE_DELETE: RawHandler<DiscordInviteDelete> = (session, _shardId, data) => {
|
export const INVITE_DELETE: RawHandler<DiscordInviteDelete> = (session, _shardId, data) => {
|
||||||
session.emit("inviteDelete", { channelId: data.channel_id, guildId: data.guild_id, code: data.code });
|
session.emit("inviteDelete", { channelId: data.channel_id, guildId: data.guild_id, code: data.code });
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export const STAGE_INSTANCE_CREATE: RawHandler<DiscordStageInstance> = (session, _shardId, payload) => {
|
||||||
|
session.emit("stageInstanceCreate", new StageInstance(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const STAGE_INSTANCE_UPDATE: RawHandler<DiscordStageInstance> = (session, _shardId, payload) => {
|
||||||
|
session.emit("stageInstanceUpdate", new StageInstance(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const STAGE_INSTANCE_DELETE: RawHandler<DiscordStageInstance> = (session, _shardId, payload) => {
|
||||||
|
session.emit("stageInstanceDelete", new StageInstance(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_SCHEDULED_EVENT_CREATE: RawHandler<DiscordScheduledEvent> = (session, _shardId, payload) => {
|
||||||
|
session.emit("guildScheduledEventCreate", new ScheduledEvent(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_SCHEDULED_EVENT_UPDATE: RawHandler<DiscordScheduledEvent> = (session, _shardId, payload) => {
|
||||||
|
session.emit("guildScheduledEventUpdate", new ScheduledEvent(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_SCHEDULED_EVENT_DELETE: RawHandler<DiscordScheduledEvent> = (session, _shardId, payload) => {
|
||||||
|
session.emit("guildScheduledEventDelete", new ScheduledEvent(session, payload));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_SCHEDULED_EVENT_USER_ADD: RawHandler<DiscordScheduledEventUserAdd> = (
|
||||||
|
session,
|
||||||
|
_shardId,
|
||||||
|
payload,
|
||||||
|
) => {
|
||||||
|
session.emit("guildScheduledEventUserAdd", {
|
||||||
|
scheduledEventId: payload.guild_scheduled_event_id,
|
||||||
|
userId: payload.user_id,
|
||||||
|
guildId: payload.guild_id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GUILD_SCHEDULED_EVENT_USER_REMOVE: RawHandler<DiscordScheduledEventUserRemove> = (
|
||||||
|
session,
|
||||||
|
_shardId,
|
||||||
|
payload,
|
||||||
|
) => {
|
||||||
|
session.emit("guildScheduledEventUserRemove", {
|
||||||
|
scheduledEventId: payload.guild_scheduled_event_id,
|
||||||
|
userId: payload.user_id,
|
||||||
|
guildId: payload.guild_id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const raw: RawHandler<unknown> = (session, shardId, data) => {
|
export const raw: RawHandler<unknown> = (session, shardId, data) => {
|
||||||
session.emit("raw", data, shardId);
|
session.emit("raw", data, shardId);
|
||||||
@ -337,6 +389,14 @@ export interface Events {
|
|||||||
"autoModerationRuleUpdate": Handler<[AutoModerationRule]>;
|
"autoModerationRuleUpdate": Handler<[AutoModerationRule]>;
|
||||||
"autoModerationRuleDelete": Handler<[AutoModerationRule]>;
|
"autoModerationRuleDelete": Handler<[AutoModerationRule]>;
|
||||||
"autoModerationActionExecution":Handler<[AutoModerationExecution]>
|
"autoModerationActionExecution":Handler<[AutoModerationExecution]>
|
||||||
|
"stageInstanceCreate": Handler<[StageInstance]>;
|
||||||
|
"stageInstanceUpdate": Handler<[StageInstance]>;
|
||||||
|
"stageInstanceDelete": Handler<[StageInstance]>;
|
||||||
|
"guildScheduledEventCreate": Handler<[ScheduledEvent]>;
|
||||||
|
"guildScheduledEventUpdate": Handler<[ScheduledEvent]>;
|
||||||
|
"guildScheduledEventDelete": Handler<[ScheduledEvent]>;
|
||||||
|
"guildScheduledEventUserAdd": Handler<[{scheduledEventId: Snowflake, userId: Snowflake, guildId: Snowflake}]>
|
||||||
|
"guildScheduledEventUserRemove": Handler<[{scheduledEventId: Snowflake, userId: Snowflake, guildId: Snowflake}]>
|
||||||
"raw": Handler<[unknown, number]>;
|
"raw": Handler<[unknown, number]>;
|
||||||
"webhooksUpdate": Handler<[{ guildId: Snowflake, channelId: Snowflake }]>;
|
"webhooksUpdate": Handler<[{ guildId: Snowflake, channelId: Snowflake }]>;
|
||||||
"userUpdate": Handler<[User]>;
|
"userUpdate": Handler<[User]>;
|
||||||
|
@ -3,14 +3,14 @@ import type { Snowflake } from "../Snowflake.ts";
|
|||||||
import type { Session } from "../Session.ts";
|
import type { Session } from "../Session.ts";
|
||||||
import {
|
import {
|
||||||
DiscordApplication,
|
DiscordApplication,
|
||||||
TeamMembershipStates,
|
|
||||||
DiscordInstallParams,
|
DiscordInstallParams,
|
||||||
|
DiscordTeam,
|
||||||
DiscordUser,
|
DiscordUser,
|
||||||
DiscordTeam
|
TeamMembershipStates,
|
||||||
} from "../../discordeno/mod.ts";
|
} from "../../discordeno/mod.ts";
|
||||||
import User from "./User.ts";
|
import User from "./User.ts";
|
||||||
|
|
||||||
type SummaryDeprecated = ""
|
type SummaryDeprecated = "";
|
||||||
|
|
||||||
export interface Team {
|
export interface Team {
|
||||||
/** a hash of the image of the team's icon */
|
/** a hash of the image of the team's icon */
|
||||||
@ -32,7 +32,7 @@ export interface TeamMember {
|
|||||||
|
|
||||||
teamId: string;
|
teamId: string;
|
||||||
|
|
||||||
user: Partial<User> & Pick<User, "avatarHash" | "discriminator" | "id" | "username">
|
user: Partial<User> & Pick<User, "avatarHash" | "discriminator" | "id" | "username">;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTeam create a new Team object for discord applications
|
// NewTeam create a new Team object for discord applications
|
||||||
@ -40,23 +40,22 @@ export function NewTeam(session: Session, data: DiscordTeam): Team {
|
|||||||
return {
|
return {
|
||||||
icon: data.icon ? data.icon : undefined,
|
icon: data.icon ? data.icon : undefined,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
members: data.members.map(member => {
|
members: data.members.map((member) => {
|
||||||
return {
|
return {
|
||||||
membershipState: member.membership_state,
|
membershipState: member.membership_state,
|
||||||
permissions: member.permissions,
|
permissions: member.permissions,
|
||||||
teamId: member.team_id,
|
teamId: member.team_id,
|
||||||
user: new User(session, member.user)
|
user: new User(session, member.user),
|
||||||
}
|
};
|
||||||
}),
|
}),
|
||||||
ownerUserId: data.owner_user_id,
|
ownerUserId: data.owner_user_id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @link https://discord.com/developers/docs/resources/application#application-object
|
* @link https://discord.com/developers/docs/resources/application#application-object
|
||||||
*/
|
*/
|
||||||
export class Application implements Model {
|
export class Application implements Model {
|
||||||
|
|
||||||
constructor(session: Session, data: DiscordApplication) {
|
constructor(session: Session, data: DiscordApplication) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
48
packages/biscuit/structures/GuildScheduledEvent.ts
Normal file
48
packages/biscuit/structures/GuildScheduledEvent.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import type { Model } from "./Base.ts";
|
||||||
|
import type { Snowflake } from "../Snowflake.ts";
|
||||||
|
import type { Session } from "../Session.ts";
|
||||||
|
import { PrivacyLevels } from "./StageInstance.ts";
|
||||||
|
import type {
|
||||||
|
DiscordScheduledEvent,
|
||||||
|
DiscordScheduledEventEntityMetadata,
|
||||||
|
ScheduledEventEntityType,
|
||||||
|
ScheduledEventStatus,
|
||||||
|
} from "../../discordeno/mod.ts";
|
||||||
|
import User from "./User.ts";
|
||||||
|
|
||||||
|
export class ScheduledEvent implements Model {
|
||||||
|
constructor(session: Session, data: DiscordScheduledEvent) {
|
||||||
|
this.session = session;
|
||||||
|
this.id = data.id;
|
||||||
|
this.guildId = data.guild_id;
|
||||||
|
this.channelId = data.channel_id;
|
||||||
|
this.creatorId = data.creator_id ? data.creator_id : undefined;
|
||||||
|
this.name = data.name;
|
||||||
|
this.description = data.description;
|
||||||
|
this.scheduledStartTime = data.scheduled_start_time;
|
||||||
|
this.scheduledEndTime = data.scheduled_end_time;
|
||||||
|
this.privacyLevel = PrivacyLevels.GuildOnly;
|
||||||
|
this.status = data.status;
|
||||||
|
this.entityType = data.entity_type;
|
||||||
|
this.entityMetadata = data.entity_metadata ? data.entity_metadata : undefined;
|
||||||
|
this.creator = data.creator ? new User(session, data.creator) : undefined;
|
||||||
|
this.userCount = data.user_count;
|
||||||
|
this.image = data.image ? data.image : undefined;
|
||||||
|
}
|
||||||
|
session: Session;
|
||||||
|
id: Snowflake;
|
||||||
|
guildId: Snowflake;
|
||||||
|
channelId: Snowflake | null;
|
||||||
|
creatorId?: Snowflake;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
scheduledStartTime: string;
|
||||||
|
scheduledEndTime: string | null;
|
||||||
|
privacyLevel: PrivacyLevels;
|
||||||
|
status: ScheduledEventStatus;
|
||||||
|
entityType: ScheduledEventEntityType;
|
||||||
|
entityMetadata?: DiscordScheduledEventEntityMetadata;
|
||||||
|
creator?: User;
|
||||||
|
userCount?: number;
|
||||||
|
image?: string;
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
import type { Session } from "../Session.ts";
|
import type { Session } from "../Session.ts";
|
||||||
import type { Snowflake } from "../Snowflake.ts";
|
import type { Snowflake } from "../Snowflake.ts";
|
||||||
import type {
|
import type {
|
||||||
|
DiscordApplication,
|
||||||
DiscordChannel,
|
DiscordChannel,
|
||||||
DiscordInvite,
|
DiscordInvite,
|
||||||
|
DiscordInviteCreate,
|
||||||
DiscordMemberWithUser,
|
DiscordMemberWithUser,
|
||||||
DiscordScheduledEventEntityMetadata,
|
DiscordScheduledEventEntityMetadata,
|
||||||
ScheduledEventEntityType,
|
ScheduledEventEntityType,
|
||||||
ScheduledEventPrivacyLevel,
|
ScheduledEventPrivacyLevel,
|
||||||
ScheduledEventStatus,
|
ScheduledEventStatus,
|
||||||
DiscordApplication,
|
|
||||||
DiscordInviteCreate
|
|
||||||
} from "../../discordeno/mod.ts";
|
} from "../../discordeno/mod.ts";
|
||||||
import { TargetTypes } from "../../discordeno/mod.ts";
|
import { TargetTypes } from "../../discordeno/mod.ts";
|
||||||
import { GuildChannel } from "./channels.ts";
|
import { GuildChannel } from "./channels.ts";
|
||||||
@ -75,10 +75,12 @@ export function NewInviteCreate(session: Session, invite: DiscordInviteCreate):
|
|||||||
maxUses: invite.max_uses,
|
maxUses: invite.max_uses,
|
||||||
targetType: invite.target_type,
|
targetType: invite.target_type,
|
||||||
targetUser: invite.target_user ? new User(session, invite.target_user) : undefined,
|
targetUser: invite.target_user ? new User(session, invite.target_user) : undefined,
|
||||||
targetApplication: invite.target_application ? new Application(session, invite.target_application as DiscordApplication) : undefined,
|
targetApplication: invite.target_application
|
||||||
|
? new Application(session, invite.target_application as DiscordApplication)
|
||||||
|
: undefined,
|
||||||
temporary: invite.temporary,
|
temporary: invite.temporary,
|
||||||
uses: invite.uses
|
uses: invite.uses,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +97,9 @@ export class Invite {
|
|||||||
this.expiresAt = data.expires_at ? Number.parseInt(data.expires_at) : undefined;
|
this.expiresAt = data.expires_at ? Number.parseInt(data.expires_at) : undefined;
|
||||||
this.inviter = data.inviter ? new User(session, data.inviter) : undefined;
|
this.inviter = data.inviter ? new User(session, data.inviter) : undefined;
|
||||||
this.targetUser = data.target_user ? new User(session, data.target_user) : undefined;
|
this.targetUser = data.target_user ? new User(session, data.target_user) : undefined;
|
||||||
this.targetApplication = data.target_application ? new Application(session, data.target_application as DiscordApplication) : undefined;
|
this.targetApplication = data.target_application
|
||||||
|
? new Application(session, data.target_application as DiscordApplication)
|
||||||
|
: undefined;
|
||||||
this.targetType = data.target_type;
|
this.targetType = data.target_type;
|
||||||
|
|
||||||
if (data.channel) {
|
if (data.channel) {
|
||||||
@ -157,7 +161,7 @@ export class Invite {
|
|||||||
channel?: Partial<GuildChannel>;
|
channel?: Partial<GuildChannel>;
|
||||||
stageInstance?: InviteStageInstance;
|
stageInstance?: InviteStageInstance;
|
||||||
guildScheduledEvent?: InviteScheduledEvent;
|
guildScheduledEvent?: InviteScheduledEvent;
|
||||||
targetApplication?: Partial<Application>
|
targetApplication?: Partial<Application>;
|
||||||
|
|
||||||
async delete(): Promise<Invite> {
|
async delete(): Promise<Invite> {
|
||||||
await Guild.prototype.deleteInvite.call(this.guild, this.code);
|
await Guild.prototype.deleteInvite.call(this.guild, this.code);
|
||||||
|
@ -4,7 +4,7 @@ import type { Snowflake } from "../Snowflake.ts";
|
|||||||
import type { DiscordStageInstance as DiscordAutoClosingStageInstance } from "../../discordeno/mod.ts";
|
import type { DiscordStageInstance as DiscordAutoClosingStageInstance } from "../../discordeno/mod.ts";
|
||||||
import * as Routes from "../Routes.ts";
|
import * as Routes from "../Routes.ts";
|
||||||
|
|
||||||
interface DiscordStageInstance extends DiscordAutoClosingStageInstance {
|
export interface DiscordStageInstance extends DiscordAutoClosingStageInstance {
|
||||||
privacy_level: PrivacyLevels;
|
privacy_level: PrivacyLevels;
|
||||||
discoverable_disabled: boolean;
|
discoverable_disabled: boolean;
|
||||||
guild_scheduled_event_id: Snowflake;
|
guild_scheduled_event_id: Snowflake;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user