Emojify message (#65)
This commit is contained in:
parent
cf3f3e51d1
commit
68db26bcac
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@ -19,6 +19,12 @@
|
|||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "b23993cbb6353f0e6aa98d0ee318a34728f628b9"
|
revision = "b23993cbb6353f0e6aa98d0ee318a34728f628b9"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/kyokomi/emoji"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "2e9a9507333f3ee28f3fab88c2c3aba34455d734"
|
||||||
|
version = "v1.5.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/lucasb-eyer/go-colorful"
|
name = "github.com/lucasb-eyer/go-colorful"
|
||||||
@ -144,6 +150,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "2a15ea883a6ee15a2274160ad22f40976519ca0a2d15c4412c04fb02e9a31223"
|
inputs-digest = "6c0a263ebffa1c073f4b67a895832017afeab906b0d88b31da38ae22bc75e1aa"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -22,12 +22,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"maunium.net/go/gomatrix"
|
"maunium.net/go/gomatrix"
|
||||||
"maunium.net/go/gomuks/debug"
|
"maunium.net/go/gomuks/debug"
|
||||||
"maunium.net/go/gomuks/matrix/pushrules"
|
"maunium.net/go/gomuks/matrix/pushrules"
|
||||||
"maunium.net/go/gomuks/matrix/rooms"
|
"maunium.net/go/gomuks/matrix/rooms"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthCache struct {
|
type AuthCache struct {
|
||||||
@ -42,6 +43,7 @@ type UserPreferences struct {
|
|||||||
BareMessageView bool `yaml:"bare_message_view"`
|
BareMessageView bool `yaml:"bare_message_view"`
|
||||||
DisableImages bool `yaml:"disable_images"`
|
DisableImages bool `yaml:"disable_images"`
|
||||||
DisableTypingNotifs bool `yaml:"disable_typing_notifs"`
|
DisableTypingNotifs bool `yaml:"disable_typing_notifs"`
|
||||||
|
DisableEmojis bool `yaml:"disable_emojis"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config contains the main config of gomuks.
|
// Config contains the main config of gomuks.
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"gopkg.in/russross/blackfriday.v2"
|
"gopkg.in/russross/blackfriday.v2"
|
||||||
"maunium.net/go/gomatrix"
|
"maunium.net/go/gomatrix"
|
||||||
"maunium.net/go/gomuks/config"
|
"maunium.net/go/gomuks/config"
|
||||||
|
@ -19,10 +19,11 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
|
||||||
"maunium.net/go/gomuks/debug"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
|
"maunium.net/go/gomuks/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cmdMe(cmd *Command) {
|
func cmdMe(cmd *Command) {
|
||||||
@ -184,7 +185,7 @@ func cmdSetState(cmd *Command) {
|
|||||||
|
|
||||||
func cmdToggle(cmd *Command) {
|
func cmdToggle(cmd *Command) {
|
||||||
if len(cmd.Args) == 0 {
|
if len(cmd.Args) == 0 {
|
||||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif>")
|
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch cmd.Args[0] {
|
switch cmd.Args[0] {
|
||||||
@ -198,8 +199,10 @@ func cmdToggle(cmd *Command) {
|
|||||||
cmd.Config.Preferences.DisableImages = !cmd.Config.Preferences.DisableImages
|
cmd.Config.Preferences.DisableImages = !cmd.Config.Preferences.DisableImages
|
||||||
case "typingnotif":
|
case "typingnotif":
|
||||||
cmd.Config.Preferences.DisableTypingNotifs = !cmd.Config.Preferences.DisableTypingNotifs
|
cmd.Config.Preferences.DisableTypingNotifs = !cmd.Config.Preferences.DisableTypingNotifs
|
||||||
|
case "emojis":
|
||||||
|
cmd.Config.Preferences.DisableEmojis = !cmd.Config.Preferences.DisableEmojis
|
||||||
default:
|
default:
|
||||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif>")
|
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// is there a reason this is called twice?
|
// is there a reason this is called twice?
|
||||||
|
@ -21,7 +21,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/kyokomi/emoji"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"os"
|
||||||
|
|
||||||
"maunium.net/go/gomatrix"
|
"maunium.net/go/gomatrix"
|
||||||
"maunium.net/go/gomuks/config"
|
"maunium.net/go/gomuks/config"
|
||||||
"maunium.net/go/gomuks/debug"
|
"maunium.net/go/gomuks/debug"
|
||||||
@ -33,7 +37,6 @@ import (
|
|||||||
"maunium.net/go/gomuks/ui/widget"
|
"maunium.net/go/gomuks/ui/widget"
|
||||||
"maunium.net/go/tcell"
|
"maunium.net/go/tcell"
|
||||||
"maunium.net/go/tview"
|
"maunium.net/go/tview"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MainView struct {
|
type MainView struct {
|
||||||
@ -143,6 +146,9 @@ func (view *MainView) SendMessage(roomView *RoomView, text string) {
|
|||||||
func (view *MainView) sendTempMessage(roomView *RoomView, tempMessage ifc.Message, text string) {
|
func (view *MainView) sendTempMessage(roomView *RoomView, tempMessage ifc.Message, text string) {
|
||||||
defer debug.Recover()
|
defer debug.Recover()
|
||||||
debug.Print("Sending message", tempMessage.Type(), text)
|
debug.Print("Sending message", tempMessage.Type(), text)
|
||||||
|
if !roomView.config.Preferences.DisableEmojis {
|
||||||
|
text = emoji.Sprint(text)
|
||||||
|
}
|
||||||
eventID, err := view.matrix.SendMarkdownMessage(roomView.Room.ID, tempMessage.Type(), text)
|
eventID, err := view.matrix.SendMarkdownMessage(roomView.Room.ID, tempMessage.Type(), text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tempMessage.SetState(ifc.MessageStateFailed)
|
tempMessage.SetState(ifc.MessageStateFailed)
|
||||||
|
2
vendor/github.com/kyokomi/emoji/.gitignore
generated
vendored
Normal file
2
vendor/github.com/kyokomi/emoji/.gitignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
emoji.iml
|
21
vendor/github.com/kyokomi/emoji/LICENSE
generated
vendored
Normal file
21
vendor/github.com/kyokomi/emoji/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 kyokomi
|
||||||
|
|
||||||
|
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.
|
53
vendor/github.com/kyokomi/emoji/README.md
generated
vendored
Normal file
53
vendor/github.com/kyokomi/emoji/README.md
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Emoji
|
||||||
|
Emoji is a simple golang package.
|
||||||
|
|
||||||
|
[![wercker status](https://app.wercker.com/status/7bef60de2c6d3e0e6c13d56b2393c5d8/s/master "wercker status")](https://app.wercker.com/project/byKey/7bef60de2c6d3e0e6c13d56b2393c5d8)
|
||||||
|
[![Coverage Status](https://coveralls.io/repos/kyokomi/emoji/badge.png?branch=master)](https://coveralls.io/r/kyokomi/emoji?branch=master)
|
||||||
|
[![GoDoc](https://godoc.org/github.com/kyokomi/emoji?status.svg)](https://godoc.org/github.com/kyokomi/emoji)
|
||||||
|
|
||||||
|
Get it:
|
||||||
|
|
||||||
|
```
|
||||||
|
go get gopkg.in/kyokomi/emoji.v1
|
||||||
|
```
|
||||||
|
|
||||||
|
Import it:
|
||||||
|
|
||||||
|
```
|
||||||
|
import (
|
||||||
|
"gopkg.in/kyokomi/emoji.v1"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kyokomi/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Hello World Emoji!")
|
||||||
|
|
||||||
|
emoji.Println(":beer: Beer!!!")
|
||||||
|
|
||||||
|
pizzaMessage := emoji.Sprint("I like a :pizza: and :sushi:!!")
|
||||||
|
fmt.Println(pizzaMessage)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
![demo](screen/image.png)
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
- [GitHub EMOJI CHEAT SHEET](http://www.emoji-cheat-sheet.com/)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[MIT](https://github.com/kyokomi/emoji/blob/master/LICENSE)
|
153
vendor/github.com/kyokomi/emoji/emoji.go
generated
vendored
Normal file
153
vendor/github.com/kyokomi/emoji/emoji.go
generated
vendored
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// Package emoji terminal output.
|
||||||
|
package emoji
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"regexp"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate generateEmojiCodeMap -pkg emoji
|
||||||
|
|
||||||
|
// Replace Padding character for emoji.
|
||||||
|
const (
|
||||||
|
ReplacePadding = " "
|
||||||
|
)
|
||||||
|
|
||||||
|
// CodeMap gets the underlying map of emoji.
|
||||||
|
func CodeMap() map[string]string {
|
||||||
|
return emojiCodeMap
|
||||||
|
}
|
||||||
|
|
||||||
|
// regular expression that matches :flag-[countrycode]:
|
||||||
|
var flagRegexp = regexp.MustCompile(":flag-([a-z]{2}):")
|
||||||
|
|
||||||
|
func emojize(x string) string {
|
||||||
|
str, ok := emojiCodeMap[x]
|
||||||
|
if ok {
|
||||||
|
return str + ReplacePadding
|
||||||
|
}
|
||||||
|
if match := flagRegexp.FindStringSubmatch(x); len(match) == 2 {
|
||||||
|
return regionalIndicator(match[1][0]) + regionalIndicator(match[1][1])
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
// regionalIndicator maps a lowercase letter to a unicode regional indicator
|
||||||
|
func regionalIndicator(i byte) string {
|
||||||
|
return string('\U0001F1E6' + rune(i) - 'a')
|
||||||
|
}
|
||||||
|
|
||||||
|
func replaseEmoji(input *bytes.Buffer) string {
|
||||||
|
emoji := bytes.NewBufferString(":")
|
||||||
|
for {
|
||||||
|
i, _, err := input.ReadRune()
|
||||||
|
if err != nil {
|
||||||
|
// not replase
|
||||||
|
return emoji.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == ':' && emoji.Len() == 1 {
|
||||||
|
return emoji.String() + replaseEmoji(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
emoji.WriteRune(i)
|
||||||
|
switch {
|
||||||
|
case unicode.IsSpace(i):
|
||||||
|
return emoji.String()
|
||||||
|
case i == ':':
|
||||||
|
return emojize(emoji.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func compile(x string) string {
|
||||||
|
if x == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
input := bytes.NewBufferString(x)
|
||||||
|
output := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
for {
|
||||||
|
i, _, err := input.ReadRune()
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
switch i {
|
||||||
|
default:
|
||||||
|
output.WriteRune(i)
|
||||||
|
case ':':
|
||||||
|
output.WriteString(replaseEmoji(input))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func compileValues(a *[]interface{}) {
|
||||||
|
for i, x := range *a {
|
||||||
|
if str, ok := x.(string); ok {
|
||||||
|
(*a)[i] = compile(str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print is fmt.Print which supports emoji
|
||||||
|
func Print(a ...interface{}) (int, error) {
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Print(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Println is fmt.Println which supports emoji
|
||||||
|
func Println(a ...interface{}) (int, error) {
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Println(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf is fmt.Printf which supports emoji
|
||||||
|
func Printf(format string, a ...interface{}) (int, error) {
|
||||||
|
format = compile(format)
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Printf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprint is fmt.Fprint which supports emoji
|
||||||
|
func Fprint(w io.Writer, a ...interface{}) (int, error) {
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Fprint(w, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintln is fmt.Fprintln which supports emoji
|
||||||
|
func Fprintln(w io.Writer, a ...interface{}) (int, error) {
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Fprintln(w, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintf is fmt.Fprintf which supports emoji
|
||||||
|
func Fprintf(w io.Writer, format string, a ...interface{}) (int, error) {
|
||||||
|
format = compile(format)
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Fprintf(w, format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprint is fmt.Sprint which supports emoji
|
||||||
|
func Sprint(a ...interface{}) string {
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Sprint(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprintf is fmt.Sprintf which supports emoji
|
||||||
|
func Sprintf(format string, a ...interface{}) string {
|
||||||
|
format = compile(format)
|
||||||
|
compileValues(&a)
|
||||||
|
return fmt.Sprintf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf is fmt.Errorf which supports emoji
|
||||||
|
func Errorf(format string, a ...interface{}) error {
|
||||||
|
compileValues(&a)
|
||||||
|
return errors.New(Sprintf(format, a...))
|
||||||
|
}
|
1517
vendor/github.com/kyokomi/emoji/emoji_codemap.go
generated
vendored
Normal file
1517
vendor/github.com/kyokomi/emoji/emoji_codemap.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
25
vendor/github.com/kyokomi/emoji/wercker.yml
generated
vendored
Normal file
25
vendor/github.com/kyokomi/emoji/wercker.yml
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
box: golang
|
||||||
|
build:
|
||||||
|
steps:
|
||||||
|
- setup-go-workspace
|
||||||
|
- script:
|
||||||
|
name: install goveralls
|
||||||
|
code: |
|
||||||
|
go get github.com/mattn/goveralls
|
||||||
|
- script:
|
||||||
|
name: go get
|
||||||
|
code: |
|
||||||
|
go get
|
||||||
|
- script:
|
||||||
|
name: go build
|
||||||
|
code: |
|
||||||
|
go build ./...
|
||||||
|
- script:
|
||||||
|
name: go test
|
||||||
|
code: |
|
||||||
|
go test ./...
|
||||||
|
- script:
|
||||||
|
name: coveralls
|
||||||
|
code: |
|
||||||
|
goveralls -v -service wercker.com -repotoken $COVERALLS_TOKEN
|
||||||
|
|
Loading…
Reference in New Issue
Block a user