Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
ce10f748
Commit
ce10f748
authored
2 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
improved the efficency of the emoji checker
parent
beaf4ced
No related branches found
No related tags found
5 merge requests
!510
Release
,
!419
rewrote the health tracker to both consider if there are waiting rounds and...
,
!371
[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast
,
!354
Channels impl
,
!340
Project/channels
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
channels/emoji.go
+21
-13
21 additions, 13 deletions
channels/emoji.go
channels/emoji_test.go
+7
-2
7 additions, 2 deletions
channels/emoji_test.go
with
28 additions
and
15 deletions
channels/emoji.go
+
21
−
13
View file @
ce10f748
...
@@ -2,35 +2,43 @@ package channels
...
@@ -2,35 +2,43 @@ package channels
import
(
import
(
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"regexp"
"regexp"
)
)
const
findEmoji
=
"(
\\\\
u00a9|
\\\\
u00ae|[
\\\\
u2000-
\\\\
u3300]|
\\\\
ud83c[
\\\\
ud000-
\\\\
udfff]|
\\\\
ud83d[
\\\\
ud000-
\\\\
udfff]|
\\\\
ud83e[
\\\\
ud000-
\\\\
udfff])"
// found at https://www.regextester.com/106421
const
findEmoji
=
`(\\u00a9|\\u00ae|[\\u2000-\\u3300]|\\ud83c[\\ud000-`
+
`\\udfff]|\\ud83d[\\ud000-\\udfff]|\\ud83e[\\ud000-\\udfff])`
var
InvalidReaction
=
errors
.
New
(
var
InvalidReaction
=
errors
.
New
(
"The reaction is not valid, it must be a single emoji"
)
"The reaction is not valid, it must be a single emoji"
)
var
compiledRegex
*
regexp
.
Regexp
// compile the regular expression in an init so it is only
// compiled once
func
init
()
{
var
err
error
compiledRegex
,
err
=
regexp
.
Compile
(
findEmoji
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"failed to compile the regex for emoji finding "
+
"within channels"
)
}
}
// ValidateReaction checks that the reaction only contains a single emoji.
// ValidateReaction checks that the reaction only contains a single emoji.
func
ValidateReaction
(
reaction
string
)
error
{
func
ValidateReaction
(
reaction
string
)
error
{
//make sure it is only only character
reactRunes
:=
[]
rune
(
reaction
)
reactRunes
:=
[]
rune
(
reaction
)
if
len
(
reactRunes
)
>
1
{
if
len
(
reactRunes
)
>
1
{
return
InvalidReaction
return
InvalidReaction
}
}
reg
,
err
:=
regexp
.
Compile
(
findEmoji
)
// make sure it is only one emoji
if
err
!=
nil
{
if
!
compiledRegex
.
Match
([]
byte
(
reaction
))
{
return
err
}
if
!
reg
.
Match
([]
byte
(
reaction
))
{
return
InvalidReaction
return
InvalidReaction
}
}
/*
fmt.Println(string(reactRunes[0]))
fmt.Println(reactRunes[1])
fmt.Println(reactRunes[2])
jww.WARN.Printf("Reaction Validation Not Yet Implemented")*/
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
channels/emoji_test.go
+
7
−
2
View file @
ce10f748
package
channels
package
channels
/*
import
(
"fmt"
"regexp"
"testing"
)
func
TestValidateReaction
(
t
*
testing
.
T
)
{
func
TestValidateReaction
(
t
*
testing
.
T
)
{
r
:=
"🍆"
r
:=
"🍆"
...
@@ -18,4 +23,4 @@ func TestValidateReaction(t *testing.T) {
...
@@ -18,4 +23,4 @@ func TestValidateReaction(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Got error: %+v"
,
err
)
t
.
Errorf
(
"Got error: %+v"
,
err
)
}
}
}
*/
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment