Skip to content

Commit

Permalink
chore!: require node 16 and bump ts target
Browse files Browse the repository at this point in the history
  • Loading branch information
HibanaSama committed Jul 15, 2023
1 parent 17da629 commit e72f4a7
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [ 12.18.0 ]
node-version: [ 16.13.0 ]
os: [ ubuntu-latest ]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12.18
node-version: 16.13
- name: Install dependencies
run: npm ci
- name: Run linters
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 12.18
node-version: 16.13
registry-url: https://registry.npmjs.org/
- name: Install required packages
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 12.18
node-version: 16.13
registry-url: https://registry.npmjs.org/
- name: Install required packages
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [ 12.18.0 ]
node-version: [ 16.13.0 ]
os: [ ubuntu-latest ]

steps:
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ Release deadline: When it's ready.
* [x] Cache must handle PresencesCachingPolicy
* [x] Cache must handle UsersCachingPolicy
* [x] Cache must handle OverwritesCachingPolicy
* [x] Cache must handle InvitesCachingPolicy
* [x] Cache must handle StickersCachingPolicy
* [x] Cache must handle CommandsCachingPolicy
* [x] All the policies listed above must be able to handle custom caching functions

SID - still in development
Expand All @@ -140,7 +143,9 @@ SID - still in development
* [x] Implement Presences
* [x] Implement Reactions
* [x] Implement Users
* [ ] Implement Interactions (SID)
* [x] Implement Interactions
* [x] Implement Overwrites (SID)
* [x] Implement Invites (SID)

### User-land APIs
* [x] Collection
Expand All @@ -159,6 +164,8 @@ SID - still in development
* [x] ThreadMembersManager/ApplicationThreadMembersManager (SID)
* [x] MessageReactionsManager/ApplicationReactionsManager
* [x] UsersManager (SID)
* [x] ApplicationInteractionsManager/ApplicationInteractionsApplicationCommandsManager/GuildApplicationCommandsManager
* [x] ApplicationInvitesManager/GuildInvitesManager (SID)

## Contributing
Feel free to create a PR, but check if there is an existing one.
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"ws": "7.4.6"
},
"engines": {
"node": ">=12.18"
"node": ">=16.13"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 3 additions & 3 deletions src/api/entities/guild/Guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RawGuildData } from '@src/api/entities/guild/interfaces/RawGuildData'
import { DiscordLocale } from '@src/constants/common/DiscordLocale'
import { AnyGuildWritableChannel } from '@src/api/entities/channel/interfaces/AnyGuildWritableChannel'
import { GuildMember } from '@src/api/entities/member/GuildMember'
import { GuildAppCommandsManager } from '@src/api'
import { GuildApplicationCommandsManager } from '@src/api'

export class Guild extends AbstractViewableGuild {
public unavailable = false
Expand All @@ -24,7 +24,7 @@ export class Guild extends AbstractViewableGuild {
public declare systemChannelId?: string
public declare ownerId: string
public declare membersCount: number
public declare commands: GuildAppCommandsManager
public declare commands: GuildApplicationCommandsManager

async init(data: GuildData | RawGuildData, options?: EntityInitOptions): Promise<this> {
await super.init(data)
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Guild extends AbstractViewableGuild {
}

if (!this.commands) {
this.commands = new GuildAppCommandsManager(this.app, {
this.commands = new GuildApplicationCommandsManager(this.app, {
guild: this.id,
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/api/entities/interaction/AppCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class AppCommand extends AbstractEntity {
declare applicationId: string
declare type: AppCommandTypes
declare guildId?: string
public options: AppCommandOption[] = []
declare defaultMemberPermissions?: ReadonlyPermissions
declare dmPermission?: boolean
declare nsfw?: boolean
public options: AppCommandOption[] = []

async init(data: AppCommandData | RawAppCommandData, options?: AppCommandEntityInitOptions): Promise<this> {
attach(this, data, {
Expand Down Expand Up @@ -76,6 +76,7 @@ export class AppCommand extends AbstractEntity {
options: true,
defaultMemberPermissions: true,
dmPermission: true,
nsfw: true,
}, obj)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DiscordRestApplication } from '@src/core'
import { DiscordooError, resolveBigBitField, resolveCommandId, resolveGuildId } from '@src/utils'
import { Keyspaces } from '@src/constants'

export class ApplicationInteractionsSlashCommandManager extends EntitiesManager {
export class ApplicationInteractionsApplicationCommandManager extends EntitiesManager {
public cache: EntitiesCacheManager<AppCommand>

constructor(app: DiscordRestApplication) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
const guildId = resolveGuildId(commandData.guild!)
if (!guildId) {
throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#createGuild', 'Cannot create guild command without guild id'
'ApplicationInteractionsApplicationCommandManager#createGuild', 'Cannot create guild command without guild id'
)
}

Expand All @@ -73,7 +73,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async deleteGlobal(command: CommandResolvable): Promise<boolean> {
const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#deleteGlobal',
'ApplicationInteractionsApplicationCommandManager#deleteGlobal',
'Cannot delete global command without command id.'
)

Expand All @@ -86,13 +86,13 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async deleteGuild(guild: GuildResolvable, command: CommandResolvable): Promise<boolean> {
const guildId = resolveGuildId(guild)
if (!guildId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#deleteGuild',
'ApplicationInteractionsApplicationCommandManager#deleteGuild',
'Cannot delete guild command without guild id.'
)

const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#deleteGuild',
'ApplicationInteractionsApplicationCommandManager#deleteGuild',
'Cannot delete guild command without command id.'
)

Expand All @@ -104,7 +104,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async editGlobal(command: CommandResolvable, data: AppCommandEditData): Promise<AppCommand | undefined> {
const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#editGlobal',
'ApplicationInteractionsApplicationCommandManager#editGlobal',
'Cannot edit global command without command id.'
)

Expand Down Expand Up @@ -132,13 +132,13 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async editGuild(guild: GuildResolvable, command: CommandResolvable, data: GuildAppCommandEditData): Promise<AppCommand | undefined> {
const guildId = resolveGuildId(guild)
if (!guildId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#editGuild',
'ApplicationInteractionsApplicationCommandManager#editGuild',
'Cannot edit guild command without guild id.'
)

const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#editGuild',
'ApplicationInteractionsApplicationCommandManager#editGuild',
'Cannot edit guild command without command id.'
)

Expand All @@ -165,7 +165,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async fetchGlobalOne(command: CommandResolvable): Promise<AppCommand | undefined> {
const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#fetchGlobalOne',
'ApplicationInteractionsApplicationCommandManager#fetchGlobalOne',
'Cannot fetch global command without command id.'
)

Expand All @@ -184,13 +184,13 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async fetchGuildOne(guild: GuildResolvable, command: CommandResolvable): Promise<AppCommand | undefined> {
const guildId = resolveGuildId(guild)
if (!guildId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#fetchGuildOne',
'ApplicationInteractionsApplicationCommandManager#fetchGuildOne',
'Cannot fetch guild command without guild id.'
)

const commandId = resolveCommandId(command)
if (!commandId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#fetchGuildOne',
'ApplicationInteractionsApplicationCommandManager#fetchGuildOne',
'Cannot fetch guild command without command id.'
)

Expand Down Expand Up @@ -228,7 +228,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
async fetchGuildMany(guild: GuildResolvable, options: FetchCommandOptions = {}): Promise<AppCommand[] | undefined> {
const guildId = resolveGuildId(guild)
if (!guildId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#fetchGuildMany',
'ApplicationInteractionsApplicationCommandManager#fetchGuildMany',
'Cannot fetch guild commands without guild id.'
)

Expand Down Expand Up @@ -280,7 +280,7 @@ export class ApplicationInteractionsSlashCommandManager extends EntitiesManager
commandsData.forEach((command) => {
const guildId = resolveGuildId(command.guild!)
if (!guildId) throw new DiscordooError(
'ApplicationInteractionsSlashCommandManager#overwriteGuild',
'ApplicationInteractionsApplicationCommandManager#overwriteGuild',
'Cannot fetch guild commands without guild id.'
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EntitiesManager } from '@src/api/managers/EntitiesManager'
import { InteractionResponseTypes, MessageFlags } from '@src/constants'
import {
AppCommandOptionChoiceData,
ApplicationInteractionsSlashCommandManager,
ApplicationInteractionsApplicationCommandManager,
EntitiesUtil, InteractionMessageEditOptions,
MessageCreateOptions, MessageResolvable,
ModalBuilder,
Expand All @@ -16,11 +16,11 @@ import { InteractionMessageContent } from '@src/api/entities/message/interfaces/
import { InteractionMessageCreateOptions } from '@src/api/entities/message/interfaces/MessageCreateOptions'

export class ApplicationInteractionsManager extends EntitiesManager {
public commands: ApplicationInteractionsSlashCommandManager
public commands: ApplicationInteractionsApplicationCommandManager

constructor(app: DiscordRestApplication) {
super(app)
this.commands = new ApplicationInteractionsSlashCommandManager(app)
this.commands = new ApplicationInteractionsApplicationCommandManager(app)
}

async deferReply(interactionId: string, token: string, ephemeral?: boolean): Promise<boolean> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {
AppCommand, AppCommandCreateData,
CommandResolvable,
EntitiesCacheManager,
GuildAppCommandsManagerOptions,
GuildApplicationCommandsManagerOptions,
RawAppCommandCreateData,
SlashCommandBuilder
} from '@src/api'
import { RestEligibleDiscordApplication } from '@src/core'

export class GuildAppCommandsManager extends EntitiesManager {
export class GuildApplicationCommandsManager extends EntitiesManager {
public cache: EntitiesCacheManager<AppCommand>
public options: GuildAppCommandsManagerOptions
public options: GuildApplicationCommandsManagerOptions

constructor(app: RestEligibleDiscordApplication, options: GuildAppCommandsManagerOptions) {
constructor(app: RestEligibleDiscordApplication, options: GuildApplicationCommandsManagerOptions) {
super(app)

this.options = options
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface GuildApplicationCommandsManagerOptions {
guild: string
}
6 changes: 3 additions & 3 deletions src/api/managers/interactions/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { ApplicationInteractionsSlashCommandManager } from './ApplicationInteractionsSlashCommandManager'
export { ApplicationInteractionsApplicationCommandManager } from './ApplicationInteractionsApplicationCommandManager'
export { InteractionResolvedCacheManagerData } from './InteractionResolvedCacheManagerData'
export { InteractionResolvedCacheManager } from './InteractionResolvedCacheManager'
export { GuildAppCommandsManagerOptions } from './GuildAppCommandsManagerOptions'
export { GuildApplicationCommandsManagerOptions } from './GuildApplicationCommandsManagerOptions'
export { ApplicationInteractionsManager } from './ApplicationInteractionsManager'
export { GuildAppCommandsManager } from './GuildAppCommandsManager'
export { GuildApplicationCommandsManager } from './GuildApplicationCommandsManager'
export { FetchCommandOptions } from './FetchCommandOptions'
export { FetchCommandQuery } from './FetchCommandQuery'

Expand Down
18 changes: 9 additions & 9 deletions src/utils/DiscordSnowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ export class DiscordSnowflake {

const segments = [
// 42 bits timestamp block (22 empty bits, 5 for worker id + 5 for process id + 12 for increment)
b(timestamp - EPOCH) << b(22),
b(timestamp - EPOCH) << 22n,
// 5 bits worker id block (17 empty bits, 5 for shard id + 12 for increment)
b(workerId) << b(17),
b(workerId) << 17n,
// 5 bits worker id block (12 empty bits, 12 for increment)
b(processId) << b(12),
b(processId) << 12n,
// 12 bits increment block (0 empty bits)
b(increment ?? INCREMENT++)
]

// just add up the segments and get valid discord snowflake
return segments.reduce((prev, curr) => prev + curr, b(0)).toString()
return segments.reduce((prev, curr) => prev + curr, 0n).toString()
}

static generatePartial(timestamp: Date | number = Date.now()): string {
if (timestamp instanceof Date) timestamp = timestamp.getTime()

const b = BigInt

return (b(timestamp - EPOCH) << b(22)).toString()
return (b(timestamp - EPOCH) << 22n).toString()
}

static deconstruct(snowflake: string): DeconstructedDiscordSnowflake {
Expand All @@ -66,16 +66,16 @@ export class DiscordSnowflake {
// https://discord.com/developers/docs/reference#snowflakes-snowflake-id-format-structure-left-to-right
return {
// 42 bits timestamp
timestamp: n((bigSnowflake >> b(22)) + b(EPOCH)),
timestamp: n((bigSnowflake >> 22n) + b(EPOCH)),

// 5 bits worker id
workerId: n((bigSnowflake & b(0x3E0000)) >> b(17)),
workerId: n((bigSnowflake & 0x3E0000n) >> 17n),

// 5 bits process id
processId: n((bigSnowflake & b(0x1F000)) >> b(12)),
processId: n((bigSnowflake & 0x1F000n) >> 12n),

// 12 bits increment, 0xFFF is a max 12 bit integer
increment: n(bigSnowflake & b(0xFFF)),
increment: n(bigSnowflake & 0xFFFn),

get date() {
return new Date(this.timestamp)
Expand Down
Loading

0 comments on commit e72f4a7

Please sign in to comment.