Skip to content

Commit 47677d3

Browse files
committed
πŸš€ feat: lets go to jsr [SMALL BREAKING: READ COMMIT MSG]
βž• feat: use node redis instead of denodrivers redis
1 parent 9ca7082 commit 47677d3

File tree

9 files changed

+109
-46
lines changed

9 files changed

+109
-46
lines changed

β€Ždeno.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@
77
},
88
"name": "@harmony/harmony",
99
"version": "2.9.1",
10-
"exports": "./mod.ts"
10+
"exports": "./mod.ts",
11+
"publish": {
12+
"include": [
13+
"mod.ts",
14+
"deps.ts",
15+
"deploy.ts",
16+
"src/**/*",
17+
"assets/*",
18+
"README.md",
19+
"tsconfig.json"
20+
]
21+
}
1122
}

β€Žsrc/cache/redis.ts

+16-23
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import { ICacheAdapter } from './adapter.ts'
22
// Not in deps.ts to allow optional dep loading
3-
import {
4-
connect,
5-
Redis,
6-
RedisConnectOptions,
7-
RedisValue
8-
} from 'https://deno.land/x/redis@v0.25.1/mod.ts'
3+
import { createClient, RedisClientOptions } from 'npm:redis@4.6.13'
94

105
/** Redis Cache Adapter for using Redis as a cache-provider. */
116
export class RedisCacheAdapter implements ICacheAdapter {
12-
_redis: Promise<Redis>
13-
redis?: Redis
7+
_redis: Promise<ReturnType<typeof createClient>>
8+
redis?: ReturnType<typeof createClient>
149
ready: boolean = false
1510
readonly _expireIntervalTimer: number = 5000
1611
private _expireInterval?: number
1712

18-
constructor(options: RedisConnectOptions) {
19-
this._redis = connect(options)
13+
constructor(options: RedisClientOptions) {
14+
this._redis = createClient(options).connect()
2015
this._redis.then(
2116
(redis) => {
2217
this.redis = redis
@@ -31,17 +26,17 @@ export class RedisCacheAdapter implements ICacheAdapter {
3126

3227
private _startExpireInterval(): void {
3328
this._expireInterval = setInterval(() => {
34-
this.redis?.scan(0, { pattern: '*:expires' }).then(([_, names]) => {
29+
this.redis?.scan(0, { MATCH: '*:expires' }).then(({ keys: names }) => {
3530
for (const name of names) {
36-
this.redis?.hvals(name).then((vals) => {
31+
this.redis?.hVals(name).then((vals) => {
3732
for (const val of vals) {
3833
const expireVal: {
3934
name: string
4035
key: string
4136
at: number
4237
} = JSON.parse(val)
4338
const expired = new Date().getTime() > expireVal.at
44-
if (expired) this.redis?.hdel(expireVal.name, expireVal.key)
39+
if (expired) this.redis?.hDel(expireVal.name, expireVal.key)
4540
}
4641
})
4742
}
@@ -55,7 +50,7 @@ export class RedisCacheAdapter implements ICacheAdapter {
5550

5651
async get<T>(cacheName: string, key: string): Promise<T | undefined> {
5752
await this._checkReady()
58-
const cache = await this.redis?.hget(cacheName, key)
53+
const cache = await this.redis?.hGet(cacheName, key)
5954
if (cache === undefined) return
6055
try {
6156
return JSON.parse(cache) as T
@@ -71,15 +66,13 @@ export class RedisCacheAdapter implements ICacheAdapter {
7166
expire?: number
7267
): Promise<void> {
7368
await this._checkReady()
74-
await this.redis?.hset(
69+
await this.redis?.hSet(
7570
cacheName,
7671
key,
77-
typeof value === 'object'
78-
? JSON.stringify(value)
79-
: (value as unknown as RedisValue)
72+
typeof value === 'object' ? JSON.stringify(value) : (value as any)
8073
)
8174
if (expire !== undefined) {
82-
await this.redis?.hset(
75+
await this.redis?.hSet(
8376
`${cacheName}:expires`,
8477
key,
8578
JSON.stringify({
@@ -93,18 +86,18 @@ export class RedisCacheAdapter implements ICacheAdapter {
9386

9487
async delete(cacheName: string, ...keys: string[]): Promise<boolean> {
9588
await this._checkReady()
96-
return ((await this.redis?.hdel(cacheName, ...keys)) ?? 0) === keys.length
89+
return ((await this.redis?.hDel(cacheName, keys)) ?? 0) === keys.length
9790
}
9891

9992
async array<T>(cacheName: string): Promise<T[] | undefined> {
10093
await this._checkReady()
101-
const data = await this.redis?.hvals(cacheName)
94+
const data = await this.redis?.hVals(cacheName)
10295
return data?.map((e: string) => JSON.parse(e))
10396
}
10497

10598
async keys(cacheName: string): Promise<string[] | undefined> {
10699
await this._checkReady()
107-
return this.redis?.hkeys(cacheName)
100+
return this.redis?.hKeys(cacheName)
108101
}
109102

110103
async deleteCache(cacheName: string): Promise<boolean> {
@@ -114,6 +107,6 @@ export class RedisCacheAdapter implements ICacheAdapter {
114107

115108
async size(cacheName: string): Promise<number | undefined> {
116109
await this._checkReady()
117-
return this.redis?.hlen(cacheName)
110+
return this.redis?.hLen(cacheName)
118111
}
119112
}

β€Žsrc/client/client.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
136136
fetchGatewayInfo: boolean = true
137137

138138
/** Voice Connections Manager */
139-
readonly voice = new VoiceManager(this)
139+
readonly voice: VoiceManager = new VoiceManager(this)
140140

141141
/** Users Manager, containing all Users cached */
142142
readonly users: UsersManager = new UsersManager(this)
@@ -487,7 +487,12 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
487487

488488
/** Event decorator to create an Event handler from function */
489489
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
490-
export function event(name?: keyof ClientEvents) {
490+
export function event(
491+
name?: keyof ClientEvents
492+
): (
493+
original: (...args: any[]) => any,
494+
ctx: ClassMethodDecoratorContext<Client | Extension>
495+
) => (...args: any[]) => any {
491496
return function (
492497
original: (...args: any[]) => any,
493498
{

β€Žsrc/commands/client.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export class CommandClient extends Client implements CommandClientOptions {
9494
commands: CommandsManager = new CommandsManager(this)
9595
categories: CategoriesManager = new CategoriesManager(this)
9696

97-
middlewares = new Array<CommandContextMiddleware<CommandContext>>()
97+
middlewares: Array<CommandContextMiddleware<CommandContext>> = new Array<
98+
CommandContextMiddleware<CommandContext>
99+
>()
98100

99101
globalCommandCooldown = 0
100102
globalCooldown = 0
@@ -518,7 +520,12 @@ export class CommandClient extends Client implements CommandClientOptions {
518520
/**
519521
* Command decorator. Decorates the function with optional metadata as a Command registered upon constructing class.
520522
*/
521-
export function command(options?: CommandOptions) {
523+
export function command(
524+
options?: CommandOptions
525+
): (
526+
original: (...args: any[]) => any,
527+
ctx: ClassMethodDecoratorContext<CommandClient | Extension>
528+
) => (...args: any[]) => any {
522529
return function (
523530
original: (...args: any[]) => any,
524531
{
@@ -552,7 +559,12 @@ export function command(options?: CommandOptions) {
552559
/**
553560
* Sub Command decorator. Decorates the function with optional metadata as a Sub Command registered upon constructing class.
554561
*/
555-
export function subcommand(options?: CommandOptions) {
562+
export function subcommand(
563+
options?: CommandOptions
564+
): (
565+
original: (...args: any[]) => any,
566+
ctx: ClassMethodDecoratorContext<Command>
567+
) => (...args: any[]) => any {
556568
return function (
557569
original: (...args: any[]) => any,
558570
{

β€Žsrc/rest/bucket.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let invalidCount = 0
4040
let invalidCountResetTime: number | null = null
4141

4242
export class BucketHandler {
43-
queue = new RequestQueue()
43+
queue: RequestQueue = new RequestQueue()
4444
reset = -1
4545
remaining = -1
4646
limit = -1

β€Žsrc/structures/guildNewsChannel.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { Mixin } from '../../deps.ts'
2+
import type { GuildNewsChannelPayload } from '../types/channel.ts'
3+
import type { Client } from '../client/mod.ts'
4+
import type { Guild } from './guild.ts'
25
import { GuildTextBasedChannel } from './guildTextChannel.ts'
36
import { GuildThreadAvailableChannel } from './guildThreadAvailableChannel.ts'
47

5-
export class NewsChannel extends Mixin(
6-
GuildTextBasedChannel,
7-
GuildThreadAvailableChannel
8-
) {}
8+
const NewsChannelSuper: (abstract new (
9+
client: Client,
10+
data: GuildNewsChannelPayload,
11+
guild: Guild
12+
) => GuildTextBasedChannel & GuildThreadAvailableChannel) &
13+
Pick<typeof GuildTextBasedChannel, keyof typeof GuildTextBasedChannel> &
14+
Pick<
15+
typeof GuildThreadAvailableChannel,
16+
keyof typeof GuildThreadAvailableChannel
17+
> = Mixin(GuildTextBasedChannel, GuildThreadAvailableChannel)
18+
19+
export class NewsChannel extends NewsChannelSuper {}

β€Žsrc/structures/guildTextChannel.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ import { CHANNEL } from '../types/endpoint.ts'
1212
import type { Message } from './message.ts'
1313
import { GuildThreadAvailableChannel } from './guildThreadAvailableChannel.ts'
1414

15+
const GuildTextBasedChannelSuper: (abstract new (
16+
client: Client,
17+
data: GuildTextBasedChannelPayload,
18+
guild: Guild
19+
) => TextChannel & GuildChannel) &
20+
Pick<typeof TextChannel, keyof typeof TextChannel> &
21+
Pick<typeof GuildChannel, keyof typeof GuildChannel> = Mixin(
22+
TextChannel,
23+
GuildChannel
24+
)
25+
1526
/** Represents a Text Channel but in a Guild */
16-
export class GuildTextBasedChannel extends Mixin(TextChannel, GuildChannel) {
27+
export class GuildTextBasedChannel extends GuildTextBasedChannelSuper {
1728
constructor(
1829
client: Client,
1930
data: GuildTextBasedChannelPayload,
@@ -81,8 +92,16 @@ export class GuildTextBasedChannel extends Mixin(TextChannel, GuildChannel) {
8192
}
8293
}
8394

95+
const GuildTextChannelSuper: (abstract new (
96+
client: Client,
97+
data: any,
98+
guild: Guild
99+
) => GuildTextBasedChannel & GuildThreadAvailableChannel) &
100+
Pick<typeof GuildTextBasedChannel, keyof typeof GuildTextBasedChannel> &
101+
Pick<
102+
typeof GuildThreadAvailableChannel,
103+
keyof typeof GuildThreadAvailableChannel
104+
> = Mixin(GuildTextBasedChannel, GuildThreadAvailableChannel)
105+
84106
// Still exist for API compatibility
85-
export class GuildTextChannel extends Mixin(
86-
GuildTextBasedChannel,
87-
GuildThreadAvailableChannel
88-
) {}
107+
export class GuildTextChannel extends GuildTextChannelSuper {}

β€Žsrc/structures/guildVoiceChannel.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ import type {
1717
import { Mixin } from '../../deps.ts'
1818
import { TextChannel } from './textChannel.ts'
1919

20-
export class VoiceChannel extends Mixin(GuildChannel, TextChannel) {
20+
const VoiceChannelSuper: (abstract new (
21+
client: Client,
22+
data: GuildVoiceChannelPayload,
23+
guild: Guild
24+
) => TextChannel & GuildChannel) &
25+
Pick<typeof TextChannel, keyof typeof TextChannel> &
26+
Pick<typeof GuildChannel, keyof typeof GuildChannel> = Mixin(
27+
TextChannel,
28+
GuildChannel
29+
)
30+
31+
export class VoiceChannel extends VoiceChannelSuper {
2132
bitrate!: string
2233
userLimit!: number
23-
voiceStates = new GuildChannelVoiceStatesManager(
24-
this.client,
25-
this.guild.voiceStates,
26-
this
27-
)
34+
voiceStates: GuildChannelVoiceStatesManager =
35+
new GuildChannelVoiceStatesManager(
36+
this.client,
37+
this.guild.voiceStates,
38+
this
39+
)
2840

2941
constructor(client: Client, data: GuildVoiceChannelPayload, guild: Guild) {
3042
super(client, data, guild)

β€Žsrc/utils/permissions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type PermissionResolvable = BitFieldResolvable
77
/** Represents permissions BitField */
88
export class Permissions extends BitField {
99
static DEFAULT = 104324673n
10-
static ALL = Object.values(PermissionFlags).reduce(
10+
static ALL: bigint = Object.values(PermissionFlags).reduce(
1111
(all, p) => BigInt(all) | BigInt(p),
1212
0n
1313
)

0 commit comments

Comments
Β (0)