@zoodogood/utils 4.2.1-change.3358 → 5.1.0-change.4236

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.
Files changed (110) hide show
  1. package/lib/discordjs/chain/configuration.d.ts +7 -0
  2. package/lib/discordjs/chain/configuration.d.ts.map +1 -0
  3. package/lib/discordjs/chain/get_chain_array.d.ts +7 -0
  4. package/lib/discordjs/chain/get_chain_array.d.ts.map +1 -0
  5. package/lib/discordjs/chain/get_chain_array.js +14 -0
  6. package/lib/discordjs/chain/lifecycle.d.ts +5 -0
  7. package/lib/discordjs/chain/lifecycle.d.ts.map +1 -0
  8. package/lib/discordjs/chain/lifecycle.js +25 -0
  9. package/lib/discordjs/chain/map.d.ts +8 -0
  10. package/lib/discordjs/chain/map.d.ts.map +1 -0
  11. package/lib/discordjs/chain/map.js +28 -0
  12. package/lib/discordjs/chain/move_partial_data_to_chain.d.ts +6 -0
  13. package/lib/discordjs/chain/move_partial_data_to_chain.d.ts.map +1 -0
  14. package/lib/discordjs/chain/move_partial_data_to_chain.js +176 -0
  15. package/lib/discordjs/helpers.d.ts +3 -18
  16. package/lib/discordjs/helpers.d.ts.map +1 -0
  17. package/lib/discordjs/helpers.js +2 -46
  18. package/lib/discordjs/main_embed_of.d.ts +4 -0
  19. package/lib/discordjs/main_embed_of.d.ts.map +1 -0
  20. package/lib/discordjs/main_embed_of.js +3 -0
  21. package/lib/discordjs/message_components.d.ts +37 -0
  22. package/lib/discordjs/message_components.d.ts.map +1 -0
  23. package/lib/discordjs/message_components.js +63 -0
  24. package/lib/discordjs/message_content_limits.d.ts +13 -0
  25. package/lib/discordjs/message_content_limits.d.ts.map +1 -0
  26. package/lib/discordjs/message_content_limits.js +29 -0
  27. package/lib/discordjs/message_lifecycle.d.ts +56 -0
  28. package/lib/discordjs/message_lifecycle.d.ts.map +1 -0
  29. package/lib/discordjs/message_lifecycle.js +157 -0
  30. package/lib/discordjs/mod.d.ts +11 -1
  31. package/lib/discordjs/mod.d.ts.map +1 -0
  32. package/lib/discordjs/mod.js +10 -1
  33. package/lib/discordjs/modal.d.ts +19 -0
  34. package/lib/discordjs/modal.d.ts.map +1 -0
  35. package/lib/discordjs/modal.js +42 -0
  36. package/lib/index.d.ts +1 -0
  37. package/lib/index.d.ts.map +1 -0
  38. package/lib/nodejs/getChildProcessUtils.d.ts +3 -2
  39. package/lib/nodejs/getChildProcessUtils.d.ts.map +1 -0
  40. package/lib/nodejs/getChildProcessUtils.js +2 -2
  41. package/lib/nodejs/mod.d.ts +1 -0
  42. package/lib/nodejs/mod.d.ts.map +1 -0
  43. package/lib/objectives/BusyNumeric.d.ts +1 -0
  44. package/lib/objectives/BusyNumeric.d.ts.map +1 -0
  45. package/lib/objectives/BusyNumeric.js +25 -39
  46. package/lib/objectives/CustomCollector.d.ts +1 -0
  47. package/lib/objectives/CustomCollector.d.ts.map +1 -0
  48. package/lib/objectives/CustomCollector.js +6 -18
  49. package/lib/objectives/DotNotatedInterface.d.ts +1 -0
  50. package/lib/objectives/DotNotatedInterface.d.ts.map +1 -0
  51. package/lib/objectives/DotNotatedInterface.js +1 -2
  52. package/lib/objectives/ExtendedEnum/BooleanWithMessage.d.ts +1 -0
  53. package/lib/objectives/ExtendedEnum/BooleanWithMessage.d.ts.map +1 -0
  54. package/lib/objectives/ExtendedEnum/BooleanWithMessage.js +4 -4
  55. package/lib/objectives/ExtendedEnum/Option.d.ts +1 -0
  56. package/lib/objectives/ExtendedEnum/Option.d.ts.map +1 -0
  57. package/lib/objectives/ExtendedEnum/Option.js +4 -4
  58. package/lib/objectives/ExtendedEnum/Result.d.ts +1 -0
  59. package/lib/objectives/ExtendedEnum/Result.d.ts.map +1 -0
  60. package/lib/objectives/ExtendedEnum/Result.js +9 -9
  61. package/lib/objectives/ExtendedEnum/index.d.ts +1 -0
  62. package/lib/objectives/ExtendedEnum/index.d.ts.map +1 -0
  63. package/lib/objectives/ExtendedEnum/main.d.ts +1 -0
  64. package/lib/objectives/ExtendedEnum/main.d.ts.map +1 -0
  65. package/lib/objectives/ExtendedEnum/main.js +4 -17
  66. package/lib/objectives/ExtendedEnum/mod.d.ts +1 -0
  67. package/lib/objectives/ExtendedEnum/mod.d.ts.map +1 -0
  68. package/lib/objectives/GlitchText.d.ts +1 -0
  69. package/lib/objectives/GlitchText.d.ts.map +1 -0
  70. package/lib/objectives/LazySort/LazySort.build.d.ts +1 -0
  71. package/lib/objectives/LazySort/LazySort.build.d.ts.map +1 -0
  72. package/lib/objectives/LazySort/LazySort.build.js +52 -53
  73. package/lib/objectives/equal.d.ts +1 -0
  74. package/lib/objectives/equal.d.ts.map +1 -0
  75. package/lib/objectives/getRandomElementFromArray.d.ts +1 -0
  76. package/lib/objectives/getRandomElementFromArray.d.ts.map +1 -0
  77. package/lib/objectives/getRandomElementFromArray.js +6 -6
  78. package/lib/objectives/getRandomNumberInRange.d.ts +1 -0
  79. package/lib/objectives/getRandomNumberInRange.d.ts.map +1 -0
  80. package/lib/objectives/mod.d.ts +1 -0
  81. package/lib/objectives/mod.d.ts.map +1 -0
  82. package/lib/objectives/rangeToArray.d.ts +1 -0
  83. package/lib/objectives/rangeToArray.d.ts.map +1 -0
  84. package/lib/primitives/BracketsParser.d.ts +1 -0
  85. package/lib/primitives/BracketsParser.d.ts.map +1 -0
  86. package/lib/primitives/BracketsParser.js +24 -29
  87. package/lib/primitives/CliParser.d.ts +1 -0
  88. package/lib/primitives/CliParser.d.ts.map +1 -0
  89. package/lib/primitives/CliParser.js +21 -20
  90. package/lib/primitives/TextTableBuilder.d.ts +1 -0
  91. package/lib/primitives/TextTableBuilder.d.ts.map +1 -0
  92. package/lib/primitives/TextTableBuilder.js +17 -22
  93. package/lib/primitives/binary_search.d.ts +1 -0
  94. package/lib/primitives/binary_search.d.ts.map +1 -0
  95. package/lib/primitives/createDefaultPreventable.d.ts +1 -0
  96. package/lib/primitives/createDefaultPreventable.d.ts.map +1 -0
  97. package/lib/primitives/mod.d.ts +8 -2
  98. package/lib/primitives/mod.d.ts.map +1 -0
  99. package/lib/primitives/mod.js +23 -5
  100. package/lib/primitives/normalize.d.ts +1 -0
  101. package/lib/primitives/normalize.d.ts.map +1 -0
  102. package/lib/primitives/symbols.d.ts +2 -0
  103. package/lib/primitives/symbols.d.ts.map +1 -0
  104. package/lib/primitives/symbols.js +1 -0
  105. package/package.json +9 -15
  106. package/lib/discordjs/simplify.d.ts +0 -54
  107. package/lib/discordjs/simplify.js +0 -116
  108. package/lib/objectives/getRandomValue.d.ts +0 -7
  109. package/lib/objectives/getRandomValue.js +0 -8
  110. /package/lib/{objectives/LazySort/LazySort.test.d.ts → discordjs/chain/configuration.js} +0 -0
@@ -0,0 +1,7 @@
1
+ import type { DiscordContentLimites } from "../message_content_limits.js";
2
+ export interface MaySplitConfiguration {
3
+ fields?: (keyof typeof DiscordContentLimites)[];
4
+ separateBy?: string;
5
+ splay: "balanced" | "rest";
6
+ }
7
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/discordjs/chain/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,MAAM,WAAW,qBAAqB;IACrC,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,qBAAqB,CAAC,EAAE,CAAC;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,7 @@
1
+ import type { Client, Message } from "discord.js";
2
+ export declare const _chain_parent: unique symbol;
3
+ export declare const _chain_child: unique symbol;
4
+ export declare function get_chain_array(partId: string, client: Client): Promise<Array<Message | {
5
+ id: string;
6
+ }>>;
7
+ //# sourceMappingURL=get_chain_array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_chain_array.d.ts","sourceRoot":"","sources":["../../../src/discordjs/chain/get_chain_array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;AAGpE,eAAO,MAAM,aAAa,eAAmB,CAAC;AAC9C,eAAO,MAAM,YAAY,eAAkB,CAAC;AAE5C,wBAAsB,eAAe,CACpC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAe1C"}
@@ -0,0 +1,14 @@
1
+ import { chain_map } from "./map.js";
2
+ export const _chain_parent = Symbol("parent");
3
+ export const _chain_child = Symbol("child");
4
+ export async function get_chain_array(partId, client) {
5
+ // В порядке от потомка к родителю
6
+ const [channelId, ...parts] = chain_map.get(partId);
7
+ const channel = client.channels.cache.get(channelId);
8
+ return await Promise.all(parts.map((id) => channel.messages.fetch(id).catch((error) => {
9
+ if (error.message !== "Unknown Message") {
10
+ throw error;
11
+ }
12
+ return { id };
13
+ })));
14
+ }
@@ -0,0 +1,5 @@
1
+ import { Message } from "discord.js";
2
+ export declare const propogate: any;
3
+ export declare function onMessageDelete(message: Message): Promise<void>;
4
+ export declare function onPropogableEvent(eventType: string, direct_target: Message, rest: unknown): Promise<void>;
5
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../src/discordjs/chain/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAKrC,eAAO,MAAM,SAAS,KAAqB,CAAC;AAC5C,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,iBAerD;AAED,wBAAsB,iBAAiB,CACtC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,OAAO,EACtB,IAAI,EAAE,OAAO,iBASb"}
@@ -0,0 +1,25 @@
1
+ import { Message } from "discord.js";
2
+ import { EventEmitter } from "node:events";
3
+ import { get_chain_array } from "./get_chain_array.js";
4
+ import { chain_map } from "./map.js";
5
+ export const propogate = new EventEmitter();
6
+ export async function onMessageDelete(message) {
7
+ const messages = chain_map.has(message.id) &&
8
+ (await get_chain_array(message.id, message.client));
9
+ if (!chain_map.has(message.id)) {
10
+ return;
11
+ }
12
+ for (const message of messages) {
13
+ chain_map.delete(message.id);
14
+ message instanceof Message && message.delete();
15
+ }
16
+ }
17
+ export async function onPropogableEvent(eventType, direct_target, rest) {
18
+ const chain = chain_map.has(direct_target.id) &&
19
+ (await get_chain_array(direct_target.id, direct_target.client));
20
+ if (!chain)
21
+ return;
22
+ for (const message of chain) {
23
+ propogate.emit(eventType, message, rest, direct_target, chain);
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ import type { Message } from "discord.js";
2
+ declare class Cache extends Map<string, string[]> {
3
+ constructor();
4
+ update(parent: Message, child: Message, channelId: string): string[] | undefined;
5
+ }
6
+ export declare const chain_map: Cache;
7
+ export {};
8
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/discordjs/chain/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,cAAM,KAAM,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;;IAqBxC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM;CAYzD;AAED,eAAO,MAAM,SAAS,OAAc,CAAC"}
@@ -0,0 +1,28 @@
1
+ class Cache extends Map {
2
+ constructor() {
3
+ super();
4
+ setInterval(() => {
5
+ const { size } = this;
6
+ if (size < /* threshold */ 100) {
7
+ return;
8
+ }
9
+ const keys = this.keys();
10
+ for (let index = 0; index < Math.floor(size * /* strong */ 0.5); index++) {
11
+ this.delete(keys.next().value);
12
+ }
13
+ }, 60 * 1000 * 30);
14
+ }
15
+ update(parent, child, channelId) {
16
+ if (this.has(parent.id)) {
17
+ return;
18
+ }
19
+ if (!this.has(child.id)) {
20
+ this.set(child.id, [channelId, child.id]);
21
+ }
22
+ const cell = this.get(child.id);
23
+ cell.indexOf(parent.id) === -1 && cell.push(parent.id);
24
+ this.set(parent.id, cell);
25
+ return cell;
26
+ }
27
+ }
28
+ export const chain_map = new Cache();
@@ -0,0 +1,6 @@
1
+ import { type diagnosticLimits } from "../message_content_limits.js";
2
+ import { type AdvancedPayload, type createMessage } from "../message_lifecycle.js";
3
+ import type { MaySplitConfiguration } from "./configuration.js";
4
+ export declare function move_partial_data_to_chain(mut_original: AdvancedPayload, splitConfigutation: MaySplitConfiguration, limitsDiagnostic: ReturnType<typeof diagnosticLimits>): undefined;
5
+ export declare function _rob_already_prepared(mut_message_data: ReturnType<typeof createMessage>, mut_payload: AdvancedPayload): void;
6
+ //# sourceMappingURL=move_partial_data_to_chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move_partial_data_to_chain.d.ts","sourceRoot":"","sources":["../../../src/discordjs/chain/move_partial_data_to_chain.ts"],"names":[],"mappings":"AAKA,OAAO,EAEN,KAAK,gBAAgB,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAgBhE,wBAAgB,0BAA0B,CACzC,YAAY,EAAE,eAAe,EAC7B,kBAAkB,EAAE,qBAAqB,EACzC,gBAAgB,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,aA6LrD;AAID,wBAAgB,qBAAqB,CACpC,gBAAgB,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,EAClD,WAAW,EAAE,eAAe,QAY5B"}
@@ -0,0 +1,176 @@
1
+ // declare state in file://./readme.md
2
+ import { DEFAULT } from "../../primitives/symbols.js";
3
+ import { main_embed_of } from "../main_embed_of.js";
4
+ import { DiscordContentLimites, } from "../message_content_limits.js";
5
+ import { isEmptyEmbed, } from "../message_lifecycle.js";
6
+ function tryMultipleMap(callback, limit = 10) {
7
+ let iteration = 0;
8
+ while (true) {
9
+ try {
10
+ return callback(iteration++);
11
+ }
12
+ catch (error) {
13
+ if (iteration >= limit) {
14
+ throw error;
15
+ }
16
+ /* continue*/
17
+ }
18
+ }
19
+ }
20
+ export function move_partial_data_to_chain(mut_original, splitConfigutation, limitsDiagnostic) {
21
+ const chain_child = {};
22
+ mut_original._chain_child = chain_child;
23
+ move_static_down(mut_original, chain_child);
24
+ if (!limitsDiagnostic.isExceeding) {
25
+ // Вернуть визуально пустые значения для рассматриваемых полей
26
+ return void 0;
27
+ }
28
+ const exceeding = Object.entries(limitsDiagnostic.exceeding).filter(([_key, value]) => value > 0);
29
+ const { separateBy = "\n" } = splitConfigutation;
30
+ const prepared = exceeding.map(([key]) => {
31
+ switch (key) {
32
+ case "content":
33
+ case "description":
34
+ return (() => {
35
+ const chunks = mut_original[key]
36
+ .split(separateBy)
37
+ .map((chunk) => ({
38
+ chunk,
39
+ codeblock_lang: (() => {
40
+ const markers = Array.from(chunk.matchAll(/```(?<lang>\S+)?/g));
41
+ if (markers.length % 2 === 0) {
42
+ return;
43
+ }
44
+ return markers.at(-1).groups.lang || DEFAULT;
45
+ })(),
46
+ }));
47
+ chunks.forEach(($) => {
48
+ if ($.chunk.length > DiscordContentLimites[key]) {
49
+ throw new Error("As a result of splitting large text, spliceBy did not find any potential separation points (https://github.com/zoodogood/1119/issues/8)");
50
+ }
51
+ });
52
+ return [key, chunks];
53
+ })();
54
+ case "fields_count":
55
+ return ["fields", mut_original.fields];
56
+ default:
57
+ return [key, mut_original[key]];
58
+ }
59
+ });
60
+ const predicated_chain_length = Math.max(...exceeding.map(([key, value]) => value /
61
+ DiscordContentLimites[key])) + 1;
62
+ const [for_original, for_child] = tryMultipleMap((iteration) => {
63
+ return resolve(predicated_chain_length + iteration);
64
+ });
65
+ Object.assign(chain_child, for_child);
66
+ Object.assign(mut_original, for_original, {
67
+ _chain_child: chain_child,
68
+ });
69
+ return void 0;
70
+ function resolve(predicated_chain_length) {
71
+ return prepared
72
+ .map(([key, value]) => {
73
+ switch (key) {
74
+ case "content":
75
+ case "description":
76
+ return [
77
+ key,
78
+ (() => {
79
+ const average = mut_original[key].length /
80
+ Math.ceil(predicated_chain_length);
81
+ const chunks_to_keep = [];
82
+ let remain_symbols_count = 0;
83
+ let opened_codeblock = null;
84
+ const pull = value;
85
+ const CLOSE_CODEBLOCK = "\n```";
86
+ const close_codeblock_length = CLOSE_CODEBLOCK.length;
87
+ while (pull.length) {
88
+ const { chunk, codeblock_lang } = pull[0];
89
+ if (codeblock_lang) {
90
+ opened_codeblock = opened_codeblock
91
+ ? null
92
+ : codeblock_lang;
93
+ }
94
+ if (remain_symbols_count +
95
+ chunk.length +
96
+ (opened_codeblock ? close_codeblock_length : 0) >
97
+ DiscordContentLimites[key] ||
98
+ remain_symbols_count > average) {
99
+ opened_codeblock && chunks_to_keep.push(CLOSE_CODEBLOCK);
100
+ break;
101
+ }
102
+ pull.shift();
103
+ chunks_to_keep.push(chunk);
104
+ remain_symbols_count += chunk.length;
105
+ }
106
+ const chunks_to_shift = pull.map(({ chunk }) => chunk);
107
+ opened_codeblock &&
108
+ chunks_to_shift.unshift(
109
+ // @ts-expect-error
110
+ `\`\`\`${opened_codeblock === DEFAULT ? "" : opened_codeblock}\n`);
111
+ return [
112
+ chunks_to_keep.join(separateBy),
113
+ chunks_to_shift.join(separateBy),
114
+ ];
115
+ })(),
116
+ ];
117
+ case "fields":
118
+ return [
119
+ key,
120
+ Object.values(Object.groupBy(value, (_value, index) => String(index <
121
+ value.length /
122
+ Math.ceil(predicated_chain_length)))),
123
+ ];
124
+ default:
125
+ throw new Error(`Unknown key: ${key}`);
126
+ }
127
+ })
128
+ .reduce((acc, item) => {
129
+ const [key, [keep, move]] = item;
130
+ // @ts-expect-error
131
+ acc[0][key] = keep;
132
+ // @ts-expect-error
133
+ acc[1][key] = move;
134
+ return acc;
135
+ }, [{}, {}]);
136
+ }
137
+ function move_static_down(from, to) {
138
+ // components, footer, reactions, files: окажутся в последнем сообщении
139
+ // color: скопируется
140
+ // если в оригинальном сообщении есть description или content — во втором сообщении им на смену прийдут визуально пустые значения
141
+ const is_started_as_empty = isEmptyEmbed(from);
142
+ to.color = from.color;
143
+ to.maySplitMessage = from.maySplitMessage;
144
+ to.image = from.image;
145
+ from.image = undefined;
146
+ to.timestamp = from.timestamp;
147
+ from.timestamp = undefined;
148
+ to.components = from.components;
149
+ from.components = undefined;
150
+ to.footer = from.footer;
151
+ from.footer = undefined;
152
+ to.reactions = from.reactions;
153
+ from.reactions = undefined;
154
+ to.files = from.files;
155
+ from.files = undefined;
156
+ from.description && (to.description = "-# (пусто)");
157
+ from.content && (to.content = "-# (пусто)");
158
+ !is_started_as_empty &&
159
+ isEmptyEmbed(from) &&
160
+ (from.description = "-# (пусто)");
161
+ }
162
+ }
163
+ // Решает прецендент когда целью становится сообщение в цепочке у которого есть потомки, и это выясняется только в момент отправки
164
+ // Хотя по хорошему данные сообщения должны быть собраны до отправки, этого невозможно сделать не целевого айди, а оно при редактировании не подразумевается
165
+ export function _rob_already_prepared(mut_message_data, mut_payload) {
166
+ const embed = main_embed_of(mut_message_data);
167
+ if (embed) {
168
+ embed.footer = undefined;
169
+ embed.image = undefined;
170
+ embed.timestamp = undefined;
171
+ embed.video = undefined;
172
+ }
173
+ mut_message_data.files = undefined;
174
+ mut_message_data.components = undefined;
175
+ mut_payload.reactions = undefined;
176
+ }
@@ -1,18 +1,3 @@
1
- export type APIBaseButton = import("discord-api-types/v10").APIButtonComponentBase<any>;
2
- /**
3
- * @typedef {import("discord-api-types/v10").APIButtonComponentBase} APIBaseButton
4
- */
5
- /**
6
- *
7
- * @param {Partial<APIBaseButton>[]} resolable
8
- */
9
- export function justButtonComponents(...resolable: Partial<APIBaseButton>[]): {
10
- label?: string | undefined;
11
- style: any;
12
- emoji?: import("discord-api-types/v10").APIMessageComponentEmoji | undefined;
13
- disabled?: boolean | undefined;
14
- type: import("discord-api-types/v10").ComponentType.Button | ComponentType;
15
- customId: string;
16
- }[];
17
- export function justSendMessage(target: any, options: any): Promise<any>;
18
- import { ComponentType } from "discord.js";
1
+ import type { Emoji } from "discord.js";
2
+ export declare function codeOfEmoji(emoji: Emoji): any;
3
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/discordjs/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,OAEvC"}
@@ -1,47 +1,3 @@
1
- import { BaseInteraction, ButtonStyle, ComponentType } from "discord.js";
2
- import { CreateMessage } from "./simplify.js";
3
- const DEFAULTS_FOR_BUTTON = {
4
- type: ComponentType.Button,
5
- style: ButtonStyle.Secondary,
6
- };
7
- /**
8
- * @typedef {import("discord-api-types/v10").APIButtonComponentBase} APIBaseButton
9
- */
10
- /**
11
- *
12
- * @param {Partial<APIBaseButton>[]} resolable
13
- */
14
- function justButtonComponents(...resolable) {
15
- const buttons = resolable.map((data, i) => ({
16
- ...DEFAULTS_FOR_BUTTON,
17
- customId: `button.${i + 1}`,
18
- ...data,
19
- }));
20
- return buttons;
1
+ export function codeOfEmoji(emoji) {
2
+ return emoji.id || emoji.name;
21
3
  }
22
- async function justSendMessage(target, options) {
23
- const messagePayload = CreateMessage(options);
24
- const message = target instanceof BaseInteraction
25
- ? await (options.edit
26
- ? target.replied
27
- ? target.editReply(messagePayload)
28
- : target.update(messagePayload)
29
- : target.reply(messagePayload))
30
- : await (options.edit
31
- ? target.edit(messagePayload)
32
- : target.send(messagePayload));
33
- if (options.delete) {
34
- setTimeout(() => message.delete(), options.delete);
35
- }
36
- if (options.reactions) {
37
- options.reactions
38
- .filter(Boolean)
39
- .filter((react) => {
40
- var _a;
41
- return !((_a = message.reactions) === null || _a === void 0 ? void 0 : _a.cache.some((compared) => compared.emoji.code === react));
42
- })
43
- .forEach((react) => message.react(react));
44
- }
45
- return message;
46
- }
47
- export { justButtonComponents, justSendMessage };
@@ -0,0 +1,4 @@
1
+ import type { APIEmbed } from "discord-api-types/v10";
2
+ import type { Embed, Message, MessageCreateOptions } from "discord.js";
3
+ export declare function main_embed_of(message: Message | MessageCreateOptions): Embed | APIEmbed | undefined;
4
+ //# sourceMappingURL=main_embed_of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main_embed_of.d.ts","sourceRoot":"","sources":["../../src/discordjs/main_embed_of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EACX,KAAK,EAEL,OAAO,EACP,oBAAoB,EACpB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,aAAa,CAC5B,OAAO,EAAE,OAAO,GAAG,oBAAoB,GACrC,KAAK,GAAG,QAAQ,GAAG,SAAS,CAK9B"}
@@ -0,0 +1,3 @@
1
+ export function main_embed_of(message) {
2
+ return message.embeds?.[0];
3
+ }
@@ -0,0 +1,37 @@
1
+ import { type ActionRow, type BaseSelectMenuComponentData, ButtonStyle, ComponentType } from "discord.js";
2
+ interface ButtonConfiguration {
3
+ customId?: string;
4
+ label?: string;
5
+ emoji?: string;
6
+ disabled?: boolean;
7
+ url?: string;
8
+ style?: ButtonStyle;
9
+ type?: ComponentType.Button;
10
+ }
11
+ export declare function justButtonComponents(...resolable: ButtonConfiguration[]): {
12
+ customId: string;
13
+ label?: string;
14
+ emoji?: string;
15
+ disabled?: boolean;
16
+ url?: string;
17
+ style: ButtonStyle;
18
+ type: ComponentType.Button;
19
+ }[];
20
+ export declare function justSelectMenuComponent({ placeholder, labels, addable, }: {
21
+ placeholder?: string;
22
+ labels: string[];
23
+ addable?: Partial<BaseSelectMenuComponentData>;
24
+ }): any;
25
+ type ItemOfActionRow<T> = {
26
+ type: ComponentType;
27
+ } & {
28
+ [key: string]: any;
29
+ };
30
+ type ActionRowSource<T> = ItemOfActionRow<T> | ItemOfActionRow<T>[] | ItemOfActionRow<T>[][] | ActionRow<any> | ActionRow<any>[];
31
+ type SimpleActionRow<T> = {
32
+ type: ComponentType.ActionRow;
33
+ components: ItemOfActionRow<T>[];
34
+ }[];
35
+ export declare function justComponents<T>(state: ActionRowSource<T>): SimpleActionRow<T>;
36
+ export {};
37
+ //# sourceMappingURL=message_components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message_components.d.ts","sourceRoot":"","sources":["../../src/discordjs/message_components.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EACd,KAAK,2BAA2B,EAChC,WAAW,EACX,aAAa,EACb,MAAM,YAAY,CAAC;AAOpB,UAAU,mBAAmB;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC;CAC5B;AAED,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,EAAE,mBAAmB,EAAE;cAT5D,MAAM;YACT,MAAM;YACN,MAAM;eACH,OAAO;UACZ,MAAM;WACJ,WAAW;UACZ,aAAa,CAAC,MAAM;IAW3B;AAED,wBAAgB,uBAAuB,CAAC,EACvC,WAAW,EACX,MAAM,EACN,OAAY,GACZ,EAAE;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC/C,OAOA;AAED,KAAK,eAAe,CAAC,CAAC,IAAI;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAC3E,KAAK,eAAe,CAAC,CAAC,IACnB,eAAe,CAAC,CAAC,CAAC,GAClB,eAAe,CAAC,CAAC,CAAC,EAAE,GACpB,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,GACtB,SAAS,CAAC,GAAG,CAAC,GACd,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;AAEpB,KAAK,eAAe,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC;IAC9B,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;CACjC,EAAE,CAAC;AAGJ,wBAAgB,cAAc,CAAC,CAAC,EAC/B,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,eAAe,CAAC,CAAC,CAAC,CA0CpB"}
@@ -0,0 +1,63 @@
1
+ import { ButtonStyle, ComponentType, } from "discord.js";
2
+ const DEFAULTS_FOR_BUTTON = {
3
+ type: ComponentType.Button,
4
+ style: ButtonStyle.Secondary,
5
+ };
6
+ export function justButtonComponents(...resolable) {
7
+ const buttons = resolable.map((data, i) => ({
8
+ ...DEFAULTS_FOR_BUTTON,
9
+ customId: `button.${i + 1}`,
10
+ ...data,
11
+ }));
12
+ return buttons;
13
+ }
14
+ export function justSelectMenuComponent({ placeholder, labels, addable = {}, }) {
15
+ return {
16
+ type: ComponentType.StringSelect,
17
+ placeholder,
18
+ options: labels.map((label, index) => ({ label, value: String(index) })),
19
+ ...addable,
20
+ };
21
+ }
22
+ // MARK: Components
23
+ export function justComponents(state) {
24
+ switch (true) {
25
+ // isEmptyArray ↴ ➞ return []
26
+ case Array.isArray(state) && state.length === 0:
27
+ return [];
28
+ // isSingleActionRow ↴ ➞ ActionRowArray ➞ return SimpleActionRow
29
+ case isSingleActionRow(state):
30
+ state = [state];
31
+ // fallthrough ¯\_(ツ)_/¯
32
+ // isActionRowArray ↴ ➞ return SimpleActionRow
33
+ case Array.isArray(state) && isSingleActionRow(state[0]):
34
+ return state;
35
+ // isSingleComponent ↴ ➞ ComponentsFlat ➞ ComponentsMatrix ➞ return ActionRowArray
36
+ case isSingleComponent(state):
37
+ state = [state];
38
+ // fallthrough ¯\_(ツ)_/¯
39
+ // isComponentsFlat ↴
40
+ case isComponentsFlat(state):
41
+ state = [state];
42
+ // fallthrough ¯\_(ツ)_/¯
43
+ // isComponentsMatrix ↴
44
+ case Array.isArray(state) && isComponentsFlat(state[0]):
45
+ return state.map((row) => ({
46
+ type: ComponentType.ActionRow,
47
+ components: row,
48
+ }));
49
+ default:
50
+ throw new TypeError("Unknown case");
51
+ }
52
+ function isSingleActionRow(component) {
53
+ // @ts-expect-error
54
+ return component.type === ComponentType.ActionRow;
55
+ }
56
+ function isSingleComponent(component) {
57
+ // @ts-expect-error
58
+ return "type" in component;
59
+ }
60
+ function isComponentsFlat(component) {
61
+ return Array.isArray(component) && isSingleComponent(component[0]);
62
+ }
63
+ }
@@ -0,0 +1,13 @@
1
+ import type { AdvancedPayload } from "./mod.js";
2
+ export declare const DiscordContentLimites: {
3
+ content: number;
4
+ description: number;
5
+ field_count: number;
6
+ };
7
+ export declare function diagnosticLimits(payload: AdvancedPayload, watchOnly?: string[]): {
8
+ isExceeding: boolean;
9
+ exceeding: {
10
+ [key in keyof typeof DiscordContentLimites]?: number;
11
+ };
12
+ };
13
+ //# sourceMappingURL=message_content_limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message_content_limits.d.ts","sourceRoot":"","sources":["../../src/discordjs/message_content_limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,eAAO,MAAM,qBAAqB;;;;CAIjC,CAAC;AAEF,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,eAAe,EACxB,SAAS,WAA4C,GACnD;IACF,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE;SAAG,GAAG,IAAI,MAAM,OAAO,qBAAqB,CAAC,CAAC,EAAE,MAAM;KAAE,CAAC;CACpE,CAwBA"}
@@ -0,0 +1,29 @@
1
+ export const DiscordContentLimites = {
2
+ content: 2048,
3
+ description: 4096,
4
+ field_count: 20,
5
+ };
6
+ export function diagnosticLimits(payload, watchOnly = ["content", "description", "field_count"]) {
7
+ let watchOnlyLocal = watchOnly;
8
+ !Array.isArray(watchOnlyLocal) && (watchOnlyLocal = [watchOnlyLocal]);
9
+ const diagnostic = watchOnlyLocal.map((field) => [
10
+ field,
11
+ exceeding_field(field),
12
+ ]);
13
+ return {
14
+ exceeding: Object.fromEntries(diagnostic),
15
+ isExceeding: diagnostic
16
+ .map(($) => $[1])
17
+ .some((exceeding) => exceeding > 0),
18
+ };
19
+ function exceeding_field(field) {
20
+ switch (field) {
21
+ case "content":
22
+ return (payload.content?.length ?? 0) - DiscordContentLimites.content;
23
+ case "description":
24
+ return (payload[field]?.length ?? 0) - DiscordContentLimites[field];
25
+ case "field_count":
26
+ return (payload.fields?.length ?? 0) - DiscordContentLimites[field];
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,56 @@
1
+ import { type AttachmentBuilder, type ColorResolvable, EmbedBuilder, Message, type MessageCreateOptions, type SendableChannels, User } from "discord.js";
2
+ import { justComponents } from "./message_components.js";
3
+ import { type MaySplitConfiguration } from "./mod.js";
4
+ declare function sendableOf<T extends User | SendableChannels | Message | ({} & {
5
+ channel: SendableChannels;
6
+ }) | ({} & {
7
+ send: (payload: MessageCreateOptions) => Promise<Message>;
8
+ })>(target: T): {
9
+ send: (payload: MessageCreateOptions) => Promise<Message>;
10
+ };
11
+ export interface AdvancedPayload {
12
+ content?: string;
13
+ reference?: string;
14
+ ephemeral?: boolean;
15
+ fetchReply?: boolean;
16
+ title?: string;
17
+ url?: string;
18
+ edit?: boolean;
19
+ author?: {
20
+ name: string;
21
+ iconURL?: string;
22
+ };
23
+ thumbnail?: string;
24
+ color?: ColorResolvable;
25
+ description?: string;
26
+ fields?: {
27
+ name: string;
28
+ value: string;
29
+ inline?: boolean;
30
+ }[];
31
+ image?: string;
32
+ video?: string;
33
+ footer?: {
34
+ text: string;
35
+ iconURL?: string;
36
+ };
37
+ timestamp?: string;
38
+ delete?: number;
39
+ reactions?: string[];
40
+ maySplitMessage?: MaySplitConfiguration;
41
+ _chain_child?: AdvancedPayload;
42
+ components?: ReturnType<typeof justComponents>;
43
+ files?: AttachmentBuilder[];
44
+ }
45
+ export declare function isEmptyEmbed(embed: {
46
+ [key in keyof EmbedBuilder["data"]]: unknown;
47
+ }): boolean;
48
+ export declare function createMessage(mut_payload: AdvancedPayload): MessageCreateOptions;
49
+ /**
50
+ *
51
+ * @param {Partial<APIBaseButton>[]} resolable
52
+ */
53
+ export declare function justSendMessage<InGuild extends boolean>(target: Parameters<typeof sendableOf>[0], payload: AdvancedPayload): Promise<Message<InGuild_1>>;
54
+ export declare function sendMessage<InGuild extends boolean>(target: Parameters<typeof sendableOf>[0], message_data: ReturnType<typeof createMessage>, mut_payload: AdvancedPayload): Promise<Message<InGuild>>;
55
+ export {};
56
+ //# sourceMappingURL=message_lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message_lifecycle.d.ts","sourceRoot":"","sources":["../../src/discordjs/message_lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACpB,YAAY,EACZ,OAAO,EACP,KAAK,oBAAoB,EAEzB,KAAK,gBAAgB,EACrB,IAAI,EAEJ,MAAM,YAAY,CAAC;AASpB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAEN,KAAK,qBAAqB,EAG1B,MAAM,UAAU,CAAC;AAElB,iBAAS,UAAU,CAClB,CAAC,SACE,IAAI,GACJ,gBAAgB,GAChB,OAAO,GACP,CAAC,EAAE,GAAG;IAAE,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC,GACpC,CAAC,EAAE,GAAG;IAAE,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,EAEvE,MAAM,EAAE,CAAC,GACP;IACF,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1D,CAWA;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAC/C,KAAK,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AAED,wBAAgB,YAAY,CAC3B,KAAK,EAAE;KAAG,GAAG,IAAI,MAAM,YAAY,CAAC,MAAM,CAAC,GAAG,OAAO;CAAE,WAmBvD;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,eAAe,wBA2DzD;AAED;;;GAGG;AAEH,wBAAsB,eAAe,CAAC,OAAO,SAAS,OAAO,EAC5D,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,EACxC,OAAO,EAAE,eAAe,+BAIxB;AAED,wBAAsB,WAAW,CAAC,OAAO,SAAS,OAAO,EACxD,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,EACxC,YAAY,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,EAC9C,WAAW,EAAE,eAAe,GAC1B,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAsG3B"}