diff options
author | Duco van Amstel <duco.vanamstel@gmail.com> | 2018-10-07 22:17:46 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-10-07 23:17:46 +0200 |
commit | 917040b044e349eadc886f9685ada30d164687eb (patch) | |
tree | ea063d87a415f89060b376f29a844e4d1ed86363 /vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go | |
parent | 69646a160d8597944c307334901f0acfd32582c5 (diff) | |
download | matterbridge-msglm-917040b044e349eadc886f9685ada30d164687eb.tar.gz matterbridge-msglm-917040b044e349eadc886f9685ada30d164687eb.tar.bz2 matterbridge-msglm-917040b044e349eadc886f9685ada30d164687eb.zip |
Update of nlopes/slack dependency (#511)
Diffstat (limited to 'vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go b/vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go new file mode 100644 index 00000000..ccf5372b --- /dev/null +++ b/vendor/github.com/nlopes/slack/slackutilsx/slackutilsx.go @@ -0,0 +1,57 @@ +// 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("&", "&", "<", "<", ">", ">") + return replacer.Replace(message) +} |