Skip to content

Commit 1fac375

Browse files
committed
エラーメッセージにリクエスト者情報を追加し、フッター処理を共通化
1 parent 2a24dc2 commit 1fac375

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/internal/bot/command/general/schedule.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ var scheduleHandler = map[string]func(ctx *internal.BotContext, s *discordgo.Ses
3131
func Schedule(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.InteractionCreate) {
3232
config := ctx.Config
3333

34+
footer := &discordgo.MessageEmbedFooter{Text: "Requested by Unknown"}
35+
if i.Member != nil {
36+
footer.Text = "Requested by " + i.Member.DisplayName()
37+
footer.IconURL = i.Member.AvatarURL("")
38+
} else if i.User != nil {
39+
footer.Text = "Requested by " + i.User.Username
40+
footer.IconURL = i.User.AvatarURL("")
41+
}
42+
3443
if i.GuildID == "" {
3544
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
3645
Type: discordgo.InteractionResponseChannelMessageWithSource,
@@ -40,10 +49,7 @@ func Schedule(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.Inter
4049
Title: "エラー",
4150
Description: "このコマンドはサーバー内でのみ使用できます。",
4251
Color: config.Colors.Error,
43-
Footer: &discordgo.MessageEmbedFooter{
44-
Text: "Requested by " + i.Member.DisplayName(),
45-
IconURL: i.Member.AvatarURL(""),
46-
},
52+
Footer: footer,
4753
Timestamp: time.Now().Format(time.RFC3339),
4854
},
4955
},
@@ -63,10 +69,7 @@ func Schedule(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.Inter
6369
Title: "エラー",
6470
Description: "このコマンドを実行する権限がありません。",
6571
Color: config.Colors.Error,
66-
Footer: &discordgo.MessageEmbedFooter{
67-
Text: "Requested by " + i.Member.DisplayName(),
68-
IconURL: i.Member.AvatarURL(""),
69-
},
72+
Footer: footer,
7073
Timestamp: time.Now().Format(time.RFC3339),
7174
},
7275
},
@@ -90,10 +93,7 @@ func Schedule(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.Inter
9093
Title: "エラー",
9194
Description: "不明なサブコマンドです。",
9295
Color: config.Colors.Error,
93-
Footer: &discordgo.MessageEmbedFooter{
94-
Text: "Requested by " + i.Member.DisplayName(),
95-
IconURL: i.Member.AvatarURL(""),
96-
},
96+
Footer: footer,
9797
Timestamp: time.Now().Format(time.RFC3339),
9898
},
9999
},

src/internal/bot/command/general/schedule/modals.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ func replyPermissionError(s *discordgo.Session, i *discordgo.InteractionCreate,
186186
}
187187

188188
func replyError(s *discordgo.Session, i *discordgo.InteractionCreate, config *internal.Config, title, description string) {
189+
footer := &discordgo.MessageEmbedFooter{Text: "Requested by Unknown"}
190+
if i.Member != nil {
191+
footer.Text = "Requested by " + i.Member.DisplayName()
192+
footer.IconURL = i.Member.AvatarURL("")
193+
} else if i.User != nil {
194+
footer.Text = "Requested by " + i.User.Username
195+
footer.IconURL = i.User.AvatarURL("")
196+
}
197+
189198
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
190199
Type: discordgo.InteractionResponseChannelMessageWithSource,
191200
Data: &discordgo.InteractionResponseData{
@@ -194,10 +203,7 @@ func replyError(s *discordgo.Session, i *discordgo.InteractionCreate, config *in
194203
Title: title,
195204
Description: description,
196205
Color: config.Colors.Error,
197-
Footer: &discordgo.MessageEmbedFooter{
198-
Text: "Requested by " + i.Member.DisplayName(),
199-
IconURL: i.Member.AvatarURL(""),
200-
},
206+
Footer: footer,
201207
Timestamp: time.Now().Format(time.RFC3339),
202208
},
203209
},

0 commit comments

Comments
 (0)