Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
fix #24 関数がstatusを返す必要がないように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
yogarasu committed Aug 19, 2022
1 parent 39ade63 commit 99e8084
Show file tree
Hide file tree
Showing 12 changed files with 686 additions and 901 deletions.
19 changes: 10 additions & 9 deletions command/build/channel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ interface Options {

// チャンネルファイルを作成する
spinner.loading("Build channel file")
const buildChannelFileResult = await buildChannelFile(
srcChannelFilePath,
distChannelFilePath,
srcMessageDirPath,
distMessageDirPath,
migrateArchive
)
if (buildChannelFileResult.status === "failed") {
spinner.failed(null, buildChannelFileResult.message)
try {
await buildChannelFile(
srcChannelFilePath,
distChannelFilePath,
srcMessageDirPath,
distMessageDirPath,
migrateArchive
)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()
Expand Down
50 changes: 30 additions & 20 deletions command/build/message.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Command } from "commander"
import dotenv from "dotenv"
import { resolve, join } from "node:path"
import type { WebClient as SlackClientType } from "@slack/web-api"
import { Spinner } from "../../libs/util/spinner.mjs"
import { getChannelFile } from "../../libs/channel.mjs"
import type { Channel } from "../../libs/channel.mjs"
import { buildAllMessageFile } from "../../libs/message.mjs"
import { getUserFile } from "../../libs/user.mjs"
import type { User } from "../../libs/user.mjs"
import { createSlackClient } from "../../libs/client.mjs"

const __dirname = new URL(import.meta.url).pathname
Expand Down Expand Up @@ -42,48 +45,55 @@ interface Options {

// Slackのクライアントを作成する
spinner.loading("Create slack client")
const { slackClient, ...createSlackClientResult } =
createSlackClient(slackBotToken)
if (!slackClient || createSlackClientResult.status === "failed") {
spinner.failed(null, createSlackClientResult.message)
let slackClient: SlackClientType | null = null
try {
slackClient = createSlackClient(slackBotToken)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// チャンネルを取得する
spinner.loading("Get channel")
const { channels, ...getChannelFileResult } = await getChannelFile(
distChannelFilePath
)
if (getChannelFileResult.status === "failed") {
spinner.failed(null, getChannelFileResult.message)
let channels: Channel[] | null = null
try {
channels = await getChannelFile(distChannelFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// ユーザーを取得する
spinner.loading("Get user")
const { users, ...getUserFileResult } = await getUserFile(distUserFilePath)
if (getUserFileResult.status === "failed") {
spinner.failed(null, getUserFileResult.message)
let users: User[] | null = null
try {
users = await getUserFile(distUserFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// メッセージファイルを作成する
spinner.loading("Build message file")
const buildAllMessageFileResult = await buildAllMessageFile(
slackClient,
channels,
users
)
if (buildAllMessageFileResult.status === "failed") {
spinner.failed(null, buildAllMessageFileResult.message)
let isMaxFileSizeOver = false
try {
const buildAllMessageFileResult = await buildAllMessageFile(
slackClient,
channels,
users
)
if (buildAllMessageFileResult.isMaxFileSizeOver) isMaxFileSizeOver = true
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// メッセージに最大ファイルサイズを超えているファイルがある場合は警告を出力する
if (buildAllMessageFileResult.isMaxFileSizeOver) {
if (isMaxFileSizeOver) {
spinner.warning(
"Message has attachments that exceed Discord's maximum file size.\nAttachments that exceed Discord's maximum file size will be appended to the message as a file URL.\nConsider releasing the maximum file upload size limit with Discord's server boost."
)
Expand Down
28 changes: 16 additions & 12 deletions command/build/user.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Command } from "commander"
import dotenv from "dotenv"
import { resolve, join } from "node:path"
import type { WebClient as SlackClientType } from "@slack/web-api"
import { Spinner } from "../../libs/util/spinner.mjs"
import { buildUser } from "../../libs/user.mjs"
import { getChannelFile } from "../../libs/channel.mjs"
import type { Channel } from "../../libs/channel.mjs"
import { createSlackClient } from "../../libs/client.mjs"

const __dirname = new URL(import.meta.url).pathname
Expand Down Expand Up @@ -43,30 +45,32 @@ interface Options {

// Slackのクライアントを作成する
spinner.loading("Create slack client")
const { slackClient, ...createSlackClientResult } =
createSlackClient(slackBotToken)
if (!slackClient || createSlackClientResult.status === "failed") {
spinner.failed(null, createSlackClientResult.message)
let slackClient: SlackClientType | null = null
try {
slackClient = createSlackClient(slackBotToken)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// チャンネルを取得する
spinner.loading("Get channel")
const { channels, ...getChannelFileResult } = await getChannelFile(
distChannelFilePath
)
if (getChannelFileResult.status === "failed") {
spinner.failed(null, getChannelFileResult.message)
let channels: Channel[] | null = null
try {
channels = await getChannelFile(distChannelFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// ユーザーファイルを作成する
spinner.loading("Build user file")
const buildUserResult = await buildUser(srcUserFilePath, distUserFilePath)
if (buildUserResult.status === "failed") {
spinner.failed(null, buildUserResult.message)
try {
await buildUser(srcUserFilePath, distUserFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()
Expand Down
63 changes: 35 additions & 28 deletions command/deploy/channel.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Command } from "commander"
import dotenv from "dotenv"
import { resolve, join } from "node:path"
import type { Guild as DiscordClientType } from "discord.js"
import { Spinner } from "../../libs/util/spinner.mjs"
import { createDiscordClient } from "../../libs/client.mjs"
import { deployChannel, getChannelFile } from "../../libs/channel.mjs"
import type { Channel } from "../../libs/channel.mjs"
import { createCategory } from "../../libs/category.mjs"
import type { Category } from "../../libs/category.mjs"

const __dirname = new URL(import.meta.url).pathname
const distDirPath = resolve(__dirname, "../../../.dist/")
Expand Down Expand Up @@ -47,37 +50,40 @@ interface Options {

// Discordのクライアントを作成する
spinner.loading("Create discord client")
const { discordClient, ...createDiscordClientResult } =
await createDiscordClient(discordBotToken, discordServerId)
if (!discordClient || createDiscordClientResult.status === "failed") {
spinner.failed(null, createDiscordClientResult.message)
let discordClient: DiscordClientType | null = null
try {
discordClient = await createDiscordClient(discordBotToken, discordServerId)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// チャンネルを取得する
spinner.loading("Get channel")
const { channels, ...getChannelFileResult } = await getChannelFile(
distChannelFilePath
)
if (getChannelFileResult.status === "failed") {
spinner.failed(null, getChannelFileResult.message)
let channels: Channel[] | null = null
try {
channels = await getChannelFile(distChannelFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// チャンネルのカテゴリーを作成する
spinner.loading("Create category")
const { categories, ...createCategoryResult } = await createCategory(
discordClient,
[
{ id: "", name: "CHANNEL" },
{ id: "", name: "ARCHIVE" },
],
distCategoryFilePath
)
if (createCategoryResult.status === "failed") {
spinner.failed(null, createCategoryResult.message)
let categories: Category[] | null = null
try {
categories = await createCategory(
discordClient,
[
{ id: "", name: "CHANNEL" },
{ id: "", name: "ARCHIVE" },
],
distCategoryFilePath
)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}

Expand All @@ -96,15 +102,16 @@ interface Options {

// チャンネルをデプロイする
spinner.loading("Deploy channel")
const deployChannelResult = await deployChannel(
discordClient,
channels,
distChannelFilePath,
defaultCategory,
archiveCategory
)
if (deployChannelResult.status === "failed") {
spinner.failed(null, deployChannelResult.message)
try {
await deployChannel(
discordClient,
channels,
distChannelFilePath,
defaultCategory,
archiveCategory
)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()
Expand Down
36 changes: 23 additions & 13 deletions command/deploy/message.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Command } from "commander"
import dotenv from "dotenv"
import { resolve, join } from "node:path"
import type { Guild as DiscordClientType } from "discord.js"
import { Spinner } from "../../libs/util/spinner.mjs"
import { createDiscordClient } from "../../libs/client.mjs"
import { getChannelFile } from "../../libs/channel.mjs"
import type { Channel } from "../../libs/channel.mjs"
import { deployAllMessage } from "../../libs/message.mjs"

const __dirname = new URL(import.meta.url).pathname
Expand Down Expand Up @@ -46,35 +48,43 @@ interface Options {

// Discordのクライアントを作成する
spinner.loading("Create discord client")
const { discordClient, ...createDiscordClientResult } =
await createDiscordClient(discordBotToken, discordServerId)
if (!discordClient || createDiscordClientResult.status === "failed") {
spinner.failed(null, createDiscordClientResult.message)
let discordClient: DiscordClientType | null = null
try {
discordClient = await createDiscordClient(discordBotToken, discordServerId)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// チャンネルを取得する
spinner.loading("Get channel")
const { channels, ...getChannelFileResult } = await getChannelFile(
distChannelFilePath
)
if (getChannelFileResult.status === "failed") {
spinner.failed(null, getChannelFileResult.message)
let channels: Channel[] | null = null
try {
channels = await getChannelFile(distChannelFilePath)
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// メッセージをデプロイする
spinner.loading("Deploy message")
const deployAllMessageResult = await deployAllMessage(discordClient, channels)
if (deployAllMessageResult.status === "failed") {
spinner.failed(null, deployAllMessageResult.message)
let isMaxFileSizeOver = false
try {
const deployAllMessageResult = await deployAllMessage(
discordClient,
channels
)
if (deployAllMessageResult.isMaxFileSizeOver) isMaxFileSizeOver = true
} catch (error) {
spinner.failed(null, error)
process.exit(0)
}
spinner.success()

// メッセージに最大ファイルサイズを超えているファイルがある場合は警告を出力する
if (deployAllMessageResult.isMaxFileSizeOver) {
if (isMaxFileSizeOver) {
spinner.warning(
"Message has attachments that exceed Discord's maximum file size.\nAttachments that exceed Discord's maximum file size will be appended to the message as a file URL.\nConsider releasing the maximum file upload size limit with Discord's server boost."
)
Expand Down
Loading

0 comments on commit 99e8084

Please sign in to comment.