Skip to content

Commit

Permalink
feat: add user contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 6, 2024
1 parent 6c86208 commit fe6b75a
Show file tree
Hide file tree
Showing 37 changed files with 101 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bugs": {
"url": "https://github.com/trello-talk/TacoInteraction/issues"
},
"homepage": "https:/tacobot.app/",
"homepage": "https://tacobot.app/",
"private": true,
"scripts": {
"start": "cd dist && node index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from '@prisma/client';
import { AxiosResponse } from 'axios';
import fuzzy from 'fuzzy';
import { AutocompleteContext, CommandContext, SlashCommand } from 'slash-create';
import { ApplicationIntegrationType, AutocompleteContext, CommandContext, InteractionContextType, SlashCommand } from 'slash-create';

import {
getBoardTextLabel,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCommand, SlashCreator } from 'slash-create';

import { getData } from '../util';
import { defaultContexts, getData } from '../util';
import { REPOSITORY } from '../util/constants';

export default class BotCommand extends SlashCommand {
Expand All @@ -9,6 +9,7 @@ export default class BotCommand extends SlashCommand {
name: 'bot',
description: 'Bot-related information.',
deferEphemeral: true,
...defaultContexts,
options: [
{
type: CommandOptionType.SUB_COMMAND,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/create/add-attachment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AutocompleteContext, ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { getBoard } from '../../util/api';

export default class CommentCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'add-attachment',
description: 'Add an attachment to a card.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/create/add-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, CommandContext, CommandOptionType, ComponentType, SlashCreator, TextInputStyle } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse } from '../../util';
import { defaultContexts, getData, noAuthResponse } from '../../util';
import { ActionType } from '../../util/actions';
import { getBoard } from '../../util/api';

Expand All @@ -10,6 +10,7 @@ export default class AddCardCommand extends SlashCommand {
super(creator, {
name: 'add-card',
description: 'Create a card on your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/create/add-label.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { getBoard, uncacheBoard } from '../../util/api';
import { LABEL_EMOJIS } from '../../util/constants';

Expand All @@ -10,6 +10,7 @@ export default class AddLabelCommand extends SlashCommand {
super(creator, {
name: 'add-label',
description: 'Create a label on your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/create/add-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { getBoard, uncacheBoard } from '../../util/api';

// TODO add position option (left, right)
Expand All @@ -10,6 +10,7 @@ export default class AddListCommand extends SlashCommand {
super(creator, {
name: 'add-list',
description: 'Create a list on your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/create/comment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AutocompleteContext, ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { getBoard } from '../../util/api';

export default class CommentCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'comment',
description: 'Comment on a card.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/delete/delete-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { ActionType } from '../../util/actions';
import { getBoard } from '../../util/api';

Expand All @@ -10,6 +10,7 @@ export default class DeleteCardCommand extends SlashCommand {
super(creator, {
name: 'delete-card',
description: 'Delete a card from your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/delete/delete-label.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../../util';
import { ActionType } from '../../util/actions';
import { getBoard } from '../../util/api';
import { LABEL_EMOJIS } from '../../util/constants';
Expand All @@ -11,6 +11,7 @@ export default class DeleteLabelCommand extends SlashCommand {
super(creator, {
name: 'delete-label',
description: 'Delete a label from your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
5 changes: 3 additions & 2 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create';
import { ApplicationIntegrationType, CommandContext, CommandOptionType, InteractionContextType, SlashCommand, SlashCreator } from 'slash-create';

import { stripIndentsAndNewlines } from '../util';
import { prisma } from '../util/prisma';
Expand All @@ -10,7 +10,8 @@ export default class BotCommand extends SlashCommand {
description: 'Dev stuff.',
deferEphemeral: true,
guildIDs: [process.env.DEV_GUILD],
dmPermission: false,
contexts: [InteractionContextType.GUILD],
integrationTypes: [ApplicationIntegrationType.GUILD_INSTALL],
requiredPermissions: [],
options: [
{
Expand Down
3 changes: 2 additions & 1 deletion src/commands/edit/edit-board.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AutocompleteContext, ButtonStyle, CommandContext, CommandOptionType, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { getBoard, getMember, uncacheBoard, uncacheMember } from '../../util/api';

export default class EditBoardCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'edit-board',
description: 'Edit a board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/edit/edit-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { ActionType, createAction } from '../../util/actions';
import { getBoard, getCard, uncacheBoard, uncacheCard } from '../../util/api';
import { LABEL_EMOJIS } from '../../util/constants';
Expand All @@ -12,6 +12,7 @@ export default class EditCardCommand extends SlashCommand {
super(creator, {
name: 'edit-card',
description: 'Edit a card from your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.SUB_COMMAND,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/edit/edit-label.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { getBoard, uncacheBoard } from '../../util/api';
import { LABEL_EMOJIS } from '../../util/constants';

Expand All @@ -10,6 +10,7 @@ export default class EditLabelCommand extends SlashCommand {
super(creator, {
name: 'edit-label',
description: 'Edit a label from your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/edit/edit-list.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AutocompleteContext, CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, stripIndentsAndNewlines, truncate } from '../../util';
import { getBoard, uncacheBoard } from '../../util/api';

export default class EditListCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'edit-list',
description: 'Edit a list from your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/links/auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ButtonStyle, CommandContext, ComponentType, SlashCommand, SlashCreator } from 'slash-create';

import { getData } from '../../util';
import { defaultContexts, getData } from '../../util';

export default class AuthCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'auth',
description: 'Sends a link to authenticate to Trello.',
...defaultContexts,
deferEphemeral: true
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/list/boards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { getMember } from '../../util/api';
import { formatNumber } from '../../util/locale';
import { createListPrompt } from '../../util/prompt';
Expand All @@ -19,6 +19,7 @@ export default class BoardsCommand extends SlashCommand {
super(creator, {
name: 'boards',
description: 'List Trello boards.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/list/cards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { getBoard } from '../../util/api';
import { formatNumber } from '../../util/locale';
import { createListPrompt } from '../../util/prompt';
Expand All @@ -21,6 +21,7 @@ export default class CardsCommand extends SlashCommand {
super(creator, {
name: 'cards',
description: 'List Trello cards on your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/list/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { oneLine } from 'common-tags';
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { getBoard } from '../../util/api';
import { LABEL_EMOJIS } from '../../util/constants';
import { formatNumber } from '../../util/locale';
Expand All @@ -18,6 +18,7 @@ export default class LabelsCommand extends SlashCommand {
super(creator, {
name: 'labels',
description: 'List Trello labels in the selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/list/lists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { defaultContexts, getData, noAuthResponse, splitMessage, truncate } from '../../util';
import { getBoard } from '../../util/api';
import { formatNumber } from '../../util/locale';
import { createListPrompt } from '../../util/prompt';
Expand All @@ -18,6 +18,7 @@ export default class ListsCommand extends SlashCommand {
super(creator, {
name: 'lists',
description: 'List Trello lists on your selected board.',
...defaultContexts,
options: [
{
type: CommandOptionType.STRING,
Expand Down
6 changes: 4 additions & 2 deletions src/commands/me.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { CommandContext, MessageEmbedOptions, SlashCreator } from 'slash-create';

import SlashCommand from '../command';
import { getData, noAuthResponse, truncate } from '../util';
import { defaultContexts, getData, noAuthResponse, truncate } from '../util';
import { getMember } from '../util/api';

export default class MeCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'me',
description: 'Get your own Trello user information.',
deferEphemeral: true
deferEphemeral: true,
...defaultContexts
});
}

async run(ctx: CommandContext) {
console.log(ctx.authorizingIntegrationOwners)
const { userData, t } = await getData(ctx);
if (!userData || !userData.trelloToken) return noAuthResponse(t);

Expand Down
5 changes: 3 additions & 2 deletions src/commands/server-settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutocompleteContext, CommandContext, CommandOptionType, SlashCreator } from 'slash-create';
import { ApplicationIntegrationType, AutocompleteContext, CommandContext, CommandOptionType, InteractionContextType, SlashCreator } from 'slash-create';

import SlashCommand from '../command';
import { getData } from '../util';
Expand All @@ -10,7 +10,8 @@ export default class ServerSettingsCommand extends SlashCommand {
super(creator, {
name: 'server-settings',
description: 'Edit server settings.',
dmPermission: false,
contexts: [InteractionContextType.GUILD],
integrationTypes: [ApplicationIntegrationType.GUILD_INSTALL],
options: [
{
type: CommandOptionType.SUB_COMMAND,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/user-settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AutocompleteContext, CommandContext, CommandOptionType, SlashCreator } from 'slash-create';

import SlashCommand from '../command';
import { getData } from '../util';
import { defaultContexts, getData } from '../util';
import { createT, langs } from '../util/locale';
import { prisma } from '../util/prisma';

Expand All @@ -11,6 +11,7 @@ export default class UserSettingsCommand extends SlashCommand {
name: 'user-settings',
description: 'Edit user settings.',
deferEphemeral: true,
...defaultContexts,
options: [
{
type: CommandOptionType.SUB_COMMAND,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/user/clearauth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ButtonStyle, CommandContext, ComponentType, SlashCreator } from 'slash-create';

import SlashCommand from '../../command';
import { getData } from '../../util';
import { defaultContexts, getData } from '../../util';
import { ActionType } from '../../util/actions';

export default class ClearAuthCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'clear-auth',
description: 'Remove your authentication data.',
...defaultContexts,
deferEphemeral: true
});
}
Expand Down
Loading

0 comments on commit fe6b75a

Please sign in to comment.