Skip to content

Commit

Permalink
chore: more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Oct 10, 2023
1 parent cbdd46f commit ab73221
Show file tree
Hide file tree
Showing 27 changed files with 934 additions and 915 deletions.
786 changes: 0 additions & 786 deletions .yarn/releases/yarn-3.2.1.cjs

This file was deleted.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'

yarnPath: .yarn/releases/yarn-3.2.1.cjs
yarnPath: .yarn/releases/yarn-3.6.4.cjs
9 changes: 1 addition & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ services:
- ./logs:/usr/ama/logs
depends_on:
- postgres
command:
[
'node',
'--es-module-specifier-resolution=node',
'--enable-source-maps',
'--no-warnings',
'./packages/bot/dist/index.js',
]
command: ['node', '--enable-source-maps', '--no-warnings', './packages/bot/dist/index.js']

volumes:
postgres-data:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chatsift/ama",
"description": "Manage AMAs in your community",
"packageManager": "yarn@3.2.1",
"packageManager": "yarn@3.6.4",
"private": true,
"version": "0.0.0",
"workspaces": [
Expand All @@ -24,9 +24,9 @@
"build": "turbo run build",
"format": "prettier --write .",
"prisma": "dotenv -e .env prisma",
"deploy-commands": "yarn build && dotenv -e .env -v DEPLOY=true -- node --es-module-specifier-resolution=node --enable-source-maps ./packages/bot/dist/index.js",
"start-bot": "dotenv -e .env -- node --es-module-specifier-resolution=node --enable-source-maps ./packages/bot/dist/index.js",
"start-api": "dotenv -e .env -- node --es-module-specifier-resolution=node --enable-source-maps ./packages/api/dist/index.js",
"deploy-commands": "yarn build && dotenv -e .env -v DEPLOY=true -- node --enable-source-maps ./packages/bot/dist/index.js",
"start-bot": "dotenv -e .env -- node --enable-source-maps ./packages/bot/dist/index.js",
"start-api": "dotenv -e .env -- node --enable-source-maps ./packages/api/dist/index.js",
"prepare": "is-ci || husky install",
"update": "yarn upgrade-interactive"
},
Expand Down
1 change: 0 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"devDependencies": {
"@types/cors": "^2.8.14",
"@types/node": "^20.8.4",
"@types/pino": "^7.0.5",
"prisma": "^5.4.2",
"typescript": "^5.2.2"
},
Expand Down
1 change: 0 additions & 1 deletion packages/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@types/common-tags": "^1.8.2",
"@types/node": "^20.8.4",
"@types/pino": "^7.0.5",
"prisma": "^5.4.2",
"typescript": "^5.2.2"
},
Expand Down
9 changes: 4 additions & 5 deletions packages/bot/src/commands/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
type ChatInputCommandInteraction,
} from 'discord.js';
import { singleton } from 'tsyringe';
import { AmaManager } from '#struct/AmaManager';
import type { CommandBody, Command } from '#struct/Command';
import type { SelectMenuPaginatorConsumers } from '#struct/SelectMenuPaginator';
import { SelectMenuPaginator } from '#struct/SelectMenuPaginator';
import { GracefulTransactionFailure } from '../struct/GracefulTransactionError';
import { AmaManager } from '../struct/AmaManager.js';
import type { Command, CommandBody } from '../struct/Command.js';
import { GracefulTransactionFailure } from '../struct/GracefulTransactionError.js';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '../struct/SelectMenuPaginator.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
5 changes: 2 additions & 3 deletions packages/bot/src/commands/end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
type ChatInputCommandInteraction,
} from 'discord.js';
import { singleton } from 'tsyringe';
import type { CommandBody, Command } from '#struct/Command';
import type { SelectMenuPaginatorConsumers } from '#struct/SelectMenuPaginator';
import { SelectMenuPaginator } from '#struct/SelectMenuPaginator';
import type { Command, CommandBody } from '../struct/Command';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '../struct/SelectMenuPaginator';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
22 changes: 5 additions & 17 deletions packages/bot/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
} from 'discord.js';
import { nanoid } from 'nanoid';
import { singleton } from 'tsyringe';
import type { CommandBody, Command } from '#struct/Command';
import { Colors } from '#util/colors';
import type { Command, CommandBody } from '../struct/Command';
import { Colors } from '../util/colors';

const allowedChannelTypes: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[] = [
ChannelType.GuildText,
ChannelType.GuildNewsThread,
ChannelType.GuildPublicThread,
ChannelType.GuildPrivateThread,
ChannelType.AnnouncementThread,
ChannelType.PublicThread,
ChannelType.PrivateThread,
];

@singleton()
Expand Down Expand Up @@ -60,11 +60,6 @@ export default class implements Command<ApplicationCommandType.ChatInput> {
type: ApplicationCommandOptionType.Channel,
channel_types: allowedChannelTypes,
},
{
name: 'stage-only',
description: 'Whether this is a stage only AMA - only available when none of the optional queues are specified',
type: ApplicationCommandOptionType.Boolean,
},
],
};

Expand All @@ -75,12 +70,6 @@ export default class implements Command<ApplicationCommandType.ChatInput> {
const flaggedQueue = interaction.options.getChannel('flagged-queue')?.id;
const guestQueue = interaction.options.getChannel('guest-queue')?.id;
const answersChannel = interaction.options.getChannel('answers-channel', true).id;
const stageOnly = interaction.options.getBoolean('stage-only') ?? false;

if (stageOnly && (modQueue || flaggedQueue || guestQueue)) {
await interaction.reply('You cannot specify a stage only AMA with any of the optional queues');
return;
}

if (!modQueue && flaggedQueue) {
await interaction.reply('You cannot specify a flagged queue without a mod queue');
Expand Down Expand Up @@ -175,7 +164,6 @@ export default class implements Command<ApplicationCommandType.ChatInput> {
guestQueue,
title,
answersChannel,
stageOnly,
promptChannelId: interaction.channel!.id,
promptMessageId: promptMessage.id,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/components/guest-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PrismaClient } from '@prisma/client';
import type { ButtonInteraction } from 'discord.js';
import { Client } from 'discord.js';
import { singleton } from 'tsyringe';
import { AmaManager } from '#struct/AmaManager';
import type { Component } from '#struct/Component';
import { Colors } from '#util/colors';
import { AmaManager } from '../struct/AmaManager.js';
import type { Component } from '../struct/Component.js';
import { Colors } from '../util/colors.js';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/components/guest-deny.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaClient } from '@prisma/client';
import type { ButtonInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Component } from '#struct/Component';
import { Colors } from '#util/colors';
import type { Component } from '../struct/Component.js';
import { Colors } from '../util/colors.js';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/components/mod-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PrismaClient } from '@prisma/client';
import type { ButtonInteraction } from 'discord.js';
import { Client } from 'discord.js';
import { singleton } from 'tsyringe';
import { AmaManager } from '#struct/AmaManager';
import type { Component } from '#struct/Component';
import { Colors } from '#util/colors';
import { AmaManager } from '../struct/AmaManager.js';
import type { Component } from '../struct/Component.js';
import { Colors } from '../util/colors.js';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/components/mod-deny.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaClient } from '@prisma/client';
import type { ButtonInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Component } from '#struct/Component';
import { Colors } from '#util/colors';
import type { Component } from '../struct/Component';
import { Colors } from '../util/colors';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/components/mod-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PrismaClient } from '@prisma/client';
import type { ButtonInteraction } from 'discord.js';
import { Client } from 'discord.js';
import { singleton } from 'tsyringe';
import { AmaManager } from '#struct/AmaManager';
import type { Component } from '#struct/Component';
import { Colors } from '#util/colors';
import { AmaManager } from '../struct/AmaManager';
import type { Component } from '../struct/Component';
import { Colors } from '../util/colors';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/components/submit-question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ModalActionRowComponentBuilder, ButtonInteraction } from 'discord.
import { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
import { nanoid } from 'nanoid';
import { singleton } from 'tsyringe';
import { AmaManager } from '#struct/AmaManager';
import type { Component } from '#struct/Component';
import { GracefulTransactionFailure } from '#struct/GracefulTransactionError';
import { AmaManager } from '../struct/AmaManager';
import type { Component } from '../struct/Component';
import { GracefulTransactionFailure } from '../struct/GracefulTransactionError';

@singleton()
export default class implements Component<ButtonInteraction<'cached'>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { container } from 'tsyringe';
import { CommandHandler } from '#struct/CommandHandler';
import { CommandHandler } from './struct/CommandHandler';

export async function deploySlashCommands(): Promise<void> {
const commandHandler = container.resolve(CommandHandler);
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/events/error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Events } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Event } from '#struct/Event';
import { logger } from '#util/logger';
import type { Event } from '../struct/Event';
import { logger } from '../util/logger';

@singleton()
export default class implements Event<typeof Events.Error> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Interaction } from 'discord.js';
import { Events, InteractionType } from 'discord.js';
import { singleton } from 'tsyringe';
import { CommandHandler } from '#struct/CommandHandler';
import type { Event } from '#struct/Event';
import { logger } from '#util/logger';
import { CommandHandler } from '../struct/CommandHandler';
import type { Event } from '../struct/Event';
import { logger } from '../util/logger';

@singleton()
export default class implements Event<typeof Events.InteractionCreate> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Client } from 'discord.js';
import { Events } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Event } from '#struct/Event';
import { logger } from '#util/logger';
import type { Event } from '../struct/Event';
import { logger } from '../util/logger';

@singleton()
export default class implements Event<typeof Events.ClientReady> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import process from 'node:process';
import { PrismaClient } from '@prisma/client';
import { Client, IntentsBitField, Options, Partials } from 'discord.js';
import { container } from 'tsyringe';
import { CommandHandler } from '#struct/CommandHandler';
import { Env } from '#struct/Env';
import { EventHandler } from '#struct/EventHandler';
import { deploySlashCommands } from './deploy';
import { CommandHandler } from './struct/CommandHandler';
import { Env } from './struct/Env';
import { EventHandler } from './struct/EventHandler';

const env = container.resolve(Env);

Expand Down
22 changes: 7 additions & 15 deletions packages/bot/src/struct/AmaManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { AmaQuestion } from '@prisma/client';
import { PrismaClient } from '@prisma/client';
import { Result } from '@sapphire/result';
import type { MessageActionRowComponentBuilder, TextChannel, User } from 'discord.js';
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle, Client } from 'discord.js';
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle, Client, Colors } from 'discord.js';
import { singleton } from 'tsyringe';
import { Colors } from '#util/colors';

export type EmbedData = {
content: string;
Expand All @@ -31,15 +29,15 @@ export type PostToGuestQueueData = PostData & {

export type PostToAnswerChannelData = PostData & {
answersChannel: string;
/**
* @deprecated We no longer distinguish between stage and non-stage answers/AMAs
*/
stage: boolean;
};

@singleton()
export class AmaManager {
public constructor(
private readonly prisma: PrismaClient,
private readonly client: Client,
) {}
public constructor(private readonly client: Client) {}

private getBaseEmbed({ content, imageUrl, user }: EmbedData): EmbedBuilder {
return new EmbedBuilder()
Expand Down Expand Up @@ -110,14 +108,7 @@ export class AmaManager {
...embedData
}: PostToGuestQueueData): Promise<Result<unknown, Error>> {
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ButtonBuilder()
.setLabel('Stage')
.setStyle(ButtonStyle.Success)
.setCustomId(`guest-approve|${question.id}|stage`),
new ButtonBuilder()
.setLabel('Text')
.setStyle(ButtonStyle.Success)
.setCustomId(`guest-approve|${question.id}|text`),
new ButtonBuilder().setLabel('Answer').setStyle(ButtonStyle.Success).setCustomId(`guest-approve|${question.id}`),
new ButtonBuilder().setLabel('Skip').setStyle(ButtonStyle.Danger).setCustomId(`guest-deny|${question.id}`),
);

Expand All @@ -144,6 +135,7 @@ export class AmaManager {
const embed = this.getBaseEmbed(embedData);
embed.setColor(Colors.Blurple);

// This is deprecated
if (stage) {
embed.setFooter({ text: 'This question was answered via stage' });
}
Expand Down
9 changes: 4 additions & 5 deletions packages/bot/src/struct/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { REST } from '@discordjs/rest';
import type { AutocompleteInteraction, CommandInteraction, MessageComponentInteraction } from 'discord.js';
import { inlineCode, Routes } from 'discord.js';
import { container, singleton } from 'tsyringe';
import type { Command, CommandConstructor } from '#struct/Command';
import type { Component, ComponentConstructor } from '#struct/Component';
import { getComponentInfo } from '#struct/Component';
import { Env } from '#struct/Env';
import { logger } from '#util/logger';
import { logger } from '../util/logger.js';
import type { Command, CommandConstructor } from './Command.js';
import { getComponentInfo, type ComponentConstructor, type Component } from './Component.js';
import { Env } from './Env.js';

@singleton()
export class CommandHandler {
Expand Down
3 changes: 1 addition & 2 deletions packages/bot/src/struct/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { readdirRecurse } from '@chatsift/readdir';
import type { ClientEvents } from 'discord.js';
import { Client } from 'discord.js';
import { container, singleton } from 'tsyringe';
import type { EventConstructor } from '#struct/Event';
import { getEventInfo } from '#struct/Event';
import { getEventInfo, type EventConstructor } from './Event.js';

@singleton()
export class EventHandler {
Expand Down
6 changes: 1 addition & 5 deletions packages/bot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"paths": {
"#struct/*": ["./src/struct/*.ts"],
"#util/*": ["./src/util/*.ts"]
}
"outDir": "./dist"
},
"include": ["./src/**/*.ts"],
"exclude": ["./**/__tests__"]
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model Ama {
answersChannel String
promptChannelId String
promptMessageId String @unique
stageOnly Boolean
stageOnly Boolean @default(false) // deprecated, hence the defualt.
ended Boolean @default(false)
questions AmaQuestion[]
Expand Down
Loading

0 comments on commit ab73221

Please sign in to comment.