Skip to content

Commit fda0309

Browse files
authored
merging PR #61
#61 🙆‍♀️ PR passed with a vote of 20 for and 14 against, with a weighted total of 6.7 and a threshold of 1.0. Vote record: @DasSkelett: -1 @Desetude: -1 @Fang-: 1 @Firedrake969: 1 @JaredDiCioccio: -1 @ScottEfird: -1 @StephenFluin: -1 @Subzidion: 1 @chipironcin: 1 @christopherjenness: 1 @cjoh: 1 @clarkbarz: 1 @danieldiekmeier: -1 @dyc3: -1 @eq: 1 @fluecke: -1 @gandhis1: 1 @golergka: 1 @griwes: 1 @hammenm: 1 @hongaar: 1 @ifonefox: -1 @itsthejoker: -1 @jaybosamiya: 1 @lduchosal: -1 @logankp: -1 @m10s: -1 @mermaid: 1 @rwhitworth: 1 @smarlow: 1 @syntonym: -1 @webbaard: 1 @ylt: 1 @zmallen: 1
2 parents e3856c7 + adf6311 commit fda0309

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

emojis.negative

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:-1:
2+
:thumbsdown:
3+
:thumbs_down:
4+
:thumbs_down::dark_skin_tone:
5+
:thumbs_down::light_skin_tone:
6+
:thumbs_down::medium-dark_skin_tone:
7+
:thumbs_down::medium-light_skin_tone:
8+
:thumbs_down::medium_skin_tone:
9+
:confused:
10+
:confused_face:

emojis.positive

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:+1:
2+
:thumbsup:
3+
:thumbs_up:
4+
:thumbs_up::dark_skin_tone:
5+
:thumbs_up::light_skin_tone:
6+
:thumbs_up::medium-dark_skin_tone:
7+
:thumbs_up::medium-light_skin_tone:
8+
:thumbs_up::medium_skin_tone:
9+
:heart:
10+
:tada:
11+
:hooray:

github_api/voting.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from math import log
22
import arrow
33
import re
4+
from emoji import demojize
45

56
from . import prs
67
from . import comments
@@ -153,21 +154,29 @@ def parse_review_for_vote(state):
153154

154155
def parse_reaction_for_vote(body):
155156
""" turns a comment reaction into a vote, if possible """
156-
try:
157-
vote = int(body)
158-
except ValueError:
159-
vote = 0
160-
return vote
157+
return parse_emojis_for_vote(":{emoji}:".format(emoji=body))
161158

162159

163160
def parse_comment_for_vote(body):
164161
""" turns a comment into a vote, if possible """
165-
vote = 0
166-
m = re.search(":((?:\+|\-)1):", body, re.M)
167-
if m:
168-
vote = int(m.group(1))
169-
return vote
170-
162+
return parse_emojis_for_vote(demojize(body))
163+
164+
def parse_emojis_for_vote(body):
165+
""" searches text for matching emojis """
166+
for positive_emoji in prepare_emojis_list('positive'):
167+
if positive_emoji in body:
168+
return 1
169+
for negative_emoji in prepare_emojis_list('negative'):
170+
if negative_emoji in body:
171+
return -1
172+
return 0
173+
174+
def prepare_emojis_list(type):
175+
fname = "emojis.{type}".format(type=type)
176+
with open(fname) as f:
177+
content = f.readlines()
178+
content = [x.strip() for x in content]
179+
return list(filter(None, content))
171180

172181
def friendly_voting_record(votes):
173182
""" returns a sorted list (a string list, not datatype list) of voters and

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ python-dateutil==2.6.0
66
requests==2.14.2
77
sh==1.12.13
88
six==1.10.0
9+
emoji==0.4.5

0 commit comments

Comments
 (0)