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

Commit

Permalink
fix #14 Userの値を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
yogarasu committed Aug 19, 2022
1 parent 62ff0f9 commit 45fb970
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
4 changes: 2 additions & 2 deletions libs/message.mts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ export const buildMessageFile = async (
name: user.slack.name,
type: message.bot_id
? "bot"
: user.slack.deleted
: user.slack.is_deleted
? "cancel-user"
: "active-user",
color: user.slack.color,
type_icon: message.bot_id ? "🤖" : user.slack.deleted ? "🔵" : "🟢",
type_icon: message.bot_id ? "🤖" : user.slack.is_deleted ? "🔵" : "🟢",
image_url: user.slack.image_url,
}

Expand Down
81 changes: 47 additions & 34 deletions libs/user.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export interface User {
slack: {
id: string
name: string
deleted: boolean
color: string
color: string | "808080"
image_url: string
is_bot: boolean
is_deleted: boolean
bot?: {
bot_id: string
app_id: string
id?: string
app_id?: string
}
}
discord: {
Expand All @@ -38,18 +38,34 @@ export const getUser = async (
try {
const result = await slackClient.users.info({ user: userId })

// ユーザーの必須項目がない場合は例外を投げる
if (
result.user?.id === undefined ||
result.user?.name === undefined ||
result.user?.color === undefined ||
result.user?.profile?.image_512 === undefined ||
result.user?.is_bot === undefined ||
result.user?.deleted === undefined
) {
throw new Error("User is missing a required parameter")
}

const bot = result.user.is_bot
? {
id: result.user?.profile?.bot_id,
app_id: result.user?.profile?.api_app_id,
}
: undefined

const user: User = {
slack: {
id: result.user?.id || "",
name: result.user?.name || "",
deleted: result.user?.deleted || false,
color: result.user?.color || "808080",
image_url: result.user?.profile?.image_512 || "",
is_bot: result.user?.is_bot || false,
bot: {
app_id: result.user?.profile?.api_app_id || "",
bot_id: result.user?.profile?.bot_id || "",
},
id: result.user.id,
name: result.user.name,
color: result.user.color,
image_url: result.user.profile?.image_512,
is_bot: result.user.is_bot,
is_deleted: result.user.deleted,
bot: bot,
},
discord: {
id: "",
Expand Down Expand Up @@ -118,38 +134,35 @@ export const buildUser = async (
const usersFile = await readFile(srcUserFilePath, "utf8")
const users = JSON.parse(usersFile)
.map((user: SlackUser) => {
// ユーザーがBotの場合はBot情報を取得
let bot: User["slack"]["bot"] = undefined
if (user.is_bot) {
const appId = user.profile?.api_app_id || ""
const botId = user.profile?.bot_id || ""
bot = { app_id: appId, bot_id: botId }
}

// ユーザー名もしくはBot名を取得
const name = user.is_bot
? user.profile?.real_name
: user.profile?.display_name

// ユーザーの必須項目がない場合は例外を投げる
if (
user.id === undefined ||
name === undefined ||
user.deleted === undefined ||
user.profile?.real_name === undefined ||
user.profile?.display_name === undefined ||
user.is_bot === undefined ||
user.color === undefined ||
user.deleted === undefined ||
user.profile?.image_512 === undefined
) {
throw new Error("User is missing a required parameter")
}

// ユーザー名もしくはBot名を取得
const name = user.is_bot
? user.profile?.real_name
: user.profile?.display_name

// ユーザーがBotの場合はBot情報を取得
const bot: User["slack"]["bot"] = user.is_bot
? { id: user.profile?.bot_id, app_id: user.profile?.api_app_id }
: undefined

const newUser: User = {
slack: {
id: user.id,
name: name || "",
deleted: user.deleted,
name: name,
is_bot: user.is_bot,
color: user.color,
is_deleted: user.deleted,
color: user.color || "808080",
image_url: user.profile.image_512,
bot: bot,
},
Expand All @@ -161,7 +174,7 @@ export const buildUser = async (

return newUser
})
.sort((user: User) => !user.slack.is_bot || !user.slack.deleted)
.sort((user: User) => !user.slack.is_bot || !user.slack.is_deleted)

await mkdir(dirname(distUserFilePath), {
recursive: true,
Expand Down

0 comments on commit 45fb970

Please sign in to comment.