reduce duplicate of struct and add X match output
This commit is contained in:
149
main.go
149
main.go
@@ -11,65 +11,28 @@ import (
|
|||||||
"github.com/bwmarrin/discordgo"
|
"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 {
|
type BattleSchedule struct {
|
||||||
Result struct {
|
Result struct {
|
||||||
Regular []struct {
|
Regular []BattleSchedudleSub `json:"regular"`
|
||||||
StartTime time.Time `json:"start_time"`
|
BankaraChallenge []BattleSchedudleSub `json:"bankara_challenge"`
|
||||||
EndTime time.Time `json:"end_time"`
|
BankaraOpen []BattleSchedudleSub `json:"bankara_open"`
|
||||||
Rule struct {
|
X []BattleSchedudleSub `json:"x"`
|
||||||
Key string `json:"key"`
|
Event []struct {
|
||||||
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 {
|
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
EndTime time.Time `json:"end_time"`
|
EndTime time.Time `json:"end_time"`
|
||||||
Rule struct {
|
Rule struct {
|
||||||
@@ -178,6 +141,31 @@ func (s *msgidstore) Get() (string, error) {
|
|||||||
return id, nil
|
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 {
|
func battleSchedule() string {
|
||||||
url := "https://spla3.yuu26.com/api/schedule"
|
url := "https://spla3.yuu26.com/api/schedule"
|
||||||
|
|
||||||
@@ -196,50 +184,17 @@ func battleSchedule() string {
|
|||||||
|
|
||||||
output := "バンカラオープン スケジュール\n"
|
output := "バンカラオープン スケジュール\n"
|
||||||
output += "```\n"
|
output += "```\n"
|
||||||
for _, v := range data.Result.BankaraOpen {
|
output += battleScheduleSub(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 += "```\n"
|
output += "```\n"
|
||||||
|
|
||||||
output += "バンカラチャレンジ スケジュール\n"
|
output += "バンカラチャレンジ スケジュール\n"
|
||||||
output += "```\n"
|
output += "```\n"
|
||||||
for _, v := range data.Result.BankaraChallenge {
|
output += battleScheduleSub(data.Result.BankaraChallenge)
|
||||||
output += fmt.Sprintf("%d/%d %2d:%02d- ", v.StartTime.Month(), v.StartTime.Day(), v.StartTime.Hour(), v.StartTime.Minute())
|
output += "```\n"
|
||||||
output += v.Rule.Name
|
|
||||||
/*
|
output += "Xマッチ スケジュール\n"
|
||||||
length := utf8.RuneCountInString(v.Rule.Name)
|
output += "```\n"
|
||||||
fill := (13 - length)
|
output += battleScheduleSub(data.Result.X)
|
||||||
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 += "```\n"
|
output += "```\n"
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|||||||
Reference in New Issue
Block a user