diff options
author | Qais Patankar <qaisjp@gmail.com> | 2020-11-30 05:47:02 +0000 |
---|---|---|
committer | Wim <wim@42.be> | 2020-12-13 23:19:48 +0100 |
commit | 52e2f926f423295dbf95463218bed6abd94d574a (patch) | |
tree | 18b7f76ab647c73a631c257ef806513dd04e90ed /bridge/discord/transmitter/utils.go | |
parent | 611fb279bc3680ef9e241e913589dc9056c2f5bd (diff) | |
download | matterbridge-msglm-52e2f926f423295dbf95463218bed6abd94d574a.tar.gz matterbridge-msglm-52e2f926f423295dbf95463218bed6abd94d574a.tar.bz2 matterbridge-msglm-52e2f926f423295dbf95463218bed6abd94d574a.zip |
Add initial transmitter implementation (discord)
This has been tested with one webhook in one channel.
Sends, edits and deletions work fine
Diffstat (limited to 'bridge/discord/transmitter/utils.go')
-rw-r--r-- | bridge/discord/transmitter/utils.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/bridge/discord/transmitter/utils.go b/bridge/discord/transmitter/utils.go new file mode 100644 index 00000000..f42e81eb --- /dev/null +++ b/bridge/discord/transmitter/utils.go @@ -0,0 +1,32 @@ +package transmitter + +import ( + "github.com/matterbridge/discordgo" +) + +// isDiscordPermissionError returns false for nil, and true if a Discord RESTError with code discordgo.ErrorCodeMissionPermissions +func isDiscordPermissionError(err error) bool { + if err == nil { + return false + } + + restErr, ok := err.(*discordgo.RESTError) + if !ok { + return false + } + + return restErr.Message != nil && restErr.Message.Code == discordgo.ErrCodeMissingPermissions +} + +// getDiscordUserID gets own user ID from state, and fallback on API request +func getDiscordUserID(session *discordgo.Session) (string, error) { + if user := session.State.User; user != nil { + return user.ID, nil + } + + user, err := session.User("@me") + if err != nil { + return "", err + } + return user.ID, nil +} |