Skip to content

Commit

Permalink
Merge pull request #194 from kounoike:fix/autosearch-delete-bug
Browse files Browse the repository at this point in the history
自動検索の削除時のバグ修正
  • Loading branch information
kounoike authored May 6, 2023
2 parents f64bf48 + 9060dba commit 5a2112d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 68 deletions.
1 change: 1 addition & 0 deletions cmd/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func (c *BotCommand) Execute(ctx context.Context, f *flag.FlagSet, args ...inter
discordHandler.AddReactionAddHandler()
discordHandler.AddReactionRemoveHandler()
discordHandler.RegisterCommand()
defer discordHandler.UnregisterCommand()

logger.Info("AddDiscordHandle done. start subscribe to SSE events.")

Expand Down
11 changes: 7 additions & 4 deletions db/auto_search_found_message.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions db/auto_search_message.sql.go

This file was deleted.

8 changes: 0 additions & 8 deletions db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions db/queries/auto_search_found_message.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ FROM
WHERE
`thread_id` = ?;

-- name: CountAutoSearchFoundMessagesByProgramID :one
-- name: CountAutoSearchFoundMessagesWithRecordByProgramID :one
SELECT
count(*)
FROM
`auto_search_found_message`
JOIN
`auto_search` ON `auto_search_found_message`.`thread_id` = `auto_search`.`thread_id`
WHERE
`program_id` = ?
`auto_search`.`record` = 1
AND `program_id` = ?
;

-- name: DeleteAutoSearchFoundMessagesByThreadID :exec
Expand Down
8 changes: 7 additions & 1 deletion discord/discord_handler/command_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (h *DiscordHandler) CommandHandler(s *discordgo.Session, i *discordgo.Inter
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("> %s\nスレッド名:%s\nタイトル:%s\nチャンネル:%s\nジャンル:%s\n録画:%s\nこれでよろしいですか?",
Content: fmt.Sprintf("> %s\n**スレッド名:**%s\n**タイトル:**%s\n**チャンネル:**%s\n**ジャンル:**%s\n**録画:**%s\nこれでよろしいですか?",
jsonStr,
data.Name,
data.Title,
Expand Down Expand Up @@ -343,3 +343,9 @@ func (h *DiscordHandler) RegisterCommand() {
h.logger.Error("ApplicationCommandCreate error", zap.Error(err))
}
}

func (h *DiscordHandler) UnregisterCommand() {
h.session.ApplicationCommandDelete(h.session.State.User.ID, h.session.State.Guilds[0].ID, "index")
h.session.ApplicationCommandDelete(h.session.State.User.ID, h.session.State.Guilds[0].ID, "create")
h.session.ApplicationCommandDelete(h.session.State.User.ID, h.session.State.Guilds[0].ID, "delete")
}
2 changes: 1 addition & 1 deletion dtv/create_auto_seach.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (dtv *DTVUsecase) CreateAutoSearch(userID string, name string, title string
}
if err := dtv.mirakc.AddRecordingSchedule(program.ID, contentPath); err != nil {
dtv.logger.Warn("AddRecordingSchedule error", zap.Error(err))
continue
// 重複登録の場合もあるので、エラーは無視して継続
}
}
if err := dtv.queries.InsertAutoSearchFoundMessage(ctx, db.InsertAutoSearchFoundMessageParams{MessageID: msg.ID, ThreadID: thID, ProgramID: program.ID}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dtv/delete_auto_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (dtv *DTVUsecase) DeleteAutoSearch(ctx context.Context, threadID string) er
}
for _, found := range founds {
programID := found.ProgramID
cnt, err := dtv.queries.CountAutoSearchFoundMessagesByProgramID(ctx, programID)
cnt, err := dtv.queries.CountAutoSearchFoundMessagesWithRecordByProgramID(ctx, programID)
if err != nil {
return err
}
Expand Down
16 changes: 14 additions & 2 deletions mirakc/mirakc_client/mirakc-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ type scheduleData struct {

func (m *MirakcClient) AddRecordingSchedule(programID int64, contentPath string) error {
url := fmt.Sprintf("http://%s:%d/api/recording/schedules", m.host, m.port)
getUrl := fmt.Sprintf("%s/%d", url, programID)

client := resty.New()
resp, err := client.R().
Get(getUrl)
if err != nil {
return err
}
if resp.StatusCode() == 200 {
// 既に予約済みなので何もしない
return nil
}

data := scheduleData{
ProgramID: programID,
Options: scheduleOptions{
Expand All @@ -129,8 +142,7 @@ func (m *MirakcClient) AddRecordingSchedule(programID int64, contentPath string)
return err
}
// postOption := fmt.Sprintf(`{"programId": %d, "options": {"contentPath": "%d.m2ts"}, "tags": ["manual"]}`, programID, programID)
client := resty.New()
resp, err := client.R().
resp, err = client.R().
SetHeader("Content-Type", "application/json").
SetBody(dataJson).
Post(url)
Expand Down

0 comments on commit 5a2112d

Please sign in to comment.