-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for user-installable apps (#782)
* refactor: update discord.js Signed-off-by: Seren_Modz 21 <[email protected]> * fix: correct the ordering of the use external apps permission Signed-off-by: Seren_Modz 21 <[email protected]> * feat: add in compute difference for new fields * chore: failed my own code writing --------- Signed-off-by: Seren_Modz 21 <[email protected]> Co-authored-by: Vlad Frangu <[email protected]>
- Loading branch information
1 parent
40967b3
commit e783074
Showing
9 changed files
with
249 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/lib/utils/application-commands/compute-differences/contexts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { InteractionContextType } from 'discord.js'; | ||
import type { CommandDifference } from './_shared'; | ||
|
||
export function* checkInteractionContextTypes( | ||
existingContexts?: InteractionContextType[], | ||
newContexts?: InteractionContextType[] | ||
): Generator<CommandDifference> { | ||
// 0. No existing contexts and now we have contexts | ||
if (!existingContexts && newContexts?.length) { | ||
yield { | ||
key: 'contexts', | ||
original: 'no contexts present', | ||
expected: 'contexts present' | ||
}; | ||
} | ||
// 1. Existing contexts and now we have no contexts | ||
else if (existingContexts?.length && !newContexts?.length) { | ||
yield { | ||
key: 'contexts', | ||
original: 'contexts present', | ||
expected: 'no contexts present' | ||
}; | ||
} | ||
// 2. Maybe changes in order or additions, log | ||
else if (newContexts?.length) { | ||
let index = 0; | ||
|
||
for (const newContext of newContexts) { | ||
const currentIndex = index++; | ||
|
||
if (existingContexts![currentIndex] !== newContext) { | ||
yield { | ||
key: `contexts[${currentIndex}]`, | ||
original: `contexts type ${existingContexts?.[currentIndex]}`, | ||
expected: `contexts type ${newContext}` | ||
}; | ||
} | ||
} | ||
|
||
if (index < existingContexts!.length) { | ||
let type: InteractionContextType; | ||
|
||
while ((type = existingContexts![index]) !== undefined) { | ||
yield { | ||
key: `contexts[${index}]`, | ||
original: `context ${type} present`, | ||
expected: `no context present` | ||
}; | ||
|
||
index++; | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/lib/utils/application-commands/compute-differences/integration_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { ApplicationIntegrationType } from 'discord.js'; | ||
import type { CommandDifference } from './_shared'; | ||
|
||
export function* checkIntegrationTypes( | ||
existingIntegrationTypes?: ApplicationIntegrationType[], | ||
newIntegrationTypes?: ApplicationIntegrationType[] | ||
): Generator<CommandDifference> { | ||
// 0. No existing integration types and now we have integration types | ||
if (!existingIntegrationTypes?.length && newIntegrationTypes?.length) { | ||
yield { | ||
key: 'integrationTypes', | ||
original: 'no integration types present', | ||
expected: 'integration types present' | ||
}; | ||
} | ||
// 1. Existing integration types and now we have no integration types | ||
else if (existingIntegrationTypes?.length && !newIntegrationTypes?.length) { | ||
yield { | ||
key: 'integrationTypes', | ||
original: 'integration types present', | ||
expected: 'no integration types present' | ||
}; | ||
} | ||
// 2. Maybe changes in order or additions, log | ||
else if (newIntegrationTypes?.length) { | ||
let index = 0; | ||
|
||
for (const newIntegrationType of newIntegrationTypes) { | ||
const currentIndex = index++; | ||
|
||
if (existingIntegrationTypes![currentIndex] !== newIntegrationType) { | ||
yield { | ||
key: `integrationTypes[${currentIndex}]`, | ||
original: `integration type ${existingIntegrationTypes?.[currentIndex]}`, | ||
expected: `integration type ${newIntegrationType}` | ||
}; | ||
} | ||
} | ||
|
||
if (index < existingIntegrationTypes!.length) { | ||
let type: ApplicationIntegrationType; | ||
|
||
while ((type = existingIntegrationTypes![index]) !== undefined) { | ||
yield { | ||
key: `integrationTypes[${index}]`, | ||
original: `integration type ${type} present`, | ||
expected: 'no integration type present' | ||
}; | ||
|
||
index++; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ import { | |
import { | ||
ApplicationCommand, | ||
PermissionsBitField, | ||
type ApplicationIntegrationType, | ||
type ChatInputApplicationCommandData, | ||
type InteractionContextType, | ||
type MessageApplicationCommandData, | ||
type UserApplicationCommandData | ||
} from 'discord.js'; | ||
|
@@ -71,7 +73,9 @@ export function normalizeChatInputCommand( | |
description_localizations: command.descriptionLocalizations, | ||
type: ApplicationCommandType.ChatInput, | ||
dm_permission: command.dmPermission, | ||
nsfw: command.nsfw | ||
nsfw: command.nsfw, | ||
integration_types: command.integrationTypes as ApplicationIntegrationType[] | undefined, | ||
contexts: command.contexts as InteractionContextType[] | undefined | ||
}; | ||
|
||
if (typeof command.defaultMemberPermissions !== 'undefined') { | ||
|
@@ -108,7 +112,9 @@ export function normalizeContextMenuCommand( | |
name_localizations: command.nameLocalizations, | ||
type: command.type, | ||
dm_permission: command.dmPermission, | ||
nsfw: command.nsfw | ||
nsfw: command.nsfw, | ||
integration_types: command.integrationTypes as ApplicationIntegrationType[] | undefined, | ||
contexts: command.contexts as InteractionContextType[] | undefined | ||
}; | ||
|
||
if (typeof command.defaultMemberPermissions !== 'undefined') { | ||
|
@@ -125,7 +131,9 @@ export function convertApplicationCommandToApiData(command: ApplicationCommand): | |
name_localizations: command.nameLocalizations, | ||
dm_permission: command.dmPermission, | ||
Check warning on line 132 in src/lib/utils/application-commands/normalizeInputs.ts GitHub Actions / Linting / Linting / Run yarn job
|
||
nsfw: command.nsfw, | ||
default_member_permissions: command.defaultMemberPermissions?.bitfield.toString() ?? null | ||
default_member_permissions: command.defaultMemberPermissions?.bitfield.toString() ?? null, | ||
integration_types: command.integrationTypes, | ||
contexts: command.contexts | ||
} as RESTPostAPIApplicationCommandsJSONBody; | ||
|
||
if (command.type === ApplicationCommandType.ChatInput) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.