Skip to content

Commit

Permalink
Hello TypeScript (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi authored Apr 19, 2023
1 parent 11fdc17 commit 58a0754
Show file tree
Hide file tree
Showing 26 changed files with 738 additions and 492 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.env*
!.env-example

dist
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ RUN mkdir /pnpm
WORKDIR /package
COPY .npmrc package.json ./
RUN curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=$(cat package.json | jq -r .packageManager | grep -oP '\d+\.\d+\.\d') bash -
COPY pnpm-lock.yaml ./
RUN pnpm i

FROM depender as builder

ENV NODE_ENV="development"
COPY tsconfig.json ./
RUN pnpm i
COPY src/ ./src
RUN pnpm exec tsc

FROM gcr.io/distroless/cc-debian11:nonroot

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /app
COPY --from=depender /pnpm /pnpm
COPY src/ ./src
COPY --from=builder /package/dist/ ./dist
COPY .npmrc package.json ./
COPY --from=depender /package/node_modules ./node_modules
ENTRYPOINT [ "pnpm", "--shell-emulator" ]
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "pow",
"version": "1.0.0",
"main": "src/index.js",
"main": "dist/index.js",
"scripts": {
"deployCommands": "node src/deployGuildCommand.js && node src/deployGlobalCommand.js",
"deployCommands": "node scripts/deployGuildCommand.js && node scripts/deployGlobalCommand.js",
"start": "node .",
"dev": "tsc && node -r dotenv/config .",
"format": "prettier --write .",
"lint": "prettier --check .",
"prepare": "husky install || [ $? = 127 ]"
Expand All @@ -17,21 +18,25 @@
"@discordjs/collection": "1.5.0",
"@discordjs/rest": "1.7.0",
"@discordjs/voice": "0.16.0",
"@sapphire/framework": "4.4.1",
"axios": "1.3.5",
"debug": "4.3.4",
"discord-emoji": "2.2.0",
"discord.js": "14.9.0",
"dotenv": "16.0.3",
"emoji-regex": "10.2.1",
"ffmpeg-static": "5.1.0",
"libsodium-wrappers": "0.7.11",
"mariadb": "3.1.1"
},
"devDependencies": {
"@types/node": "18.15.11",
"dotenv": "16.0.3",
"husky": "8.0.3",
"prettier": "2.8.7"
"prettier": "2.8.7",
"typescript": "5.0.4"
},
"author": "kazukazu123123",
"license": "MIT",
"description": ""
"description": "",
"type": "module"
}
101 changes: 96 additions & 5 deletions pnpm-lock.yaml

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

39 changes: 28 additions & 11 deletions src/commands/join.js → src/commands/join.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
// @ts-check
const { SlashCommandBuilder } = require('discord.js')
const voiceRead = require('../voiceRead')
import { Command, type ChatInputCommand } from '@sapphire/framework'
import { guildCtxManager } from '../index.js'

module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('ボイスチャンネルに参加します。')
.setDMPermission(false),
export class JoinCommand extends Command {
public constructor(
context: ChatInputCommand.Context,
options: ChatInputCommand.Options,
) {
super(context, {
...options,
description: 'ボイスチャンネルに参加します。',
})
}

async execute(interaction) {
public override registerApplicationCommands(
registry: ChatInputCommand.Registry,
) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.setDMPermission(false),
)
}
public override async chatInputRun(
interaction: ChatInputCommand.Interaction,
) {
if (!interaction.inCachedGuild()) return
const user = await interaction.member.fetch()
if (!user.voice.channel) {
return interaction.reply({
Expand All @@ -23,7 +40,7 @@ module.exports = {
})
}

const ctx = voiceRead.guilds.get(interaction.member.guild)
const ctx = guildCtxManager.get(interaction.member.guild)

if (ctx.isJoined()) {
return interaction.reply({
Expand Down Expand Up @@ -54,5 +71,5 @@ module.exports = {
},
],
})
},
}
}
38 changes: 0 additions & 38 deletions src/commands/leave.js

This file was deleted.

55 changes: 55 additions & 0 deletions src/commands/leave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Command, type ChatInputCommand } from '@sapphire/framework'
import { guildCtxManager } from '../index.js'

export class JoinCommand extends Command {
public constructor(
context: ChatInputCommand.Context,
options: ChatInputCommand.Options,
) {
super(context, {
...options,
description: 'ボイスチャンネルから退出します。',
})
}

public override registerApplicationCommands(
registry: ChatInputCommand.Registry,
) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.setDMPermission(false),
)
}
public override async chatInputRun(
interaction: ChatInputCommand.Interaction,
) {
if (!interaction.inCachedGuild()) return
const ctx = guildCtxManager.get(interaction.member.guild)
if (!ctx.isJoined()) {
return interaction.reply({
embeds: [
{
color: 0xff0000,
title: 'エラー',
description: 'BOTがVCに参加している必要があります。',
},
],
ephemeral: true,
})
}

await ctx.leave()

return interaction.reply({
embeds: [
{
color: 0x00ff00,
title: 'ボイスチャンネルから退出しました。',
description: 'またのご利用をお待ちしております。',
},
],
})
}
}
Loading

0 comments on commit 58a0754

Please sign in to comment.