バンカラオープンのスケジュール文字列出力を関数に切り出した
This commit is contained in:
48
main.go
48
main.go
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AutoGenerated struct {
|
type BattleSchedule struct {
|
||||||
Result struct {
|
Result struct {
|
||||||
Regular []struct {
|
Regular []struct {
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
@@ -109,6 +109,27 @@ type AutoGenerated struct {
|
|||||||
} `json:"result"`
|
} `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 {
|
type msgidstore struct {
|
||||||
filepath string
|
filepath string
|
||||||
}
|
}
|
||||||
@@ -157,15 +178,7 @@ func (s *msgidstore) Get() (string, error) {
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func battleSchedule() string {
|
||||||
discordChannelId := os.Getenv("DISCORD_CHANNEL_ID")
|
|
||||||
discordToken := os.Getenv("DISCORD_TOKEN")
|
|
||||||
|
|
||||||
discord, err := discordgo.New("Bot " + discordToken)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "https://spla3.yuu26.com/api/schedule"
|
url := "https://spla3.yuu26.com/api/schedule"
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
@@ -175,7 +188,7 @@ func main() {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
byteArray, _ := io.ReadAll(resp.Body)
|
byteArray, _ := io.ReadAll(resp.Body)
|
||||||
var data AutoGenerated
|
var data BattleSchedule
|
||||||
err = json.Unmarshal(byteArray, &data)
|
err = json.Unmarshal(byteArray, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -204,6 +217,19 @@ func main() {
|
|||||||
output += fmt.Sprintln()
|
output += fmt.Sprintln()
|
||||||
}
|
}
|
||||||
output += "```\n"
|
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"
|
output += "updated at " + time.Now().Format("1/2 15:04") + "\n"
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user