diff --git a/main.go b/main.go index 69a4f1a..d5387eb 100644 --- a/main.go +++ b/main.go @@ -11,65 +11,28 @@ import ( "github.com/bwmarrin/discordgo" ) +type BattleSchedudleSub struct { + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + Rule struct { + Key string `json:"key"` + Name string `json:"name"` + } `json:"rule"` + Stages []struct { + ID int `json:"id"` + Name string `json:"name"` + Image string `json:"image"` + } `json:"stages"` + IsFest bool `json:"is_fest"` +} + type BattleSchedule struct { Result struct { - Regular []struct { - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Rule struct { - Key string `json:"key"` - Name string `json:"name"` - } `json:"rule"` - Stages []struct { - ID int `json:"id"` - Name string `json:"name"` - Image string `json:"image"` - } `json:"stages"` - IsFest bool `json:"is_fest"` - } `json:"regular"` - BankaraChallenge []struct { - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Rule struct { - Key string `json:"key"` - Name string `json:"name"` - } `json:"rule"` - Stages []struct { - ID int `json:"id"` - Name string `json:"name"` - Image string `json:"image"` - } `json:"stages"` - IsFest bool `json:"is_fest"` - } `json:"bankara_challenge"` - BankaraOpen []struct { - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Rule struct { - Key string `json:"key"` - Name string `json:"name"` - } `json:"rule"` - Stages []struct { - ID int `json:"id"` - Name string `json:"name"` - Image string `json:"image"` - } `json:"stages"` - IsFest bool `json:"is_fest"` - } `json:"bankara_open"` - X []struct { - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Rule struct { - Key string `json:"key"` - Name string `json:"name"` - } `json:"rule"` - Stages []struct { - ID int `json:"id"` - Name string `json:"name"` - Image string `json:"image"` - } `json:"stages"` - IsFest bool `json:"is_fest"` - } `json:"x"` - Event []struct { + Regular []BattleSchedudleSub `json:"regular"` + BankaraChallenge []BattleSchedudleSub `json:"bankara_challenge"` + BankaraOpen []BattleSchedudleSub `json:"bankara_open"` + X []BattleSchedudleSub `json:"x"` + Event []struct { StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` Rule struct { @@ -178,6 +141,31 @@ func (s *msgidstore) Get() (string, error) { return id, nil } +func battleScheduleSub(schedSub []BattleSchedudleSub) string { + var output string + for _, v := range schedSub { + output += fmt.Sprintf("%d/%d %2d:%02d- ", v.StartTime.Month(), v.StartTime.Day(), v.StartTime.Hour(), v.StartTime.Minute()) + output += v.Rule.Name + /* + length := utf8.RuneCountInString(v.Rule.Name) + fill := (13 - length) + for range fill { + output += " " + } + for _, stage := range v.Stages { + output += fmt.Sprintf("%s ", stage.Name) + length := utf8.RuneCountInString(stage.Name) + fill := (11 - length) + for range fill { + output += " " + } + } + */ + output += fmt.Sprintln() + } + return output +} + func battleSchedule() string { url := "https://spla3.yuu26.com/api/schedule" @@ -196,50 +184,17 @@ func battleSchedule() string { output := "バンカラオープン スケジュール\n" output += "```\n" - for _, v := range data.Result.BankaraOpen { - output += fmt.Sprintf("%d/%d %2d:%02d- ", v.StartTime.Month(), v.StartTime.Day(), v.StartTime.Hour(), v.StartTime.Minute()) - output += v.Rule.Name - /* - length := utf8.RuneCountInString(v.Rule.Name) - fill := (13 - length) - for range fill { - output += " " - } - for _, stage := range v.Stages { - output += fmt.Sprintf("%s ", stage.Name) - length := utf8.RuneCountInString(stage.Name) - fill := (11 - length) - for range fill { - output += " " - } - } - */ - output += fmt.Sprintln() - } + output += battleScheduleSub(data.Result.BankaraOpen) output += "```\n" output += "バンカラチャレンジ スケジュール\n" output += "```\n" - for _, v := range data.Result.BankaraChallenge { - output += fmt.Sprintf("%d/%d %2d:%02d- ", v.StartTime.Month(), v.StartTime.Day(), v.StartTime.Hour(), v.StartTime.Minute()) - output += v.Rule.Name - /* - length := utf8.RuneCountInString(v.Rule.Name) - fill := (13 - length) - for range fill { - output += " " - } - for _, stage := range v.Stages { - output += fmt.Sprintf("%s ", stage.Name) - length := utf8.RuneCountInString(stage.Name) - fill := (11 - length) - for range fill { - output += " " - } - } - */ - output += fmt.Sprintln() - } + output += battleScheduleSub(data.Result.BankaraChallenge) + output += "```\n" + + output += "Xマッチ スケジュール\n" + output += "```\n" + output += battleScheduleSub(data.Result.X) output += "```\n" return output