Add improve webhook integration
This commit is contained in:
@@ -8,6 +8,35 @@ import (
|
||||
"github.com/yeslayla/birdbot/persistence"
|
||||
)
|
||||
|
||||
const WebhookName = "BirdBot"
|
||||
|
||||
// RefreshWebhookState refreshes the state of all webhooks
|
||||
func (discord *Discord) RefreshWebhookState() {
|
||||
channels, err := discord.session.GuildChannels(discord.guildID)
|
||||
if err != nil {
|
||||
log.Printf("Error getting channels: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
webhookData, err := discord.db.GetDiscordWebhook(channel.ID)
|
||||
if err != nil {
|
||||
log.Printf("Error getting webhook from DB: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if webhookData == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = discord.session.WebhookEdit(webhookData.ID, WebhookName, discord.GetAvatarBase64(NewUser(discord.session.State.User)), channel.ID)
|
||||
if err != nil {
|
||||
log.Printf("Error updating webhook: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WebhookSendMessage sends a message to a channel using a webhook
|
||||
func (discord *Discord) WebhookSendMessage(channel *core.Channel, displayName string, message string) {
|
||||
|
||||
webhookData, err := discord.db.GetDiscordWebhook(channel.ID)
|
||||
@@ -17,7 +46,9 @@ func (discord *Discord) WebhookSendMessage(channel *core.Channel, displayName st
|
||||
}
|
||||
|
||||
if webhookData == nil {
|
||||
webhook, err := discord.session.WebhookCreate(channel.ID, "BirdBot", "")
|
||||
webhookAvatar := discord.GetAvatarBase64(NewUser(discord.session.State.User))
|
||||
|
||||
webhook, err := discord.session.WebhookCreate(channel.ID, WebhookName, webhookAvatar)
|
||||
if err != nil {
|
||||
log.Printf("Error creating webhook: %s", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user