-
Notifications
You must be signed in to change notification settings - Fork 0
[v9] Projectsにあるロールパネル機能の実装 #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/go
Are you sure you want to change the base?
Changes from all commits
b3eeab3
d7a6541
8bef316
4ec078c
4c69e2d
25e45d5
1accc8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package server_management | ||
|
|
||
| import ( | ||
| "time" | ||
| "unibot/internal" | ||
| "unibot/internal/bot/command/server_management/rolepanel" | ||
|
|
||
| "github.com/bwmarrin/discordgo" | ||
| ) | ||
|
|
||
| func LoadRolepanelCommandContext() *discordgo.ApplicationCommand { | ||
| return &discordgo.ApplicationCommand{ | ||
| Name: "rolepanel", | ||
| Description: "ロールパネルを管理します", | ||
| DefaultMemberPermissions: ptrInt64(discordgo.PermissionManageRoles), | ||
| Options: []*discordgo.ApplicationCommandOption{ | ||
| rolepanel.LoadCreateCommandContext(), | ||
| rolepanel.LoadDeleteCommandContext(), | ||
| rolepanel.LoadAddCommandContext(), | ||
| rolepanel.LoadRemoveCommandContext(), | ||
| rolepanel.LoadListCommandContext(), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func ptrInt64(i int64) *int64 { | ||
| return &i | ||
| } | ||
|
|
||
| var rolepanelHandler = map[string]func(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.InteractionCreate){ | ||
| "create": rolepanel.Create, | ||
| "delete": rolepanel.Delete, | ||
| "add": rolepanel.Add, | ||
| "remove": rolepanel.Remove, | ||
| "list": rolepanel.List, | ||
| } | ||
|
|
||
| func Rolepanel(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
| config := ctx.Config | ||
| subCommand := i.ApplicationCommandData().Options[0] | ||
|
|
||
| if handler, exists := rolepanelHandler[subCommand.Name]; exists { | ||
| handler(ctx, s, i) | ||
| return | ||
| } | ||
|
|
||
| _ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ | ||
| Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
| Data: &discordgo.InteractionResponseData{ | ||
| Embeds: []*discordgo.MessageEmbed{ | ||
| { | ||
| Title: "エラー", | ||
| Description: "不明なサブコマンドです。", | ||
| Color: config.Colors.Error, | ||
| Footer: &discordgo.MessageEmbedFooter{ | ||
| Text: "Requested by " + i.Member.DisplayName(), | ||
| IconURL: i.Member.AvatarURL(""), | ||
| }, | ||
| Timestamp: time.Now().Format(time.RFC3339), | ||
| }, | ||
| }, | ||
| Flags: discordgo.MessageFlagsEphemeral, | ||
| }, | ||
| }) | ||
| } | ||
|
Comment on lines
+38
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n[dispatcher の ACK 順序]\n'
rg -n -C3 'InteractionRespond|entry\.Handler\(ctx, s, i\)' \
src/internal/bot/handler/interaction.go
printf '\n[rolepanel 配下の InteractionRespond 呼び出し]\n'
rg -n -C1 'InteractionRespond\s*\(' \
src/internal/bot/command/server_management/rolepanel.go \
src/internal/bot/command/server_management/rolepanelRepository: UniPro-tech/UniBot Length of output: 6411
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| package rolepanel | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| "unibot/internal" | ||
| "unibot/internal/bot/messageComponent" | ||
| "unibot/internal/repository" | ||
|
|
||
| "github.com/bwmarrin/discordgo" | ||
| ) | ||
|
|
||
| func LoadAddCommandContext() *discordgo.ApplicationCommandOption { | ||
| return &discordgo.ApplicationCommandOption{ | ||
| Type: discordgo.ApplicationCommandOptionSubCommand, | ||
| Name: "add", | ||
| Description: "ロールパネルにロールを追加します", | ||
| Options: []*discordgo.ApplicationCommandOption{ | ||
| { | ||
| Type: discordgo.ApplicationCommandOptionRole, | ||
| Name: "role", | ||
| Description: "追加するロール", | ||
| Required: true, | ||
| }, | ||
| { | ||
| Type: discordgo.ApplicationCommandOptionString, | ||
| Name: "label", | ||
| Description: "セレクトメニューに表示するラベル", | ||
| Required: true, | ||
| MaxLength: 100, | ||
| }, | ||
| { | ||
| Type: discordgo.ApplicationCommandOptionString, | ||
| Name: "description", | ||
| Description: "ロールの説明", | ||
| Required: false, | ||
| MaxLength: 100, | ||
| }, | ||
| { | ||
| Type: discordgo.ApplicationCommandOptionString, | ||
| Name: "emoji", | ||
| Description: "絵文字 (例: 🎮)", | ||
| Required: false, | ||
|
ysmreg marked this conversation as resolved.
|
||
| MaxLength: 100, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func Add(ctx *internal.BotContext, s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
| config := ctx.Config | ||
| options := i.ApplicationCommandData().Options[0].Options | ||
|
|
||
| var roleID, label, description, emoji string | ||
| for _, opt := range options { | ||
| switch opt.Name { | ||
| case "role": | ||
| roleID = opt.RoleValue(s, i.GuildID).ID | ||
| case "label": | ||
| label = opt.StringValue() | ||
| case "description": | ||
| description = opt.StringValue() | ||
| case "emoji": | ||
| emoji = opt.StringValue() | ||
| } | ||
| } | ||
|
|
||
| repo := repository.NewRolePanelRepository(ctx.DB) | ||
|
|
||
| // このギルドのパネル一覧を取得 | ||
| panels, err := repo.ListByGuild(i.GuildID) | ||
| if err != nil { | ||
| _ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ | ||
| Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
| Data: &discordgo.InteractionResponseData{ | ||
| Embeds: []*discordgo.MessageEmbed{ | ||
| { | ||
| Title: "エラー", | ||
| Description: "パネルの取得中にエラーが発生しました。", | ||
| Color: config.Colors.Error, | ||
| Footer: &discordgo.MessageEmbedFooter{ | ||
| Text: "Requested by " + i.Member.DisplayName(), | ||
| IconURL: i.Member.AvatarURL(""), | ||
| }, | ||
| Timestamp: time.Now().Format(time.RFC3339), | ||
| }, | ||
| }, | ||
| Flags: discordgo.MessageFlagsEphemeral, | ||
| }, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| if len(panels) == 0 { | ||
| _ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ | ||
| Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
| Data: &discordgo.InteractionResponseData{ | ||
| Embeds: []*discordgo.MessageEmbed{ | ||
| { | ||
| Title: "エラー", | ||
| Description: "このサーバーにはロールパネルがありません。\n先に `/rolepanel create` でパネルを作成してください。", | ||
| Color: config.Colors.Error, | ||
| Footer: &discordgo.MessageEmbedFooter{ | ||
| Text: "Requested by " + i.Member.DisplayName(), | ||
| IconURL: i.Member.AvatarURL(""), | ||
| }, | ||
| Timestamp: time.Now().Format(time.RFC3339), | ||
| }, | ||
| }, | ||
| Flags: discordgo.MessageFlagsEphemeral, | ||
| }, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| // パネル選択用セレクトメニューを作成 | ||
| var selectOptions []discordgo.SelectMenuOption | ||
| for _, panel := range panels { | ||
| selectOptions = append(selectOptions, discordgo.SelectMenuOption{ | ||
| Label: panel.Title, | ||
| Value: panel.MessageID, | ||
| Description: fmt.Sprintf("%d個のロール", len(panel.Options)), | ||
| }) | ||
| } | ||
|
|
||
| token, err := messageComponent.SaveRolePanelPendingAdd(messageComponent.RolePanelPendingAdd{ | ||
| UserID: i.Member.User.ID, | ||
| GuildID: i.GuildID, | ||
| RoleID: roleID, | ||
| Label: label, | ||
| Description: description, | ||
| Emoji: emoji, | ||
| }) | ||
| if err != nil { | ||
| _ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ | ||
| Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
| Data: &discordgo.InteractionResponseData{ | ||
| Embeds: []*discordgo.MessageEmbed{ | ||
| { | ||
| Title: "エラー", | ||
| Description: "ロール追加情報の準備中にエラーが発生しました。", | ||
| Color: config.Colors.Error, | ||
| Footer: &discordgo.MessageEmbedFooter{ | ||
| Text: "Requested by " + i.Member.DisplayName(), | ||
| IconURL: i.Member.AvatarURL(""), | ||
| }, | ||
| Timestamp: time.Now().Format(time.RFC3339), | ||
| }, | ||
| }, | ||
| Flags: discordgo.MessageFlagsEphemeral, | ||
| }, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| customID := "rolepanel_add_" + token | ||
|
|
||
| _ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ | ||
| Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
| Data: &discordgo.InteractionResponseData{ | ||
| Embeds: []*discordgo.MessageEmbed{ | ||
| { | ||
| Title: "パネルを選択", | ||
| Description: fmt.Sprintf("ロール <@&%s> を追加するパネルを選択してください。", roleID), | ||
| Color: config.Colors.Primary, | ||
| Footer: &discordgo.MessageEmbedFooter{ | ||
| Text: "Requested by " + i.Member.DisplayName(), | ||
| IconURL: i.Member.AvatarURL(""), | ||
| }, | ||
| Timestamp: time.Now().Format(time.RFC3339), | ||
| }, | ||
| }, | ||
| Components: []discordgo.MessageComponent{ | ||
| discordgo.ActionsRow{ | ||
| Components: []discordgo.MessageComponent{ | ||
| discordgo.SelectMenu{ | ||
| CustomID: customID, | ||
| Placeholder: "パネルを選択...", | ||
| Options: selectOptions, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| Flags: discordgo.MessageFlagsEphemeral, | ||
| }, | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: UniPro-tech/UniBot
Length of output: 4773
🏁 Script executed:
cat -n src/internal/bot/handler/interaction.go | head -60Repository: UniPro-tech/UniBot
Length of output: 2271
rolepanelはEphemeral: trueにそろえた方がよいです。src/internal/bot/handler/interaction.go:29-32で deferred response にレジストリのEphemeralフラグが反映されるため、現在の rolepanel 登録ではデファード応答が公開扱いになります。一方、rolepanel 配下のすべてのハンドラ (rolepanel.go、create.go、add.go、remove.go、list.go、delete.go) は応答時にMessageFlagsEphemeralを指定しており、プライベート前提の運用です。登録側と実装側のエフェメラル指定を統一するため、レジストリ側にEphemeral: trueを追加してください。🔧 修正例
"rolepanel": { - Handler: server_management.Rolepanel, + Handler: server_management.Rolepanel, + Ephemeral: true, },📝 Committable suggestion
🤖 Prompt for AI Agents