-
Notifications
You must be signed in to change notification settings - Fork 0
/
emojisign.py
62 lines (51 loc) · 2.13 KB
/
emojisign.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import glob
import socket
import re
import emoji_data_python
from slack_sdk.rtm_v2 import RTMClient
from typing import cast
from dotenv import load_dotenv
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
load_dotenv()
rtm = RTMClient(token=os.environ["SLACK_BOT_TOKEN"])
ip_address = get_ip_address()
os.system('pkill led-image-view')
os.system(f'/home/pi/rpi-rgb-led-matrix/utils/text-scroller -f /home/pi/rpi-rgb-led-matrix/fonts/9x18.bdf -s 5 -l 1 --led-rows=32 --led-cols=64 --led-chain=2 --led-pixel-mapper=V-mapper {ip_address}')
@rtm.on("message")
def handle(client: RTMClient, event: dict):
channel_id = event['channel']
thread_ts = event['ts']
user = event['user']
emoji_search = re.search('\:([0-9a-z-_+]*)\:(?:\:([0-9a-z-]*)\:)?', event['text'], re.IGNORECASE)
if emoji_search:
short_name = emoji_search.group(1)
skin_tone = emoji_search.group(2)
print(f'Name: {short_name}')
print(f'Skin tone: {skin_tone}')
custom_search = glob.glob(f'/home/pi/custom/{short_name}.*')
if custom_search:
file_name = custom_search[0]
print(f'Custom: {file_name}')
else:
try:
base_emoji = emoji_data_python.emoji_short_names[short_name]
if emoji_search.lastindex == 1:
file_name = f'/home/pi/emoji-data/img-apple-64/{base_emoji.image}'
else:
file_name = f'/home/pi/emoji-data/img-apple-64/{base_emoji.skin_variations[emoji_data_python.emoji_short_names[skin_tone].unified].image}'
print(f'Apple: {file_name}')
except:
print('emoji not known')
client.web_client.chat_postMessage(
channel=channel_id,
text=f"emojisign does not know {event['text']}",
thread_ts=thread_ts
)
if file_name:
os.system('pkill led-image-view')
os.system(f'/home/pi/rpi-rgb-led-matrix/utils/led-image-viewer --led-rows=32 --led-cols=64 --led-chain=2 --led-pixel-mapper=V-mapper --led-daemon -C {file_name}')
rtm.start()