バンカラオープンのスケジュール文字列出力を関数に切り出した

This commit is contained in:
2025-05-28 19:18:19 +09:00
parent 58c5c5590f
commit 6a98933369

48
main.go
View File

@@ -11,7 +11,7 @@ import (
"github.com/bwmarrin/discordgo"
)
type AutoGenerated struct {
type BattleSchedule struct {
Result struct {
Regular []struct {
StartTime time.Time `json:"start_time"`
@@ -109,6 +109,27 @@ type AutoGenerated struct {
} `json:"result"`
}
type SalmonRunSchedule struct {
Results []struct {
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Boss struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"boss"`
Stage struct {
ID int `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
} `json:"stage"`
Weapons []struct {
Name string `json:"name"`
Image string `json:"image"`
} `json:"weapons"`
IsBigRun bool `json:"is_big_run"`
} `json:"results"`
}
type msgidstore struct {
filepath string
}
@@ -157,15 +178,7 @@ func (s *msgidstore) Get() (string, error) {
return id, nil
}
func main() {
discordChannelId := os.Getenv("DISCORD_CHANNEL_ID")
discordToken := os.Getenv("DISCORD_TOKEN")
discord, err := discordgo.New("Bot " + discordToken)
if err != nil {
panic(err)
}
func battleSchedule() string {
url := "https://spla3.yuu26.com/api/schedule"
resp, err := http.Get(url)
@@ -175,7 +188,7 @@ func main() {
defer resp.Body.Close()
byteArray, _ := io.ReadAll(resp.Body)
var data AutoGenerated
var data BattleSchedule
err = json.Unmarshal(byteArray, &data)
if err != nil {
panic(err)
@@ -204,6 +217,19 @@ func main() {
output += fmt.Sprintln()
}
output += "```\n"
return output
}
func main() {
discordChannelId := os.Getenv("DISCORD_CHANNEL_ID")
discordToken := os.Getenv("DISCORD_TOKEN")
discord, err := discordgo.New("Bot " + discordToken)
if err != nil {
panic(err)
}
output := battleSchedule()
output += "updated at " + time.Now().Format("1/2 15:04") + "\n"
print(output)