-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
45 lines (34 loc) · 1.32 KB
/
utils.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
import re
from fbchat.models import ThreadType
#Class to keep state when checking if strings match regexes
#from Markus Jarderot @ https://stackoverflow.com/questions/597476
class Re(object):
def __init__(self):
self.last_match = None
def match(self,pattern,text):
self.last_match = re.match(pattern,text)
return self.last_match
def search(self,pattern,text):
self.last_match = re.search(pattern,text)
return self.last_match
#Maps ascii text to the full-width unicode variant
_WIDE_MAP = dict((i, i + 0xFEE0) for i in range(0x21, 0x7F))
_WIDE_MAP[0x20] = 0x3000
def vaporwave(text):
return text.translate(_WIDE_MAP)
#Nested dictionary setting from Bakuriu @ https://stackoverflow.com/questions/13687924
def nested_set(dic, keys, value):
for key in keys[:-1]:
dic = dic.setdefault(key, {})
dic[keys[-1]] = value
def get_name(client, author_id, thread_id, thread_type):
user = client.fetchUserInfo(author_id)[author_id]
#cache this, update on onNicknameChanged
nicknames = {}
nicknames[user.uid] = user.nickname
if thread_type == ThreadType.GROUP:
nicknames = client.fetchGroupInfo(thread_id)[thread_id].nicknames
print(nicknames)
nickname = nicknames.get(user.uid)
name = "@"+(nickname or user.first_name)
return name