seyfert 2.1.1-dev-11768778519.0 → 2.1.1-dev-11842640994.0

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.
@@ -34,7 +34,6 @@ export type DisabledCache = {
34
34
  export declare class Cache {
35
35
  intents: number;
36
36
  adapter: Adapter;
37
- readonly disabledCache: DisabledCache;
38
37
  users?: Users;
39
38
  guilds?: Guilds;
40
39
  members?: Members;
@@ -49,7 +48,8 @@ export declare class Cache {
49
48
  messages?: Messages;
50
49
  bans?: Bans;
51
50
  __logger__?: Logger;
52
- constructor(intents: number, adapter: Adapter, disabledCache?: DisabledCache, client?: UsingClient);
51
+ constructor(intents: number, adapter: Adapter, disabledCache: DisabledCache, client: UsingClient);
52
+ buildCache(disabledCache: DisabledCache, client: UsingClient): void;
53
53
  flush(): ReturnCache<void>;
54
54
  hasIntent(intent: keyof typeof GatewayIntentBits): boolean;
55
55
  get hasGuildsIntent(): boolean;
@@ -76,7 +76,6 @@ export declare class Cache {
76
76
  members: import("..").GuildMember[];
77
77
  users: import("..").User[];
78
78
  channels: NonNullable<ReturnCache<import("..").AllChannels | undefined>>[];
79
- messages: import("..").Message[];
80
79
  voiceStates: import("..").VoiceState[];
81
80
  presences: (Omit<import("../types").GatewayPresenceUpdate, "user"> & {
82
81
  id: string;
@@ -94,6 +93,7 @@ export declare class Cache {
94
93
  allow: import("../structures/extra/Permissions").PermissionsBitField;
95
94
  guildId: string;
96
95
  }[][];
96
+ messages: import("..").Message[];
97
97
  bans: import("../structures/GuildBan").GuildBan[];
98
98
  }>>;
99
99
  bulkPatch(keys: (readonly [
@@ -117,6 +117,7 @@ export declare class Cache {
117
117
  string
118
118
  ])[]): Promise<void>;
119
119
  onPacket(event: GatewayDispatchPayload): Promise<void>;
120
+ protected onPacketDefault(event: GatewayDispatchPayload): Promise<void>;
120
121
  testAdapter(): Promise<void>;
121
122
  private testUsersAndMembers;
122
123
  private testChannelsAndOverwrites;
@@ -40,7 +40,6 @@ __exportStar(require("./adapters/index"), exports);
40
40
  class Cache {
41
41
  intents;
42
42
  adapter;
43
- disabledCache;
44
43
  // non-guild based
45
44
  users;
46
45
  guilds;
@@ -58,74 +57,33 @@ class Cache {
58
57
  messages;
59
58
  bans;
60
59
  __logger__;
61
- constructor(intents, adapter, disabledCache = {}, client) {
60
+ constructor(intents, adapter, disabledCache, client) {
62
61
  this.intents = intents;
63
62
  this.adapter = adapter;
64
- this.disabledCache = disabledCache;
63
+ this.buildCache(disabledCache, client);
64
+ }
65
+ buildCache(disabledCache, client) {
65
66
  // non-guild based
66
- if (!this.disabledCache.users) {
67
- this.users = new users_1.Users(this, client);
68
- }
69
- if (!this.disabledCache.guilds) {
70
- this.guilds = new guilds_1.Guilds(this, client);
71
- }
67
+ this.users = disabledCache.users ? undefined : new users_1.Users(this, client);
68
+ this.guilds = disabledCache.guilds ? undefined : new guilds_1.Guilds(this, client);
72
69
  // guild related
73
- if (!this.disabledCache.members) {
74
- this.members = new members_1.Members(this, client);
75
- }
76
- if (!this.disabledCache.voiceStates) {
77
- this.voiceStates = new voice_states_1.VoiceStates(this, client);
78
- }
70
+ this.members = disabledCache.members ? undefined : new members_1.Members(this, client);
71
+ this.voiceStates = disabledCache.voiceStates ? undefined : new voice_states_1.VoiceStates(this, client);
79
72
  // guild based
80
- if (!this.disabledCache.roles) {
81
- this.roles = new roles_1.Roles(this, client);
82
- }
83
- if (!this.disabledCache.overwrites) {
84
- this.overwrites = new overwrites_1.Overwrites(this, client);
85
- }
86
- if (!this.disabledCache.channels) {
87
- this.channels = new channels_1.Channels(this, client);
88
- }
89
- if (!this.disabledCache.emojis) {
90
- this.emojis = new emojis_1.Emojis(this, client);
91
- }
92
- if (!this.disabledCache.stickers) {
93
- this.stickers = new stickers_1.Stickers(this, client);
94
- }
95
- if (!this.disabledCache.presences) {
96
- this.presences = new presence_1.Presences(this, client);
97
- }
98
- if (!this.disabledCache.stageInstances) {
99
- this.stageInstances = new stage_instances_1.StageInstances(this, client);
100
- }
101
- if (!this.disabledCache.messages) {
102
- this.messages = new messages_1.Messages(this, client);
103
- }
104
- if (!this.disabledCache.bans) {
105
- this.bans = new bans_1.Bans(this, client);
106
- }
107
- if (this.disabledCache.onPacket) {
108
- //@ts-expect-error
109
- this.onPacket = () => {
110
- // disable cache
111
- };
112
- }
113
- }
114
- /** @internal */
115
- __setClient(client) {
116
- this.users?.__setClient(client);
117
- this.guilds?.__setClient(client);
118
- this.members?.__setClient(client);
119
- this.voiceStates?.__setClient(client);
120
- this.roles?.__setClient(client);
121
- this.overwrites?.__setClient(client);
122
- this.channels?.__setClient(client);
123
- this.emojis?.__setClient(client);
124
- this.stickers?.__setClient(client);
125
- this.presences?.__setClient(client);
126
- this.stageInstances?.__setClient(client);
127
- this.messages?.__setClient(client);
128
- this.bans?.__setClient(client);
73
+ this.roles = disabledCache.roles ? undefined : new roles_1.Roles(this, client);
74
+ this.overwrites = disabledCache.overwrites ? undefined : new overwrites_1.Overwrites(this, client);
75
+ this.channels = disabledCache.channels ? undefined : new channels_1.Channels(this, client);
76
+ this.emojis = disabledCache.emojis ? undefined : new emojis_1.Emojis(this, client);
77
+ this.stickers = disabledCache.stickers ? undefined : new stickers_1.Stickers(this, client);
78
+ this.presences = disabledCache.presences ? undefined : new presence_1.Presences(this, client);
79
+ this.stageInstances = disabledCache.stageInstances ? undefined : new stage_instances_1.StageInstances(this, client);
80
+ this.messages = disabledCache.messages ? undefined : new messages_1.Messages(this, client);
81
+ this.bans = disabledCache.bans ? undefined : new bans_1.Bans(this, client);
82
+ this.onPacket = disabledCache.onPacket
83
+ ? (() => {
84
+ //
85
+ })
86
+ : this.onPacketDefault.bind(this);
129
87
  }
130
88
  flush() {
131
89
  return this.adapter.flush();
@@ -353,7 +311,10 @@ class Cache {
353
311
  await this.adapter.bulkAddToRelationShip(relationshipsData);
354
312
  await this.adapter.bulkSet(allData);
355
313
  }
356
- async onPacket(event) {
314
+ onPacket(event) {
315
+ return this.onPacketDefault(event);
316
+ }
317
+ async onPacketDefault(event) {
357
318
  switch (event.t) {
358
319
  case 'READY':
359
320
  await this.users?.set(event.d.user.id, event.d.user);
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
3
3
  import type { Cache, ReturnCache } from '../../index';
4
4
  export declare class BaseResource<T = any, S = any> {
5
5
  protected cache: Cache;
6
- client: UsingClient;
6
+ readonly client: UsingClient;
7
7
  namespace: string;
8
- constructor(cache: Cache, client?: UsingClient);
8
+ constructor(cache: Cache, client: UsingClient);
9
9
  filter(data: any, id: string): boolean;
10
10
  get adapter(): import("../../index").Adapter;
11
11
  removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): import("../../../common").Awaitable<void>;
@@ -8,12 +8,6 @@ class BaseResource {
8
8
  namespace = 'base';
9
9
  constructor(cache, client) {
10
10
  this.cache = cache;
11
- if (client) {
12
- this.client = client;
13
- }
14
- }
15
- /** @internal */
16
- __setClient(client) {
17
11
  this.client = client;
18
12
  }
19
13
  //@ts-expect-error
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
3
3
  import type { Cache, ReturnCache } from '../../index';
4
4
  export declare class GuildBasedResource<T = any, S = any> {
5
5
  protected cache: Cache;
6
- client: UsingClient;
6
+ readonly client: UsingClient;
7
7
  namespace: string;
8
- constructor(cache: Cache, client?: UsingClient);
8
+ constructor(cache: Cache, client: UsingClient);
9
9
  filter(data: any, id: string, guild_id: string): boolean;
10
10
  parse(data: any, id: string, guild_id: string): any;
11
11
  get adapter(): import("../../index").Adapter;
@@ -8,12 +8,6 @@ class GuildBasedResource {
8
8
  namespace = 'base';
9
9
  constructor(cache, client) {
10
10
  this.cache = cache;
11
- if (client) {
12
- this.client = client;
13
- }
14
- }
15
- /** @internal */
16
- __setClient(client) {
17
11
  this.client = client;
18
12
  }
19
13
  //@ts-expect-error
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
3
3
  import type { Cache, ReturnCache } from '../../index';
4
4
  export declare class GuildRelatedResource<T = any, S = any> {
5
5
  protected cache: Cache;
6
- client: UsingClient;
6
+ readonly client: UsingClient;
7
7
  namespace: string;
8
- constructor(cache: Cache, client?: UsingClient);
8
+ constructor(cache: Cache, client: UsingClient);
9
9
  filter(data: any, id: string, guild_id?: string): boolean;
10
10
  parse(data: any, id: string, guild_id: string): any;
11
11
  get adapter(): import("../../index").Adapter;
@@ -8,12 +8,6 @@ class GuildRelatedResource {
8
8
  namespace = 'base';
9
9
  constructor(cache, client) {
10
10
  this.cache = cache;
11
- if (client) {
12
- this.client = client;
13
- }
14
- }
15
- /** @internal */
16
- __setClient(client) {
17
11
  this.client = client;
18
12
  }
19
13
  //@ts-expect-error
@@ -1,5 +1,5 @@
1
1
  import { ApiHandler } from '../api';
2
- import type { Adapter } from '../cache';
2
+ import type { Adapter, DisabledCache } from '../cache';
3
3
  import { Cache } from '../cache';
4
4
  import type { Command, CommandContext, ContextMenuCommand, ExtendedRC, ExtendedRCLocations, ExtraProps, MenuCommandContext, RegisteredMiddlewares, SubCommand, UsingClient } from '../commands';
5
5
  import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
@@ -155,7 +155,7 @@ export interface ServicesOptions {
155
155
  rest?: ApiHandler;
156
156
  cache?: {
157
157
  adapter?: Adapter;
158
- disabledCache?: boolean | Cache['disabledCache'] | ((cacheType: keyof Cache['disabledCache']) => boolean);
158
+ disabledCache?: boolean | DisabledCache | ((cacheType: keyof DisabledCache) => boolean);
159
159
  };
160
160
  langs?: {
161
161
  default?: string;
@@ -15,7 +15,7 @@ const handler_2 = require("../components/handler");
15
15
  const handler_3 = require("../langs/handler");
16
16
  class BaseClient {
17
17
  rest = new api_1.ApiHandler({ token: 'INVALID' });
18
- cache = new cache_1.Cache(0, new cache_1.MemoryAdapter());
18
+ cache = new cache_1.Cache(0, new cache_1.MemoryAdapter(), {}, this);
19
19
  applications = new common_1.ApplicationShorter(this);
20
20
  users = new common_1.UsersShorter(this);
21
21
  channels = new common_1.ChannelShorter(this);
@@ -142,7 +142,7 @@ class BaseClient {
142
142
  'users',
143
143
  'voiceStates',
144
144
  ];
145
- let disabledCache = this.cache.disabledCache;
145
+ let disabledCache = {};
146
146
  if (typeof cache.disabledCache === 'boolean') {
147
147
  for (const i of caches) {
148
148
  disabledCache[i] = cache.disabledCache;
@@ -156,7 +156,10 @@ class BaseClient {
156
156
  else if (typeof cache.disabledCache === 'object') {
157
157
  disabledCache = cache.disabledCache;
158
158
  }
159
- this.cache = new cache_1.Cache(this.cache.intents, cache.adapter ?? this.cache.adapter, disabledCache, this);
159
+ if (cache.adapter)
160
+ this.cache.adapter = cache.adapter;
161
+ if (cache.disabledCache)
162
+ this.cache.buildCache(disabledCache, this);
160
163
  }
161
164
  if (middlewares) {
162
165
  this.middlewares = middlewares;
@@ -195,7 +198,6 @@ class BaseClient {
195
198
  if (this.rest.options.token === 'INVALID')
196
199
  this.rest.options.token = token;
197
200
  this.rest.debug = debug;
198
- this.cache.__setClient(this);
199
201
  if (!this.handleCommand)
200
202
  this.handleCommand = new handle_1.HandleCommand(this);
201
203
  // The reason of this method is so for adapters that need to connect somewhere, have time to connect.
@@ -64,7 +64,7 @@ class WorkerClient extends base_1.BaseClient {
64
64
  }
65
65
  setServices(rest) {
66
66
  super.setServices(rest);
67
- if (rest.cache) {
67
+ if (rest.cache?.adapter) {
68
68
  this.__setServicesCache = true;
69
69
  }
70
70
  }
@@ -84,13 +84,8 @@ class WorkerClient extends base_1.BaseClient {
84
84
  this.logger = new __1.Logger({
85
85
  name: `[Worker #${workerData.workerId}]`,
86
86
  });
87
- if (this.__setServicesCache) {
88
- this.setServices({
89
- cache: {
90
- disabledCache: this.cache.disabledCache,
91
- },
92
- });
93
- }
87
+ if (this.__setServicesCache)
88
+ delete this.__setServicesCache;
94
89
  else {
95
90
  const adapter = new cache_1.WorkerAdapter(workerData);
96
91
  if (this.options.postMessage) {
@@ -99,11 +94,9 @@ class WorkerClient extends base_1.BaseClient {
99
94
  this.setServices({
100
95
  cache: {
101
96
  adapter,
102
- disabledCache: this.cache.disabledCache,
103
97
  },
104
98
  });
105
99
  }
106
- delete this.__setServicesCache;
107
100
  if (workerData.debug) {
108
101
  this.debugger = new __1.Logger({
109
102
  name: `[Worker #${workerData.workerId}]`,
@@ -39,8 +39,8 @@ export declare abstract class ContextMenuCommand {
39
39
  reload(): Promise<void>;
40
40
  abstract run?(context: MenuCommandContext<any>): any;
41
41
  onAfterRun?(context: MenuCommandContext<any>, error: unknown | undefined): any;
42
- onRunError(context: MenuCommandContext<any, never>, error: unknown): any;
43
- onMiddlewaresError(context: MenuCommandContext<any, never>, error: string): any;
44
- onBotPermissionsFail(context: MenuCommandContext<any, never>, permissions: PermissionStrings): any;
45
- onInternalError(client: UsingClient, command: ContextMenuCommand, error?: unknown): any;
42
+ onRunError?(context: MenuCommandContext<any, never>, error: unknown): any;
43
+ onMiddlewaresError?(context: MenuCommandContext<any, never>, error: string): any;
44
+ onBotPermissionsFail?(context: MenuCommandContext<any, never>, permissions: PermissionStrings): any;
45
+ onInternalError?(client: UsingClient, command: ContextMenuCommand, error?: unknown): any;
46
46
  }
@@ -39,17 +39,5 @@ class ContextMenuCommand {
39
39
  const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
40
40
  Object.setPrototypeOf(this, __tempCommand.prototype);
41
41
  }
42
- onRunError(context, error) {
43
- context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
44
- }
45
- onMiddlewaresError(context, error) {
46
- context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
47
- }
48
- onBotPermissionsFail(context, permissions) {
49
- context.client.logger.fatal(`${this.name}.<onBotPermissionsFail>`, context.author.id, permissions);
50
- }
51
- onInternalError(client, command, error) {
52
- client.logger.fatal(command.name, error);
53
- }
54
42
  }
55
43
  exports.ContextMenuCommand = ContextMenuCommand;
@@ -40,7 +40,7 @@ class HandleCommand {
40
40
  if (context.guildId && command.botPermissions) {
41
41
  const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
42
42
  if (permissions)
43
- return command.onBotPermissionsFail(context, permissions);
43
+ return command.onBotPermissionsFail?.(context, permissions);
44
44
  }
45
45
  const resultGlobal = await this.runGlobalMiddlewares(command, context);
46
46
  if (typeof resultGlobal === 'boolean')
@@ -54,13 +54,13 @@ class HandleCommand {
54
54
  await command.onAfterRun?.(context, undefined);
55
55
  }
56
56
  catch (error) {
57
- await command.onRunError(context, error);
57
+ await command.onRunError?.(context, error);
58
58
  await command.onAfterRun?.(context, error);
59
59
  }
60
60
  }
61
61
  catch (error) {
62
62
  try {
63
- await command.onInternalError(this.client, command, error);
63
+ await command.onInternalError?.(this.client, command, error);
64
64
  }
65
65
  catch {
66
66
  // pass
@@ -448,14 +448,10 @@ class CommandHandler extends common_1.BaseHandler {
448
448
  if (!(commandInstance instanceof menu_1.ContextMenuCommand))
449
449
  return false;
450
450
  commandInstance.onAfterRun ??= this.client.options.commands?.defaults?.onAfterRun;
451
- if (this.client.options.commands?.defaults?.onBotPermissionsFail)
452
- commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
453
- if (this.client.options.commands?.defaults?.onInternalError)
454
- commandInstance.onInternalError ??= this.client.options.commands.defaults.onInternalError;
455
- if (this.client.options.commands?.defaults?.onMiddlewaresError)
456
- commandInstance.onMiddlewaresError ??= this.client.options.commands.defaults.onMiddlewaresError;
457
- if (this.client.options.commands?.defaults?.onRunError)
458
- commandInstance.onRunError ??= this.client.options.commands.defaults.onRunError;
451
+ commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
452
+ commandInstance.onInternalError ??= this.client.options.commands?.defaults?.onInternalError;
453
+ commandInstance.onMiddlewaresError ??= this.client.options.commands?.defaults?.onMiddlewaresError;
454
+ commandInstance.onRunError ??= this.client.options.commands?.defaults?.onRunError;
459
455
  return commandInstance;
460
456
  }
461
457
  stablishCommandDefaults(commandInstance) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "2.1.1-dev-11768778519.0",
3
+ "version": "2.1.1-dev-11842640994.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",