mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-02 11:42:15 +00:00
Pulls from git and posts to discord
This commit is contained in:
parent
d63f121871
commit
b37a425589
12 changed files with 611 additions and 5 deletions
48
internal/nzcovidbot/discord.go
Normal file
48
internal/nzcovidbot/discord.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package nzcovidbot
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/DisgoOrg/disgohook"
|
||||
"github.com/DisgoOrg/disgohook/api"
|
||||
)
|
||||
|
||||
var (
|
||||
// Slice of discord webhooks
|
||||
DiscordWebhooks []string
|
||||
)
|
||||
|
||||
func postToDiscord(webhookString string, msg string) {
|
||||
tokenParts := strings.Split(webhookString, "/")
|
||||
len := len(tokenParts)
|
||||
webhook, err := disgohook.NewWebhookClientByToken(nil, nil, tokenParts[len-2]+"/"+tokenParts[len-1])
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
// message, err := webhook.SendContent(msg)
|
||||
// if err != nil {
|
||||
// log.Print(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // message, err = webhook.SendEmbeds(api.NewEmbedBuilder().
|
||||
// // SetDescription(msg).
|
||||
// // Build(),
|
||||
// // )
|
||||
// if err != nil {
|
||||
// log.Print(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
_, err = webhook.SendMessage(api.NewWebhookMessageCreateBuilder().
|
||||
SetContent(msg).
|
||||
Build(),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue