Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7546a76
refactor(database): GORMを使用してデータベースモデルを更新し、エンティティの操作を改善
ikafly144 Jan 28, 2026
abacba8
feat(models): WordSuffixにUUIDのデフォルト値を追加
ikafly144 Jan 28, 2026
e76c3ff
fix(components): ギルド脱退時のデータベース削除エラーをログに記録
ikafly144 Jan 28, 2026
54f58cf
feat(components): ギルド初期化時にオーナーIDを追加
ikafly144 Jan 28, 2026
4f93464
build(Docker): gemini-cli-sandboxのバージョンをlatestに更新
ikafly144 Jan 28, 2026
8e8c399
feat(models): UUIDの生成をBeforeCreateフックで追加
ikafly144 Jan 28, 2026
17daee4
feat(permission): 最大文字数を1から100に更新
ikafly144 Jan 28, 2026
06b26ce
fix(components): ギルド脱退時の削除処理にエラーログを追加
ikafly144 Jan 28, 2026
bd6fab7
refactor(components): ユーザー作成処理のリファクタリング
ikafly144 Jan 28, 2026
f8d73ff
chore(Docker): gemini-cli-sandboxのDockerfileを削除
ikafly144 Jan 28, 2026
f681768
refactor(models): OwnerIDとOwnerフィールドをポインタ型に変更
ikafly144 Jan 28, 2026
c3fa2d5
fix(level): GormDBの保存処理にエラーハンドリングを追加
ikafly144 Jan 28, 2026
df59406
refactor(level): addXp関数にGormDBを引数として渡すように変更
ikafly144 Jan 28, 2026
87d60f9
fix(message): GormDBのエラーハンドリングを改善
ikafly144 Jan 28, 2026
1fbb466
fix(permission): GormDBの保存処理にエラーハンドリングを追加
ikafly144 Jan 28, 2026
21cc717
fix(role): rpEditBaseMessage関数にエラーハンドリングを追加
ikafly144 Jan 28, 2026
c9cf833
fix(setting): GormDBの保存処理にエラーハンドリングを追加
ikafly144 Jan 28, 2026
e46827b
fix(setting): GormDBの保存処理にエラーハンドリングを追加
ikafly144 Jan 28, 2026
89078ea
fix(user): GormDBのユーザー作成処理にエラーハンドリングを追加
ikafly144 Jan 28, 2026
7f988de
fix(guild): ギルド脱退時のエラーハンドリングを追加
ikafly144 Jan 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sabafly/gobot/database"
"github.com/sabafly/gobot/ent/migrate"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
Expand Down Expand Up @@ -150,10 +149,7 @@ func run() error {
// return fmt.Errorf("cacheを開けません: %w", err)
// }

if err := db.Schema.Create(ctx,
migrate.WithForeignKeys(!config.DisableForeignKeys)); err != nil {
return fmt.Errorf("スキーマを定義できません: %w", err)
}
// ent schema migration is removed as we use GORM migration in database.NewDB

if _, err := translate.LoadDir(config.TranslateDir); err != nil {
return fmt.Errorf("翻訳ファイルが読み込めません path=%s: %w", config.TranslateDir, err)
Expand All @@ -168,11 +164,11 @@ func run() error {
}
emoji.SetDefaultRegistry(reg)

component := components.New(ctx, db, *config, gormDB)
component := components.New(ctx, *config, gormDB)
component.Version = version

component.AddCommands(
debug.Command(component),
debug.Command(component, db),
ping.Command(component),
message.Command(component),
role.Command(component),
Expand Down
162 changes: 13 additions & 149 deletions bot/commands/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,23 @@
package debug

import (
"fmt"
"iter"
"log/slog"
"slices"
"strings"

"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/json/v2"
"github.com/disgoorg/omit"
"github.com/disgoorg/snowflake/v2"
"github.com/google/uuid"
"github.com/redis/go-redis/v9"
"github.com/sabafly/gobot/bot/commands/debug/db"
"github.com/sabafly/gobot/bot/commands/role"
"github.com/sabafly/gobot/bot/components"
"github.com/sabafly/gobot/bot/components/generic"
"github.com/sabafly/gobot/ent"
"github.com/sabafly/gobot/ent/rolepanelplaced"
"github.com/sabafly/gobot/ent/schema"
"github.com/sabafly/gobot/internal/builtin"
"github.com/sabafly/gobot/internal/errors"
"github.com/sabafly/gobot/internal/i18n"
"github.com/sabafly/gobot/internal/translate"
)

func Command(c *components.Components) *generic.Command {
func Command(c *components.Components, entClient *ent.Client) *generic.Command {
return (&generic.Command{
Namespace: "debug",
Private: true,
Expand Down Expand Up @@ -86,28 +76,6 @@ func Command(c *components.Components) *generic.Command {
},
},
},
discord.ApplicationCommandOptionSubCommandGroup{
Name: "redis",
Description: "redis",
Options: []discord.ApplicationCommandOptionSubCommand{
{
Name: "import",
Description: "import",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionString{
Name: "addr",
Description: "address",
Required: true,
},
discord.ApplicationCommandOptionInt{
Name: "db",
Description: "db",
Required: true,
},
},
},
},
},
discord.ApplicationCommandOptionSubCommandGroup{
Name: "guild",
Description: "guild",
Expand All @@ -129,6 +97,16 @@ func Command(c *components.Components) *generic.Command {
},
},
},
discord.ApplicationCommandOptionSubCommandGroup{
Name: "migration",
Description: "database migration",
Options: []discord.ApplicationCommandOptionSubCommand{
{
Name: "ent_to_gorm",
Description: "migrate from ent to gorm",
},
},
},
},
},
},
Expand Down Expand Up @@ -222,122 +200,8 @@ func Command(c *components.Components) *generic.Command {
}
return nil
}),
"/debug/redis/import": generic.CommandHandler(func(c *components.Components, event *events.ApplicationCommandInteractionCreate) errors.Error {
client := redis.NewClient(&redis.Options{
Addr: event.SlashCommandInteractionData().String("addr"),
DB: event.SlashCommandInteractionData().Int("db"),
})
// GuildData
guildCmd := client.HGetAll(event, "guild-data")
if err := guildCmd.Err(); err != nil {
return errors.NewError(err)
}

rpv2Cmd := client.HGetAll(event, "role-panel-v2")
if err := rpv2Cmd.Err(); err != nil {
return errors.NewError(err)
}

rpv2List := map[uuid.UUID]db.RolePanelV2{}

for _, v := range rpv2Cmd.Val() {
var rpv2 db.RolePanelV2
if err := json.Unmarshal([]byte(v), &rpv2); err != nil {
slog.Error("unmarshalに失敗", "err", err)
continue
}
rpv2List[rpv2.ID] = rpv2
}

for _, v := range guildCmd.Val() {
var guildData db.GuildData
if err := json.Unmarshal([]byte(v), &guildData); err != nil {
slog.Error("unmarshalに失敗", "err", err)
continue
}
if guildData.DataVersion == nil || *guildData.DataVersion != 11 {
continue
}

g, err := c.GuildCreateID(event, guildData.ID)
if err != nil {
slog.Error("guild取得に失敗", slog.Any("err", err))
continue
}

var createRolePanelBulk []*ent.RolePanelCreate

for u := range guildData.RolePanelV2 {
rpv2, ok := rpv2List[u]
if !ok {
continue
}

roles := make([]schema.Role, len(rpv2.Roles))

for i, r := range rpv2.Roles {
roles[i] = schema.Role{
ID: r.RoleID,
Name: r.RoleName,
Emoji: r.Emoji,
}
}

createRolePanelBulk = append(createRolePanelBulk,
c.DB().RolePanel.Create().
SetID(rpv2.ID).
SetRoles(roles).
SetName(rpv2.Name).
SetGuild(g).
SetDescription(rpv2.Description),
)
}

rolePanels, err := c.DB().RolePanel.CreateBulk(createRolePanelBulk...).Save(event)
if err != nil {
return errors.NewError(err)
}

placedIDMap := map[[2]snowflake.ID]uuid.UUID{}
for k, u := range guildData.RolePanelV2Placed {
ks := strings.Split(k, "/")
channelID, messageID := snowflake.MustParse(ks[0]), snowflake.MustParse(ks[1])
placedIDMap[[2]snowflake.ID{channelID, messageID}] = u
}

for k, u := range placedIDMap {
index := slices.IndexFunc(rolePanels, func(rp *ent.RolePanel) bool { return rp.ID == u })
if index == -1 {
continue
}

keyString := fmt.Sprintf("%d/%d", k[0], k[1])

placed := c.DB().RolePanelPlaced.Create().
SetChannelID(k[0]).
SetMessageID(k[1]).
SetType(rolepanelplaced.Type(guildData.RolePanelV2PlacedConfig[keyString].PanelType)).
SetButtonType(builtin.Or(guildData.RolePanelV2PlacedConfig[keyString].ButtonStyle != 0, guildData.RolePanelV2PlacedConfig[keyString].ButtonStyle, 1)).
SetFoldingSelectMenu(guildData.RolePanelV2PlacedConfig[keyString].SimpleSelectMenu).
SetUseDisplayName(guildData.RolePanelV2PlacedConfig[keyString].UseDisplayName).
SetShowName(guildData.RolePanelV2PlacedConfig[keyString].ButtonShowName).
SetHideNotice(guildData.RolePanelV2PlacedConfig[keyString].HideNotice).
SetName(rolePanels[index].Name).
SetDescription(rolePanels[index].Description).
SetRoles(rolePanels[index].Roles).
SetRolePanel(rolePanels[index]).
SetGuild(g).
SaveX(event)

role.UpdateRolePanel(event, placed, event.Locale(), event.Client())
}

}

if err := event.RespondMessage(discord.NewMessageBuilder().SetContent("OK")); err != nil {
return errors.NewError(err)
}
return nil
"/debug/migration/ent_to_gorm": generic.CommandHandler(func(c *components.Components, event *events.ApplicationCommandInteractionCreate) errors.Error {
return migrateEntToGormHandler(c, entClient, event)
}),
},
}).SetComponent(c)
Expand Down
Loading