This commit is contained in:
Yuzu 2022-07-01 10:12:48 -05:00
parent fcf8c60cca
commit 42e5c9f62b
4 changed files with 19 additions and 20 deletions

View File

@ -6,7 +6,7 @@ export class Component {
constructor(session: Session, data: DiscordComponent) {
this.session = session;
this.customId = data.custom_id;
this.type = data.type
this.type = data.type;
this.components = data.components?.map((component) => new Component(session, component));
this.disabled = !!data.disabled;

View File

@ -72,7 +72,8 @@ export class Guild extends BaseGuild implements Model {
this.vefificationLevel = data.verification_level;
this.defaultMessageNotificationLevel = data.default_message_notifications;
this.explicitContentFilterLevel = data.explicit_content_filter;
this.members = data.members?.map((member) => new Member(session, { ...member, user: member.user! }, data.id)) ?? [];
this.members = data.members?.map((member) => new Member(session, { ...member, user: member.user! }, data.id)) ??
[];
this.roles = data.roles.map((role) => new Role(session, role, data.id));
this.emojis = data.emojis.map((guildEmoji) => new GuildEmoji(session, guildEmoji, data.id));
}
@ -201,7 +202,6 @@ export class Guild extends BaseGuild implements Model {
return invites.map((invite) => new Invite(this.session, invite));
}
/**
* Bans the member
*/

View File

@ -2,11 +2,11 @@ import type { Model } from "./Base.ts";
import type { Snowflake } from "../util/Snowflake.ts";
import type { Session } from "../session/Session.ts";
import type {
DiscordMessage,
DiscordInteraction,
InteractionTypes,
InteractionResponseTypes,
DiscordMessage,
FileContent,
InteractionResponseTypes,
InteractionTypes,
} from "../vendor/external.ts";
import type { MessageFlags } from "../util/shared/flags.ts";
import type { AllowedMentions } from "./Message.ts";
@ -34,8 +34,8 @@ export interface InteractionApplicationCommandCallbackData {
/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice */
export interface ApplicationCommandOptionChoice {
name: string;
value: string | number;
name: string;
value: string | number;
}
export class Interaction implements Model {
@ -43,7 +43,7 @@ export class Interaction implements Model {
this.session = session;
this.id = data.id;
this.token = data.token;
this.type = data.type
this.type = data.type;
this.guildId = data.guild_id;
this.channelId = data.channel_id;
this.applicationId = data.application_id;
@ -52,8 +52,7 @@ export class Interaction implements Model {
if (!data.guild_id) {
this.user = new User(session, data.user!);
}
else {
} else {
this.member = new Member(session, data.member!, data.guild_id);
}
}
@ -104,11 +103,11 @@ export class Interaction implements Model {
file: data?.files,
},
headers: {
// remove authorization header
Authorization: "",
// remove authorization header
Authorization: "",
},
}),
}
},
);
return;
@ -123,21 +122,21 @@ export class Interaction implements Model {
method: "POST",
body: {
...toSend,
file: data?.files
file: data?.files,
},
headers: {
// remove authorization header
Authorization: "",
},
}),
}
},
);
return new Message(this.session, result);
}
inGuild(): this is Interaction & { user: undefined, guildId: Snowflake, member: Member } {
return "guildId" in this;
inGuild(): this is Interaction & { user: undefined; guildId: Snowflake; member: Member } {
return !!this.guildId;
}
}

View File

@ -57,13 +57,13 @@ export class Member implements Model {
}
async ban(options: CreateGuildBan): Promise<Member> {
await Guild.prototype.banMember.call({ id: this.guildId }, this.user.id, options);
await Guild.prototype.banMember.call({ id: this.guildId, session: this.session }, this.user.id, options);
return this;
}
async kick(options: { reason?: string }): Promise<Member> {
await Guild.prototype.kickMember.call({ id: this.guildId }, this.user.id, options);
await Guild.prototype.kickMember.call({ id: this.guildId, session: this.session }, this.user.id, options);
return this;
}