Merge 4ec929a4bd4fa13d060584afdf733f26d806d3ab into c4157a4d5b49fce79c80a30730dc7c404bacd663
This commit is contained in:
commit
4a487f7bd1
@ -278,7 +278,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
|
|
||||||
// Use webhook to send the message
|
// Use webhook to send the message
|
||||||
useWebhooks := b.shouldMessageUseWebhooks(&msg)
|
useWebhooks := b.shouldMessageUseWebhooks(&msg)
|
||||||
if useWebhooks && msg.Event != config.EventMsgDelete && msg.ParentID == "" {
|
if useWebhooks && msg.ParentID == "" {
|
||||||
return b.handleEventWebhook(&msg, channelID)
|
return b.handleEventWebhook(&msg, channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,23 @@ func (t *Transmitter) Edit(channelID string, messageID string, params *discordgo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete will delete a message from a channel, if possible.
|
||||||
|
func (t *Transmitter) Delete(channelID string, messageID string) error {
|
||||||
|
wh := t.getWebhook(channelID)
|
||||||
|
|
||||||
|
if wh == nil {
|
||||||
|
return ErrWebhookNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := discordgo.EndpointWebhookToken(wh.ID, wh.Token) + "/messages/" + messageID
|
||||||
|
_, err := t.session.RequestWithBucketID("DELETE", uri, nil, discordgo.EndpointWebhookToken("", ""))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("delete failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// HasWebhook checks whether the transmitter is using a particular webhook.
|
// HasWebhook checks whether the transmitter is using a particular webhook.
|
||||||
func (t *Transmitter) HasWebhook(id string) bool {
|
func (t *Transmitter) HasWebhook(id string) bool {
|
||||||
t.mutex.RLock()
|
t.mutex.RLock()
|
||||||
|
@ -125,6 +125,21 @@ func (b *Bdiscord) webhookSend(msg *config.Message, channelID string) (string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bdiscord) handleEventWebhook(msg *config.Message, channelID string) (string, error) {
|
func (b *Bdiscord) handleEventWebhook(msg *config.Message, channelID string) (string, error) {
|
||||||
|
if msg.Event == config.EventMsgDelete {
|
||||||
|
if msg.ID == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := b.transmitter.Delete(channelID, msg.ID)
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Errorf("Could not delete message: %s", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Log.Infof("Message deleted successfully")
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// skip events
|
// skip events
|
||||||
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave && msg.Event != config.EventTopicChange {
|
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave && msg.Event != config.EventTopicChange {
|
||||||
return "", nil
|
return "", nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user