5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-09 23:40:27 +00:00

Replace :emoji: with unicode chars. #215

Add vendor github.com/peterhellberg/emojilib
This commit is contained in:
Wim 2017-07-09 13:59:50 +02:00
parent 870b89a8f0
commit 6256c066f1
5 changed files with 19742 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/Sirupsen/logrus"
"github.com/peterhellberg/emojilib"
// "github.com/davecgh/go-spew/spew"
"regexp"
"strings"
@ -116,6 +117,7 @@ func (gw *Gateway) handleReceive() {
}
if !gw.ignoreMessage(&msg) {
msg.Timestamp = time.Now()
gw.modifyMessage(&msg)
for _, br := range gw.Bridges {
gw.handleMessage(msg, br)
}
@ -296,6 +298,11 @@ func (gw *Gateway) modifyAvatar(msg *config.Message, dest *bridge.Bridge) {
}
}
func (gw *Gateway) modifyMessage(msg *config.Message) {
// replace :emoji: to unicode
msg.Text = emojilib.Replace(msg.Text)
}
func getChannelID(msg config.Message) string {
return msg.Channel + msg.Account
}

19
vendor/github.com/peterhellberg/emojilib/LICENSE generated vendored Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2015-2017 Peter Hellberg https://c7.se/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

88
vendor/github.com/peterhellberg/emojilib/emojilib.go generated vendored Normal file
View File

@ -0,0 +1,88 @@
/*
Package emojilib is a port of the Emoji keyword library to Go
Installation
Just go get the package:
go get -u github.com/peterhellberg/emojilib
Usage
A small usage example
package main
import (
"fmt"
"github.com/peterhellberg/emojilib"
)
func main() {
fmt.Println(emojilib.ReplaceWithPadding("I :green_heart: You!"))
}
*/
package emojilib
import "errors"
//go:generate go run _generator/main.go
// Emojis contain emojis keyed on their name
type Emojis map[string]Emoji
// Emoji contains the keywords, char and category for an emoji
type Emoji struct {
Keywords []string `json:"keywords"`
Char string `json:"char"`
Category string `json:"category"`
}
// ErrUnknownEmoji is returned from Find if provided with a unknown emoji name
var ErrUnknownEmoji = errors.New("unknown emoji")
// ErrUnknownKeyword is returned from Keyword if provided with a unknown keyword
var ErrUnknownKeyword = errors.New("unknown keyword")
// Find returns an Emoji if provided with a known name
func Find(n string) (Emoji, error) {
if e, ok := emojis[n]; ok {
return e, nil
}
return Emoji{}, ErrUnknownEmoji
}
// Keyword returns Emojis for the given keyword
func Keyword(k string) ([]Emoji, error) {
if names, ok := keywordLookup[k]; ok {
es := []Emoji{}
for _, n := range names {
es = append(es, emojis[n])
}
return es, nil
}
return []Emoji{}, ErrUnknownKeyword
}
// All returns all the emojis
func All() Emojis {
return emojis
}
// Replace takes a string and replaces all emoji names with their emoji character
func Replace(s string) string {
return emojiReplacer.Replace(s)
}
// ReplaceWithPadding takes a string and replaces all emoji names with their
// emoji character and a space in order to display better in terminals
func ReplaceWithPadding(s string) string {
return emojiPaddedReplacer.Replace(s)
}

19620
vendor/github.com/peterhellberg/emojilib/generated.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

8
vendor/manifest vendored
View File

@ -416,6 +416,14 @@
"branch": "master",
"notests": true
},
{
"importpath": "github.com/peterhellberg/emojilib",
"repository": "https://github.com/peterhellberg/emojilib",
"vcs": "git",
"revision": "41920917e2710c9f0ec22d29db182f60e7ed9d11",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/peterhellberg/giphy",
"repository": "https://github.com/peterhellberg/giphy",