@magicyan/discord 1.0.19 → 1.0.21

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.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const core = require('@magicyan/core');
4
3
  const discord_js = require('discord.js');
5
4
  const chars = require('../constants/chars.cjs');
5
+ const core = require('@magicyan/core');
6
6
 
7
7
  function createEmbedAuthor(options) {
8
8
  const {
@@ -35,7 +35,7 @@ function createEmbedAsset(source, options) {
35
35
  }
36
36
  class EmbedBuilderPlus extends discord_js.EmbedBuilder {
37
37
  constructor(data) {
38
- const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? []).map(({ name = chars.chars.invisible, value = chars.chars.invisible, inline }) => ({
38
+ const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? data.extend?.fields ?? []).map(({ name = chars.chars.invisible, value = chars.chars.invisible, inline }) => ({
39
39
  name,
40
40
  value,
41
41
  inline
@@ -64,7 +64,7 @@ class EmbedBuilderPlus extends discord_js.EmbedBuilder {
64
64
  super(embed.data);
65
65
  }
66
66
  has(property) {
67
- return Object.hasOwn(this, property);
67
+ return Boolean(this.data[property]);
68
68
  }
69
69
  toArray() {
70
70
  return [this];
@@ -1,6 +1,6 @@
1
- import { notFound } from '@magicyan/core';
2
1
  import { Attachment, AttachmentBuilder, EmbedBuilder, Embed } from 'discord.js';
3
2
  import { chars } from '../constants/chars.mjs';
3
+ import { notFound } from '@magicyan/core';
4
4
 
5
5
  function createEmbedAuthor(options) {
6
6
  const {
@@ -33,7 +33,7 @@ function createEmbedAsset(source, options) {
33
33
  }
34
34
  class EmbedBuilderPlus extends EmbedBuilder {
35
35
  constructor(data) {
36
- const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? []).map(({ name = chars.invisible, value = chars.invisible, inline }) => ({
36
+ const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? data.extend?.fields ?? []).map(({ name = chars.invisible, value = chars.invisible, inline }) => ({
37
37
  name,
38
38
  value,
39
39
  inline
@@ -62,7 +62,7 @@ class EmbedBuilderPlus extends EmbedBuilder {
62
62
  super(embed.data);
63
63
  }
64
64
  has(property) {
65
- return Object.hasOwn(this, property);
65
+ return Boolean(this.data[property]);
66
66
  }
67
67
  toArray() {
68
68
  return [this];
@@ -5,6 +5,23 @@ const core = require('@magicyan/core');
5
5
  function findMessage(channel) {
6
6
  const messages = channel.messages.cache;
7
7
  return {
8
+ async all(limit = Infinity) {
9
+ const messages2 = [];
10
+ let lastMessageId;
11
+ while (true) {
12
+ const fetched = await channel.messages.fetch({ limit: 100, before: lastMessageId });
13
+ messages2.push(...fetched.values());
14
+ lastMessageId = fetched.lastKey();
15
+ if (fetched.size < 100 || messages2.length >= limit)
16
+ break;
17
+ }
18
+ if (limit < messages2.length) {
19
+ const sliced = messages2.slice(0, limit);
20
+ messages2.length = 0;
21
+ messages2.push(...sliced);
22
+ }
23
+ return messages2;
24
+ },
8
25
  byId(id) {
9
26
  return messages.get(id);
10
27
  },
@@ -3,6 +3,23 @@ import { equalsIgnoreCase, includesIgnoreCase } from '@magicyan/core';
3
3
  function findMessage(channel) {
4
4
  const messages = channel.messages.cache;
5
5
  return {
6
+ async all(limit = Infinity) {
7
+ const messages2 = [];
8
+ let lastMessageId;
9
+ while (true) {
10
+ const fetched = await channel.messages.fetch({ limit: 100, before: lastMessageId });
11
+ messages2.push(...fetched.values());
12
+ lastMessageId = fetched.lastKey();
13
+ if (fetched.size < 100 || messages2.length >= limit)
14
+ break;
15
+ }
16
+ if (limit < messages2.length) {
17
+ const sliced = messages2.slice(0, limit);
18
+ messages2.length = 0;
19
+ messages2.push(...sliced);
20
+ }
21
+ return messages2;
22
+ },
6
23
  byId(id) {
7
24
  return messages.get(id);
8
25
  },
package/dist/index.d.cts CHANGED
@@ -167,6 +167,7 @@ declare function findMember(guild: Guild): {
167
167
 
168
168
  type FindMessageFilter = (role: Message<true>) => boolean;
169
169
  declare function findMessage(channel: GuildTextBasedChannel): {
170
+ all(limit?: number): Promise<Message<boolean>[]>;
170
171
  byId(id: string): Message<true> | undefined;
171
172
  byContent(): {
172
173
  equals(content: string, ignoreCase?: boolean): Message<true> | undefined;
package/dist/index.d.mts CHANGED
@@ -167,6 +167,7 @@ declare function findMember(guild: Guild): {
167
167
 
168
168
  type FindMessageFilter = (role: Message<true>) => boolean;
169
169
  declare function findMessage(channel: GuildTextBasedChannel): {
170
+ all(limit?: number): Promise<Message<boolean>[]>;
170
171
  byId(id: string): Message<true> | undefined;
171
172
  byContent(): {
172
173
  equals(content: string, ignoreCase?: boolean): Message<true> | undefined;
package/dist/index.d.ts CHANGED
@@ -167,6 +167,7 @@ declare function findMember(guild: Guild): {
167
167
 
168
168
  type FindMessageFilter = (role: Message<true>) => boolean;
169
169
  declare function findMessage(channel: GuildTextBasedChannel): {
170
+ all(limit?: number): Promise<Message<boolean>[]>;
170
171
  byId(id: string): Message<true> | undefined;
171
172
  byContent(): {
172
173
  equals(content: string, ignoreCase?: boolean): Message<true> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicyan/discord",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Simple functions to facilitate discord bot development",
5
5
  "license": "MIT",
6
6
  "type": "module",