-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji_parser.py
42 lines (34 loc) · 1.4 KB
/
emoji_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
class EmojiParser:
def __init__(self, slack_client):
# grabs the custom emoji list for server
self.custom_emoji_list = slack_client.api_call("emoji.list")["emoji"]
# load emojis file
with open('emoji.json') as data_file:
self.data = json.load(data_file)
def search_list(self, query_list):
result_set = list()
for query in query_list:
if query in self.custom_emoji_list:
result_set.append(query)
result_set.append(self.find_query(query))
return result_set
def format_text(self, message):
formatted_message = message.lower()
return formatted_message
def find_query(self, query):
for sub_list in self.data:
if query == sub_list["short_name"]:
return query
# temporary function
def get_fields(self, output_list):
for output in output_list:
return output['text'], output['channel'], output['ts'], output['user']
BOT_ID = 'U3YLPLY5C'
def parse_message(self, slack_message):
text, channel, timestamp, user = self.get_fields(slack_message)
text = self.format_text(text)
if text and channel and timestamp and user != self.BOT_ID:
emoji_list = self.search_list(text.split())
print(emoji_list)
return self.format_text(text), channel, timestamp, user