summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-03-01 20:59:19 +0100
committerGitHub <noreply@github.com>2020-03-01 20:59:19 +0100
commit250b3bb5795240d5ebdab5416ab99dbc41be734b (patch)
tree11e44ec2e7e37cd7eb0deaf0a7843fe6bf3c0e40 /vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go
parente9edbfc051afc643d91fc04bc7fb3fe70039c213 (diff)
downloadmatterbridge-msglm-250b3bb5795240d5ebdab5416ab99dbc41be734b.tar.gz
matterbridge-msglm-250b3bb5795240d5ebdab5416ab99dbc41be734b.tar.bz2
matterbridge-msglm-250b3bb5795240d5ebdab5416ab99dbc41be734b.zip
Use upstream slack-go/slack again (#1018)
Diffstat (limited to 'vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go')
-rw-r--r--vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go b/vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go
new file mode 100644
index 00000000..1f7b2b8c
--- /dev/null
+++ b/vendor/github.com/slack-go/slack/slackutilsx/slackutilsx.go
@@ -0,0 +1,62 @@
+// Package slackutilsx is a utility package that doesn't promise API stability.
+// its for experimental functionality and utilities.
+package slackutilsx
+
+import (
+ "strings"
+ "unicode/utf8"
+)
+
+// ChannelType the type of channel based on the channelID
+type ChannelType int
+
+func (t ChannelType) String() string {
+ switch t {
+ case CTypeDM:
+ return "Direct"
+ case CTypeGroup:
+ return "Group"
+ case CTypeChannel:
+ return "Channel"
+ default:
+ return "Unknown"
+ }
+}
+
+const (
+ // CTypeUnknown represents channels we cannot properly detect.
+ CTypeUnknown ChannelType = iota
+ // CTypeDM is a private channel between two slack users.
+ CTypeDM
+ // CTypeGroup is a group channel.
+ CTypeGroup
+ // CTypeChannel is a public channel.
+ CTypeChannel
+)
+
+// DetectChannelType converts a channelID to a ChannelType.
+// channelID must not be empty. However, if it is empty, the channel type will default to Unknown.
+func DetectChannelType(channelID string) ChannelType {
+ // intentionally ignore the error and just default to CTypeUnknown
+ switch r, _ := utf8.DecodeRuneInString(channelID); r {
+ case 'C':
+ return CTypeChannel
+ case 'G':
+ return CTypeGroup
+ case 'D':
+ return CTypeDM
+ default:
+ return CTypeUnknown
+ }
+}
+
+// EscapeMessage text
+func EscapeMessage(message string) string {
+ replacer := strings.NewReplacer("&", "&amp;", "<", "&lt;", ">", "&gt;")
+ return replacer.Replace(message)
+}
+
+// Retryable errors return true.
+type Retryable interface {
+ Retryable() bool
+}