mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix
This commit is contained in:
parent
cf780977bc
commit
b059fb0d5d
2
src/cache/adapters/default.ts
vendored
2
src/cache/adapters/default.ts
vendored
@ -1,6 +1,8 @@
|
||||
import type { Adapter } from './types';
|
||||
|
||||
export class MemoryAdapter implements Adapter {
|
||||
isAsync = false;
|
||||
|
||||
readonly storage = new Map<string, string>();
|
||||
readonly relationships = new Map<string, string[]>();
|
||||
|
||||
|
2
src/cache/adapters/redis.ts
vendored
2
src/cache/adapters/redis.ts
vendored
@ -14,6 +14,8 @@ interface RedisAdapterOptions {
|
||||
}
|
||||
|
||||
export class RedisAdapter implements Adapter {
|
||||
isAsync = true;
|
||||
|
||||
client: import('ioredis').Redis;
|
||||
namespace: string;
|
||||
|
||||
|
2
src/cache/adapters/types.ts
vendored
2
src/cache/adapters/types.ts
vendored
@ -1,4 +1,6 @@
|
||||
export interface Adapter {
|
||||
isAsync: boolean;
|
||||
|
||||
scan(query: string, keys?: false): RPV<any[]>;
|
||||
scan(query: string, keys: true): RPV<string[]>;
|
||||
scan(query: string, keys?: boolean): RPV<(any | string)[]>;
|
||||
|
1
src/cache/adapters/workeradapter.ts
vendored
1
src/cache/adapters/workeradapter.ts
vendored
@ -5,6 +5,7 @@ import type { WorkerSendCacheRequest } from '../../websocket/discord/worker';
|
||||
import type { Adapter } from './types';
|
||||
|
||||
export class WorkerAdapter implements Adapter {
|
||||
isAsync = true;
|
||||
promises = new Map<string, { resolve: (value: unknown) => void; timeout: NodeJS.Timeout }>();
|
||||
|
||||
constructor(readonly parent: MessagePort) {}
|
||||
|
1
src/cache/index.ts
vendored
1
src/cache/index.ts
vendored
@ -102,7 +102,6 @@ export class Cache {
|
||||
constructor(
|
||||
public intents: number,
|
||||
public adapter: Adapter,
|
||||
public asyncCache = false,
|
||||
readonly disabledCache: (NonGuildBased | GuildBased | GuildRelated)[] = [],
|
||||
client?: BaseClient,
|
||||
) {
|
||||
|
@ -97,7 +97,6 @@ export class BaseClient {
|
||||
this.cache = new Cache(
|
||||
this.cache?.intents ?? 0,
|
||||
cache.adapter,
|
||||
cache.asyncCache ?? this.cache?.asyncCache,
|
||||
cache.disabledCache ?? this.cache?.disabledCache,
|
||||
this,
|
||||
);
|
||||
@ -147,7 +146,7 @@ export class BaseClient {
|
||||
}
|
||||
|
||||
if (!this.cache) {
|
||||
this.cache = new Cache(0, new MemoryAdapter(), false, [], this);
|
||||
this.cache = new Cache(0, new MemoryAdapter(), [], this);
|
||||
} else {
|
||||
this.cache.__setClient(this);
|
||||
}
|
||||
@ -290,7 +289,7 @@ export type RuntimeConfig = OmitInsert<InternalRuntimeConfig, 'intents', { inten
|
||||
|
||||
export type ServicesOptions = {
|
||||
rest?: ApiHandler;
|
||||
cache?: { adapter: Adapter; disabledCache?: Cache['disabledCache']; asyncCache?: boolean };
|
||||
cache?: { adapter: Adapter; disabledCache?: Cache['disabledCache'] };
|
||||
langs?: {
|
||||
default?: string;
|
||||
aliases?: Record<string, LocaleString[]>;
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
type WebhookMessage,
|
||||
} from '../..';
|
||||
import type { Client, WorkerClient } from '../../client';
|
||||
import { MessageFlags, type When, type If, type UnionToTuple } from '../../common';
|
||||
import { MessageFlags, type If, type UnionToTuple, type When } from '../../common';
|
||||
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
|
||||
import {
|
||||
Message,
|
||||
@ -108,12 +108,12 @@ export class CommandContext<T extends OptionsRecord = {}, M extends keyof Regist
|
||||
channel(mode?: 'cache'): ReturnCache<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
|
||||
channel(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (this.interaction?.channel && mode === 'cache')
|
||||
return this.client.cache.asyncCache ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
||||
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
||||
switch (mode) {
|
||||
case 'cache':
|
||||
return (
|
||||
this.client.cache.channels?.get(this.channelId) ||
|
||||
(this.client.cache.asyncCache ? (Promise.resolve() as any) : undefined)
|
||||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
|
||||
);
|
||||
default:
|
||||
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
||||
@ -124,12 +124,12 @@ export class CommandContext<T extends OptionsRecord = {}, M extends keyof Regist
|
||||
me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
|
||||
me(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (!this.guildId)
|
||||
return mode === 'cache' ? (this.client.cache.asyncCache ? Promise.resolve() : undefined) : Promise.resolve();
|
||||
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
|
||||
switch (mode) {
|
||||
case 'cache':
|
||||
return (
|
||||
this.client.cache.members?.get(this.client.botId, this.guildId) ||
|
||||
(this.client.cache.asyncCache ? (Promise.resolve() as any) : undefined)
|
||||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
|
||||
);
|
||||
default:
|
||||
return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
|
||||
@ -141,7 +141,7 @@ export class CommandContext<T extends OptionsRecord = {}, M extends keyof Regist
|
||||
guild(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (!this.guildId)
|
||||
return (mode === 'cache'
|
||||
? this.client.cache.asyncCache
|
||||
? this.client.cache.adapter.isAsync
|
||||
? Promise.resolve()
|
||||
: undefined
|
||||
: Promise.resolve()) as unknown as undefined;
|
||||
@ -149,7 +149,7 @@ export class CommandContext<T extends OptionsRecord = {}, M extends keyof Regist
|
||||
case 'cache':
|
||||
return (
|
||||
this.client.cache.guilds?.get(this.guildId) ||
|
||||
(this.client.cache.asyncCache ? (Promise.resolve() as any) : undefined)
|
||||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
|
||||
);
|
||||
default:
|
||||
return this.client.guilds.fetch(this.guildId, mode === 'rest');
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { CommandContext, type WebhookMessage, type ReturnCache } from '../..';
|
||||
import { CommandContext, type ReturnCache, type WebhookMessage } from '../..';
|
||||
import {
|
||||
ApplicationCommandType,
|
||||
MessageFlags,
|
||||
type When,
|
||||
toSnakeCase,
|
||||
type InteractionCreateBodyRequest,
|
||||
type InteractionMessageUpdateBodyRequest,
|
||||
type UnionToTuple,
|
||||
type When,
|
||||
} from '../../common';
|
||||
import {
|
||||
Message,
|
||||
@ -100,7 +100,7 @@ export class MenuCommandContext<
|
||||
channel(mode?: 'cache'): ReturnCache<AllChannels>;
|
||||
channel(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (this.interaction?.channel && mode === 'cache')
|
||||
return this.client.cache.asyncCache ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
||||
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
||||
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ export class MenuCommandContext<
|
||||
me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
|
||||
me(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (!this.guildId)
|
||||
return mode === 'cache' ? (this.client.cache.asyncCache ? Promise.resolve() : undefined) : Promise.resolve();
|
||||
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
|
||||
switch (mode) {
|
||||
case 'cache':
|
||||
return this.client.cache.members?.get(this.client.botId, this.guildId);
|
||||
@ -122,7 +122,7 @@ export class MenuCommandContext<
|
||||
guild(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||
if (!this.guildId)
|
||||
return (
|
||||
mode === 'cache' ? (this.client.cache.asyncCache ? Promise.resolve() : undefined) : Promise.resolve()
|
||||
mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve()
|
||||
) as any;
|
||||
switch (mode) {
|
||||
case 'cache':
|
||||
|
Loading…
x
Reference in New Issue
Block a user