Skip to content

Commit

Permalink
feat: add support for user-installable apps (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeadTriXz committed Jul 19, 2024
1 parent b1294a5 commit fd32287
Show file tree
Hide file tree
Showing 43 changed files with 388 additions and 151 deletions.
6 changes: 3 additions & 3 deletions apps/barry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"dependencies": {
"@barry-bot/core": "*",
"@discordjs/core": "^1.1.1",
"@discordjs/rest": "^2.2.0",
"@discordjs/ws": "^1.0.2",
"@discordjs/core": "^1.3.0-dev.1721153953-efa16a609",
"@discordjs/rest": "^2.3.0",
"@discordjs/ws": "^1.2.0-dev.1721153959-efa16a609",
"@napi-rs/canvas": "^0.1.41",
"@prisma/client": "^5.0.0",
"canvas-constructor": "^7.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from "@barry-bot/core";
import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType, MessageFlags } from "@discordjs/core";
import { Canvas } from "canvas-constructor/napi-rs";
import { MessageFlags } from "@discordjs/core";
import { parseColor } from "../../../functions/colors.js";
import config from "../../../../../config.js";

Expand All @@ -33,6 +33,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "color",
description: "Shows information about a color.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
color: SlashCommandOptionBuilder.string({
description: "The color to show information about.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type APIEmbedFooter,
type APISelectMenuOption,
ComponentType,
InteractionContextType,
MessageFlags,
PermissionFlagsBits
} from "@discordjs/core";
Expand Down Expand Up @@ -51,8 +52,8 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "config",
description: "Manage the configuration of the bot for this server.",
defaultMemberPermissions: PermissionFlagsBits.ManageGuild,
guildOnly: true
contexts: [InteractionContextType.Guild],
defaultMemberPermissions: PermissionFlagsBits.ManageGuild
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from "@barry-bot/core";
import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType, MessageFlags } from "@discordjs/core";
import { Canvas, loadFont } from "canvas-constructor/napi-rs";
import { getContrastScore, parseColor } from "../../../functions/colors.js";
import { MessageFlags } from "@discordjs/core";
import { join } from "node:path";
import config from "../../../../../config.js";

Expand Down Expand Up @@ -52,6 +52,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "contrast",
description: "Check the contrast between two colors.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
background: SlashCommandOptionBuilder.string({
description: "The background color.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { type APIApplicationCommandOptionChoice, MessageFlags } from "@discordjs/core";
import { type ApplicationCommandInteraction, SlashCommand, SlashCommandOptionBuilder } from "@barry-bot/core";
import {
type APIApplicationCommandOptionChoice,
ApplicationIntegrationType,
MessageFlags
} from "@discordjs/core";
import {
type ApplicationCommandInteraction,
SlashCommand,
SlashCommandOptionBuilder
} from "@barry-bot/core";
import type GeneralModule from "../../../../index.js";

import { fetch } from "undici";
Expand Down Expand Up @@ -137,6 +145,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "currency",
description: "Converts currency from one to another.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
amount: SlashCommandOptionBuilder.number({
description: "The amount to convert.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType } from "@discordjs/core";
import { SlashCommand } from "@barry-bot/core";
import ConvertCurrencyCommand from "./currency/index.js";
import ConvertUnitCommand from "./unit/index.js";
Expand All @@ -17,6 +18,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "convert",
description: "Converts one unit to another.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
children: [
ConvertCurrencyCommand,
ConvertUnitCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type APIApplicationCommandOptionChoice, MessageFlags } from "@discordjs/core";
import {
type APIApplicationCommandOptionChoice,
ApplicationIntegrationType,
MessageFlags
} from "@discordjs/core";
import {
type ApplicationCommandInteraction,
type AutocompleteInteraction,
Expand Down Expand Up @@ -63,6 +67,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "unit",
description: "Converts one unit to another.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
amount: SlashCommandOptionBuilder.number({
description: "The amount to convert.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@barry-bot/core";
import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType } from "@discordjs/core";
import {
generateParagraphs,
generateSentences,
Expand Down Expand Up @@ -45,6 +46,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "lipsum",
description: "Lorem ipsum dolor sit amet.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
words: SlashCommandOptionBuilder.integer({
description: "The amount of words to generate.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
SlashCommand,
getCreatedAt
} from "@barry-bot/core";

import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType } from "@discordjs/core";
import config from "../../../../../config.js";

/**
Expand All @@ -19,7 +20,8 @@ export default class extends SlashCommand<GeneralModule> {
constructor(module: GeneralModule) {
super(module, {
name: "ping",
description: "Shows the latency of the bot."
description: "Shows the latency of the bot.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall]
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
SlashCommand,
SlashCommandOptionBuilder
} from "@barry-bot/core";
import { type APIAttachment, MessageFlags } from "@discordjs/core";
import {
type APIAttachment,
ApplicationIntegrationType,
MessageFlags
} from "@discordjs/core";
import type GeneralModule from "../../../../index.js";

import { getReverseContent } from "../../../../functions/reverse/getReverseContent.js";
Expand All @@ -22,6 +26,7 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "image",
description: "Reverse search an image.",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
options: {
image: SlashCommandOptionBuilder.attachments({
description: "The image to reverse search.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType } from "@discordjs/core";
import { SlashCommand } from "@barry-bot/core";
import ReverseImageCommand from "./image/index.js";

Expand All @@ -16,7 +17,8 @@ export default class extends SlashCommand<GeneralModule> {
super(module, {
name: "reverse",
description: "Reverse search an image.",
children: [ReverseImageCommand]
children: [ReverseImageCommand],
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall]
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import type GeneralModule from "../../../index.js";

import { MessageFlags } from "@discordjs/core";
import { ApplicationIntegrationType, MessageFlags } from "@discordjs/core";
import { PaginationMessage } from "../../../../../utils/pagination.js";
import { getReverseContent } from "../../../functions/reverse/getReverseContent.js";

Expand All @@ -23,7 +23,8 @@ export default class extends MessageCommand<GeneralModule> {
*/
constructor(module: GeneralModule) {
super(module, {
name: "Reverse Search Image"
name: "Reverse Search Image",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall]
});
}

Expand Down
6 changes: 4 additions & 2 deletions apps/barry/src/modules/general/commands/user/avatar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {
UserCommand,
getDefaultAvatarURL
} from "@barry-bot/core";

import type GeneralModule from "../../../index.js";

import { ApplicationIntegrationType } from "@discordjs/core";
import config from "../../../../../config.js";

/**
Expand All @@ -19,7 +20,8 @@ export default class extends UserCommand<GeneralModule> {
*/
constructor(module: GeneralModule) {
super(module, {
name: "View Avatar"
name: "View Avatar",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall]
});
}

Expand Down
5 changes: 3 additions & 2 deletions apps/barry/src/modules/general/commands/user/reverse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import type GeneralModule from "../../../index.js";

import { MessageFlags } from "@discordjs/core";
import { ApplicationIntegrationType, MessageFlags } from "@discordjs/core";
import { getReverseAvatarContent } from "../../../functions/reverse/getReverseContent.js";

import config from "../../../../../config.js";
Expand All @@ -22,7 +22,8 @@ export default class extends UserCommand<GeneralModule> {
*/
constructor(module: GeneralModule) {
super(module, {
name: "Reverse Search Avatar"
name: "Reverse Search Avatar",
integrationTypes: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall]
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type APIButtonComponentWithCustomId,
ButtonStyle,
ComponentType,
InteractionContextType,
MessageFlags,
TextInputStyle
} from "@discordjs/core";
Expand Down Expand Up @@ -69,7 +70,7 @@ export default class extends SlashCommand<LevelingModule> {
super(module, {
name: "leaderboard",
description: "View the most active members of this server.",
guildOnly: true
contexts: [InteractionContextType.Guild]
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "@barry-bot/core";
import type LevelingModule from "../../../index.js";

import { InteractionContextType } from "@discordjs/core";
import { viewRank } from "../../../functions/viewRank.js";

/**
Expand All @@ -21,7 +22,7 @@ export default class extends SlashCommand<LevelingModule> {
super(module, {
name: "rank",
description: "View someone's rank card.",
guildOnly: true,
contexts: [InteractionContextType.Guild],
options: {
user: SlashCommandOptionBuilder.user({
description: "The user to view the rank card of.",
Expand Down
3 changes: 2 additions & 1 deletion apps/barry/src/modules/leveling/commands/user/rank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@barry-bot/core";
import type LevelingModule from "../../../index.js";

import { InteractionContextType } from "@discordjs/core";
import { viewRank } from "../../../functions/viewRank.js";

/**
Expand All @@ -19,7 +20,7 @@ export default class extends UserCommand<LevelingModule> {
constructor(module: LevelingModule) {
super(module, {
name: "View Rank",
guildOnly: true
contexts: [InteractionContextType.Guild]
});
}

Expand Down
6 changes: 3 additions & 3 deletions apps/barry/src/modules/leveling/commands/user/rep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "@barry-bot/core";
import type LevelingModule from "../../../index.js";

import { MessageFlags } from "@discordjs/core";
import { InteractionContextType, MessageFlags } from "@discordjs/core";
import config from "../../../../../config.js";

/**
Expand All @@ -20,8 +20,8 @@ export default class extends UserCommand<LevelingModule> {
constructor(module: LevelingModule) {
super(module, {
name: "Give Reputation",
cooldown: 86400,
guildOnly: true
contexts: [InteractionContextType.Guild],
cooldown: 86400
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import type { BanOptions } from "../../../../../types/moderation.js";
import type ModerationModule from "../../../index.js";

import { InteractionContextType, PermissionFlagsBits } from "@discordjs/core";
import { COMMON_SEVERE_REASONS } from "../../../constants.js";
import { PermissionFlagsBits } from "@discordjs/core";

/**
* Represents a slash command that bans a user.
Expand All @@ -23,8 +23,8 @@ export default class extends SlashCommand<ModerationModule> {
name: "ban",
description: "Ban a user from the server.",
appPermissions: PermissionFlagsBits.BanMembers,
contexts: [InteractionContextType.Guild],
defaultMemberPermissions: PermissionFlagsBits.BanMembers,
guildOnly: true,
options: {
user: SlashCommandOptionBuilder.user({
description: "The user to ban.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type ModerationModule from "../../../../index.js";
import {
ButtonStyle,
ComponentType,
InteractionContextType,
MessageFlags,
PermissionFlagsBits
} from "@discordjs/core";
Expand Down Expand Up @@ -37,8 +38,8 @@ export default class extends SlashCommand<ModerationModule> {
super(module, {
name: "delete",
description: "Delete a specific case.",
contexts: [InteractionContextType.Guild],
defaultMemberPermissions: PermissionFlagsBits.ModerateMembers,
guildOnly: true,
options: {
case: SlashCommandOptionBuilder.integer({
description: "The ID of the case to delete.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type ModerationModule from "../../../index.js";

import { InteractionContextType } from "@discordjs/core";
import { SlashCommand } from "@barry-bot/core";
import DeleteCommand from "./delete/index.js";
import NoteCommand from "./notes/index.js";
Expand All @@ -18,7 +19,7 @@ export default class extends SlashCommand<ModerationModule> {
super(module, {
name: "cases",
description: "Manage or view a case.",
guildOnly: true,
contexts: [InteractionContextType.Guild],
children: [
DeleteCommand,
NoteCommand,
Expand Down
Loading

0 comments on commit fd32287

Please sign in to comment.