@minesa-org/mini-interaction 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ import { type APIAutoModerationAction, type APIAutoModerationRuleTriggerMetadata, AutoModerationRuleEventType, AutoModerationRuleTriggerType } from "discord-api-types/v10";
2
+ import type { RESTPostAPIAutoModerationRuleJSONBody } from "discord-api-types/v10";
3
+ import type { JSONEncodable } from "./shared.js";
4
+ /**
5
+ * Shape describing initial data used to seed the auto moderation rule builder.
6
+ */
7
+ export type AutomodRuleBuilderData = Partial<RESTPostAPIAutoModerationRuleJSONBody> & {
8
+ name?: string;
9
+ event_type?: AutoModerationRuleEventType;
10
+ trigger_type?: AutoModerationRuleTriggerType;
11
+ actions?: APIAutoModerationAction[];
12
+ };
13
+ /** Builder that produces Discord auto moderation rule payloads. */
14
+ export declare class AutomodRuleBuilder implements JSONEncodable<RESTPostAPIAutoModerationRuleJSONBody> {
15
+ private data;
16
+ constructor(data?: AutomodRuleBuilderData);
17
+ /** Sets the name of the rule. */
18
+ setName(name: string): this;
19
+ /** Sets the event type that will trigger the rule. */
20
+ setEventType(eventType: AutoModerationRuleEventType): this;
21
+ /** Sets the trigger type for the rule. */
22
+ setTriggerType(triggerType: AutoModerationRuleTriggerType): this;
23
+ /**
24
+ * Assigns trigger metadata describing how the rule should match content.
25
+ */
26
+ setTriggerMetadata(metadata: APIAutoModerationRuleTriggerMetadata | null | undefined): this;
27
+ /**
28
+ * Replaces the actions executed when the rule triggers.
29
+ */
30
+ setActions(actions: Array<APIAutoModerationAction | JSONEncodable<APIAutoModerationAction>>): this;
31
+ /** Adds an action to execute when the rule triggers. */
32
+ addAction(action: APIAutoModerationAction | JSONEncodable<APIAutoModerationAction>): this;
33
+ /** Enables or disables the rule. */
34
+ setEnabled(enabled: boolean): this;
35
+ /** Replaces the list of exempt role ids. */
36
+ setExemptRoles(roleIds: string[]): this;
37
+ /** Adds an exempt role id if not already present. */
38
+ addExemptRole(roleId: string): this;
39
+ /** Replaces the list of exempt channel ids. */
40
+ setExemptChannels(channelIds: string[]): this;
41
+ /** Adds an exempt channel id if not already present. */
42
+ addExemptChannel(channelId: string): this;
43
+ /** Serialises the builder into a REST auto moderation rule payload. */
44
+ toJSON(): RESTPostAPIAutoModerationRuleJSONBody;
45
+ }
@@ -0,0 +1,151 @@
1
+ import { resolveJSONEncodable } from "./shared.js";
2
+ /** Builder that produces Discord auto moderation rule payloads. */
3
+ export class AutomodRuleBuilder {
4
+ data;
5
+ constructor(data = {}) {
6
+ this.data = {
7
+ ...data,
8
+ actions: data.actions?.map(cloneAutoModerationAction) ?? [],
9
+ trigger_metadata: data.trigger_metadata
10
+ ? cloneTriggerMetadata(data.trigger_metadata)
11
+ : undefined,
12
+ exempt_roles: data.exempt_roles ? [...data.exempt_roles] : undefined,
13
+ exempt_channels: data.exempt_channels
14
+ ? [...data.exempt_channels]
15
+ : undefined,
16
+ };
17
+ }
18
+ /** Sets the name of the rule. */
19
+ setName(name) {
20
+ this.data.name = name;
21
+ return this;
22
+ }
23
+ /** Sets the event type that will trigger the rule. */
24
+ setEventType(eventType) {
25
+ this.data.event_type = eventType;
26
+ return this;
27
+ }
28
+ /** Sets the trigger type for the rule. */
29
+ setTriggerType(triggerType) {
30
+ this.data.trigger_type = triggerType;
31
+ return this;
32
+ }
33
+ /**
34
+ * Assigns trigger metadata describing how the rule should match content.
35
+ */
36
+ setTriggerMetadata(metadata) {
37
+ this.data.trigger_metadata = metadata
38
+ ? cloneTriggerMetadata(metadata)
39
+ : undefined;
40
+ return this;
41
+ }
42
+ /**
43
+ * Replaces the actions executed when the rule triggers.
44
+ */
45
+ setActions(actions) {
46
+ this.data.actions = actions.map((action) => cloneAutoModerationAction(resolveJSONEncodable(action)));
47
+ return this;
48
+ }
49
+ /** Adds an action to execute when the rule triggers. */
50
+ addAction(action) {
51
+ if (!this.data.actions) {
52
+ this.data.actions = [];
53
+ }
54
+ this.data.actions.push(cloneAutoModerationAction(resolveJSONEncodable(action)));
55
+ return this;
56
+ }
57
+ /** Enables or disables the rule. */
58
+ setEnabled(enabled) {
59
+ this.data.enabled = enabled;
60
+ return this;
61
+ }
62
+ /** Replaces the list of exempt role ids. */
63
+ setExemptRoles(roleIds) {
64
+ this.data.exempt_roles = [...roleIds];
65
+ return this;
66
+ }
67
+ /** Adds an exempt role id if not already present. */
68
+ addExemptRole(roleId) {
69
+ if (!this.data.exempt_roles) {
70
+ this.data.exempt_roles = [];
71
+ }
72
+ if (!this.data.exempt_roles.includes(roleId)) {
73
+ this.data.exempt_roles.push(roleId);
74
+ }
75
+ return this;
76
+ }
77
+ /** Replaces the list of exempt channel ids. */
78
+ setExemptChannels(channelIds) {
79
+ this.data.exempt_channels = [...channelIds];
80
+ return this;
81
+ }
82
+ /** Adds an exempt channel id if not already present. */
83
+ addExemptChannel(channelId) {
84
+ if (!this.data.exempt_channels) {
85
+ this.data.exempt_channels = [];
86
+ }
87
+ if (!this.data.exempt_channels.includes(channelId)) {
88
+ this.data.exempt_channels.push(channelId);
89
+ }
90
+ return this;
91
+ }
92
+ /** Serialises the builder into a REST auto moderation rule payload. */
93
+ toJSON() {
94
+ const { name, event_type, trigger_type } = this.data;
95
+ const actions = this.data.actions ?? [];
96
+ if (!name) {
97
+ throw new Error("[AutomodRuleBuilder] name is required");
98
+ }
99
+ if (event_type === undefined) {
100
+ throw new Error("[AutomodRuleBuilder] event type is required");
101
+ }
102
+ if (trigger_type === undefined) {
103
+ throw new Error("[AutomodRuleBuilder] trigger type is required");
104
+ }
105
+ if (actions.length === 0) {
106
+ throw new Error("[AutomodRuleBuilder] at least one action is required");
107
+ }
108
+ return {
109
+ name,
110
+ event_type,
111
+ trigger_type,
112
+ trigger_metadata: this.data.trigger_metadata
113
+ ? cloneTriggerMetadata(this.data.trigger_metadata)
114
+ : undefined,
115
+ actions: actions.map(cloneAutoModerationAction),
116
+ enabled: this.data.enabled,
117
+ exempt_roles: this.data.exempt_roles
118
+ ? [...this.data.exempt_roles]
119
+ : undefined,
120
+ exempt_channels: this.data.exempt_channels
121
+ ? [...this.data.exempt_channels]
122
+ : undefined,
123
+ };
124
+ }
125
+ }
126
+ function cloneTriggerMetadata(metadata) {
127
+ return {
128
+ keyword_filter: metadata.keyword_filter
129
+ ? [...metadata.keyword_filter]
130
+ : undefined,
131
+ presets: metadata.presets ? [...metadata.presets] : undefined,
132
+ allow_list: metadata.allow_list ? [...metadata.allow_list] : undefined,
133
+ regex_patterns: metadata.regex_patterns
134
+ ? [...metadata.regex_patterns]
135
+ : undefined,
136
+ mention_total_limit: metadata.mention_total_limit,
137
+ mention_raid_protection_enabled: metadata.mention_raid_protection_enabled,
138
+ };
139
+ }
140
+ function cloneAutoModerationAction(action) {
141
+ return {
142
+ type: action.type,
143
+ metadata: action.metadata
144
+ ? {
145
+ channel_id: action.metadata.channel_id,
146
+ duration_seconds: action.metadata.duration_seconds,
147
+ custom_message: action.metadata.custom_message,
148
+ }
149
+ : undefined,
150
+ };
151
+ }
@@ -0,0 +1,33 @@
1
+ import { type APIEmbed, type APIEmbedAuthor, type APIEmbedField, type APIEmbedFooter, type APIEmbedImage, type APIEmbedThumbnail } from "discord-api-types/v10";
2
+ import type { JSONEncodable } from "./shared.js";
3
+ /** Shape describing data used to seed an embed builder instance. */
4
+ export type EmbedBuilderData = Partial<APIEmbed>;
5
+ /** Builder for Discord embed payloads. */
6
+ export declare class EmbedBuilder implements JSONEncodable<APIEmbed> {
7
+ private data;
8
+ constructor(data?: EmbedBuilderData);
9
+ /** Sets or clears the embed title. */
10
+ setTitle(title: string | null | undefined): this;
11
+ /** Sets or clears the embed description. */
12
+ setDescription(description: string | null | undefined): this;
13
+ /** Sets or clears the embed URL. */
14
+ setURL(url: string | null | undefined): this;
15
+ /** Sets or clears the embed color. */
16
+ setColor(color: number | null | undefined): this;
17
+ /** Sets the timestamp value using either a Date or ISO string. */
18
+ setTimestamp(timestamp: Date | number | string | null | undefined): this;
19
+ /** Sets or clears the footer. */
20
+ setFooter(footer: APIEmbedFooter | null | undefined): this;
21
+ /** Sets or clears the image. */
22
+ setImage(image: APIEmbedImage | null | undefined): this;
23
+ /** Sets or clears the thumbnail. */
24
+ setThumbnail(thumbnail: APIEmbedThumbnail | null | undefined): this;
25
+ /** Sets or clears the author. */
26
+ setAuthor(author: APIEmbedAuthor | null | undefined): this;
27
+ /** Replaces the embed fields with the provided values. */
28
+ setFields(fields: APIEmbedField[]): this;
29
+ /** Appends fields to the embed. */
30
+ addFields(...fields: APIEmbedField[]): this;
31
+ /** Serialises the builder into an API compatible embed payload. */
32
+ toJSON(): APIEmbed;
33
+ }
@@ -0,0 +1,94 @@
1
+ /** Builder for Discord embed payloads. */
2
+ export class EmbedBuilder {
3
+ data;
4
+ constructor(data = {}) {
5
+ this.data = {
6
+ ...data,
7
+ footer: data.footer ? { ...data.footer } : undefined,
8
+ image: data.image ? { ...data.image } : undefined,
9
+ thumbnail: data.thumbnail ? { ...data.thumbnail } : undefined,
10
+ author: data.author ? { ...data.author } : undefined,
11
+ fields: data.fields ? data.fields.map((field) => ({ ...field })) : [],
12
+ };
13
+ }
14
+ /** Sets or clears the embed title. */
15
+ setTitle(title) {
16
+ this.data.title = title ?? undefined;
17
+ return this;
18
+ }
19
+ /** Sets or clears the embed description. */
20
+ setDescription(description) {
21
+ this.data.description = description ?? undefined;
22
+ return this;
23
+ }
24
+ /** Sets or clears the embed URL. */
25
+ setURL(url) {
26
+ this.data.url = url ?? undefined;
27
+ return this;
28
+ }
29
+ /** Sets or clears the embed color. */
30
+ setColor(color) {
31
+ this.data.color = color ?? undefined;
32
+ return this;
33
+ }
34
+ /** Sets the timestamp value using either a Date or ISO string. */
35
+ setTimestamp(timestamp) {
36
+ if (timestamp === null || timestamp === undefined) {
37
+ this.data.timestamp = undefined;
38
+ }
39
+ else if (timestamp instanceof Date) {
40
+ this.data.timestamp = timestamp.toISOString();
41
+ }
42
+ else if (typeof timestamp === "number") {
43
+ this.data.timestamp = new Date(timestamp).toISOString();
44
+ }
45
+ else {
46
+ this.data.timestamp = new Date(timestamp).toISOString();
47
+ }
48
+ return this;
49
+ }
50
+ /** Sets or clears the footer. */
51
+ setFooter(footer) {
52
+ this.data.footer = footer ? { ...footer } : undefined;
53
+ return this;
54
+ }
55
+ /** Sets or clears the image. */
56
+ setImage(image) {
57
+ this.data.image = image ? { ...image } : undefined;
58
+ return this;
59
+ }
60
+ /** Sets or clears the thumbnail. */
61
+ setThumbnail(thumbnail) {
62
+ this.data.thumbnail = thumbnail ? { ...thumbnail } : undefined;
63
+ return this;
64
+ }
65
+ /** Sets or clears the author. */
66
+ setAuthor(author) {
67
+ this.data.author = author ? { ...author } : undefined;
68
+ return this;
69
+ }
70
+ /** Replaces the embed fields with the provided values. */
71
+ setFields(fields) {
72
+ this.data.fields = fields.map((field) => ({ ...field }));
73
+ return this;
74
+ }
75
+ /** Appends fields to the embed. */
76
+ addFields(...fields) {
77
+ if (!this.data.fields) {
78
+ this.data.fields = [];
79
+ }
80
+ this.data.fields.push(...fields.map((field) => ({ ...field })));
81
+ return this;
82
+ }
83
+ /** Serialises the builder into an API compatible embed payload. */
84
+ toJSON() {
85
+ return {
86
+ ...this.data,
87
+ footer: this.data.footer ? { ...this.data.footer } : undefined,
88
+ image: this.data.image ? { ...this.data.image } : undefined,
89
+ thumbnail: this.data.thumbnail ? { ...this.data.thumbnail } : undefined,
90
+ author: this.data.author ? { ...this.data.author } : undefined,
91
+ fields: this.data.fields?.map((field) => ({ ...field })),
92
+ };
93
+ }
94
+ }
@@ -0,0 +1,131 @@
1
+ import type { APIComponentInContainer, APIContainerComponent, APIMediaGalleryComponent, APIMediaGalleryItem, APISectionAccessoryComponent, APISectionComponent, APISeparatorComponent, APITextDisplayComponent, APIThumbnailComponent, APIUnfurledMediaItem } from "discord-api-types/v10";
2
+ import { SeparatorSpacingSize } from "discord-api-types/v10";
3
+ import type { JSONEncodable } from "./shared.js";
4
+ /** Structured message container payload. */
5
+ export type MiniContainerComponent = APIContainerComponent;
6
+ /** Section within a structured message container. */
7
+ export type MiniSectionComponent = APISectionComponent;
8
+ /** Text display structured message component. */
9
+ export type MiniTextDisplayComponent = APITextDisplayComponent;
10
+ /** Separator structured message component. */
11
+ export type MiniSeparatorComponent = APISeparatorComponent;
12
+ /** Thumbnail payload used within sections. */
13
+ export type MiniThumbnailComponent = APIThumbnailComponent;
14
+ /** Gallery item payload. */
15
+ export type MiniGalleryItemComponent = APIMediaGalleryItem;
16
+ /** Gallery structured message component. */
17
+ export type MiniGalleryComponent = APIMediaGalleryComponent;
18
+ /** Union of supported components within a container. */
19
+ export type MiniContentComponent = APIComponentInContainer;
20
+ /** Union of supported section accessory components. */
21
+ export type MiniSectionAccessoryComponent = APISectionAccessoryComponent;
22
+ /** Data accepted by the container builder constructor. */
23
+ export type ContainerBuilderData = Partial<Omit<MiniContainerComponent, "components">> & {
24
+ components?: Array<MiniContentComponent | JSONEncodable<MiniContentComponent>>;
25
+ };
26
+ /** Data accepted by the section builder constructor. */
27
+ export type SectionBuilderData = Partial<Omit<MiniSectionComponent, "components" | "accessory">> & {
28
+ components?: Array<MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>>;
29
+ accessory?: MiniSectionAccessoryComponent | JSONEncodable<MiniSectionAccessoryComponent>;
30
+ };
31
+ /** Data accepted by the text display builder constructor. */
32
+ export type TextDisplayBuilderData = Partial<MiniTextDisplayComponent>;
33
+ /** Data accepted by the separator builder constructor. */
34
+ export type SeparatorBuilderData = Partial<MiniSeparatorComponent>;
35
+ /** Data accepted by the gallery builder constructor. */
36
+ export type GalleryBuilderData = Partial<Omit<MiniGalleryComponent, "items">> & {
37
+ items?: Array<MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>>;
38
+ };
39
+ /** Data accepted by the gallery item builder constructor. */
40
+ export type GalleryItemBuilderData = Partial<MiniGalleryItemComponent>;
41
+ /** Data accepted by the thumbnail builder constructor. */
42
+ export type ThumbnailBuilderData = Partial<MiniThumbnailComponent>;
43
+ /** Builder for structured message container payloads. */
44
+ export declare class ContainerBuilder implements JSONEncodable<MiniContainerComponent> {
45
+ private data;
46
+ constructor(data?: ContainerBuilderData);
47
+ /** Replaces the components contained in the container. */
48
+ setComponents(components: Array<MiniContentComponent | JSONEncodable<MiniContentComponent>>): this;
49
+ /** Replaces the sections contained in the container. */
50
+ setSections(sections: Array<MiniSectionComponent | JSONEncodable<MiniSectionComponent>>): this;
51
+ /** Adds a component to the container. */
52
+ addComponent(component: MiniContentComponent | JSONEncodable<MiniContentComponent>): this;
53
+ /** Adds a section to the container. */
54
+ addSection(section: MiniSectionComponent | JSONEncodable<MiniSectionComponent>): this;
55
+ /** Sets or clears the accent colour on the container. */
56
+ setAccentColor(color: number | null | undefined): this;
57
+ /** Marks the container as a spoiler. */
58
+ setSpoiler(spoiler: boolean | null | undefined): this;
59
+ /** Serialises the container into a structured message payload. */
60
+ toJSON(): MiniContainerComponent;
61
+ }
62
+ /** Builder for structured message sections. */
63
+ export declare class SectionBuilder implements JSONEncodable<MiniSectionComponent> {
64
+ private data;
65
+ constructor(data?: SectionBuilderData);
66
+ /** Replaces the text components within the section. */
67
+ setComponents(components: Array<MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>>): this;
68
+ /** Adds a text component to the section. */
69
+ addComponent(component: MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>): this;
70
+ /** Sets or clears the accessory component. */
71
+ setAccessory(accessory: MiniSectionAccessoryComponent | JSONEncodable<MiniSectionAccessoryComponent> | null | undefined): this;
72
+ /** Serialises the section into a structured message payload. */
73
+ toJSON(): MiniSectionComponent;
74
+ }
75
+ /** Builder for structured message text display components. */
76
+ export declare class TextDisplayBuilder implements JSONEncodable<MiniTextDisplayComponent> {
77
+ private data;
78
+ constructor(data?: TextDisplayBuilderData);
79
+ /** Sets or clears the primary text content. */
80
+ setContent(content: string | null | undefined): this;
81
+ /** Serialises the component into a structured message payload. */
82
+ toJSON(): MiniTextDisplayComponent;
83
+ }
84
+ /** Builder for structured message separator components. */
85
+ export declare class SeparatorBuilder implements JSONEncodable<MiniSeparatorComponent> {
86
+ private data;
87
+ constructor(data?: SeparatorBuilderData);
88
+ /** Sets whether the separator should render a divider. */
89
+ setDivider(divider: boolean | null | undefined): this;
90
+ /** Sets the separator spacing value. */
91
+ setSpacing(spacing: SeparatorSpacingSize | null | undefined): this;
92
+ /** Serialises the separator payload. */
93
+ toJSON(): MiniSeparatorComponent;
94
+ }
95
+ /** Builder for structured message thumbnails. */
96
+ export declare class ThumbnailBuilder implements JSONEncodable<MiniThumbnailComponent> {
97
+ private data;
98
+ constructor(data?: ThumbnailBuilderData);
99
+ /** Sets the media payload for the thumbnail. */
100
+ setMedia(media: APIUnfurledMediaItem | null | undefined): this;
101
+ /** Sets the thumbnail description. */
102
+ setDescription(description: string | null | undefined): this;
103
+ /** Marks the thumbnail as a spoiler. */
104
+ setSpoiler(spoiler: boolean | null | undefined): this;
105
+ /** Serialises the thumbnail payload. */
106
+ toJSON(): MiniThumbnailComponent;
107
+ }
108
+ /** Builder for structured message gallery items. */
109
+ export declare class GalleryItemBuilder implements JSONEncodable<MiniGalleryItemComponent> {
110
+ private data;
111
+ constructor(data?: GalleryItemBuilderData);
112
+ /** Sets the media item payload. */
113
+ setMedia(media: APIUnfurledMediaItem | null | undefined): this;
114
+ /** Sets the media description. */
115
+ setDescription(description: string | null | undefined): this;
116
+ /** Marks the media item as a spoiler. */
117
+ setSpoiler(spoiler: boolean | null | undefined): this;
118
+ /** Serialises the gallery item payload. */
119
+ toJSON(): MiniGalleryItemComponent;
120
+ }
121
+ /** Builder for structured message gallery components. */
122
+ export declare class GalleryBuilder implements JSONEncodable<MiniGalleryComponent> {
123
+ private data;
124
+ constructor(data?: GalleryBuilderData);
125
+ /** Replaces the gallery items. */
126
+ setItems(items: Array<MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>>): this;
127
+ /** Adds a gallery item to the payload. */
128
+ addItem(item: MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>): this;
129
+ /** Serialises the gallery payload. */
130
+ toJSON(): MiniGalleryComponent;
131
+ }