forked from JQ-Networks/UnifiedMessageRelay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cq_utils.py
206 lines (191 loc) · 4.61 KB
/
cq_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import re
from PIL import Image
from configparser import ConfigParser
import os
from urllib.request import urlretrieve
import traceback
from bot_constant import CQ_ROOT
import logging
CQ_IMAGE_ROOT = os.path.join(CQ_ROOT, r'data/image')
cq_location_regex = re.compile(r'^mqqapi:.*lat=(.*)&lon=(.*)&title=(.*)&loc=(.*)&.*$')
logger = logging.getLogger("CTBMain.cq_utils")
qq_emoji_list = { # created by JogleLew, optimizations are welcome
0: u'\U0001F62E',
1: u'\U0001F623',
2: u'\U0001F60D',
3: u'\U0001F633',
4: u'\U0001F60E',
5: u'\U0001F62D',
6: u'\U0000263A',
7: u'\U0001F637',
8: u'\U0001F634',
9: u'\U0001F62D',
10: u'\U0001F630',
11: u'\U0001F621',
12: u'\U0001F61D',
13: u'\U0001F603',
14: u'\U0001F642',
15: u'\U0001F641',
16: u'\U0001F913',
18: u'\U0001F624',
19: u'\U0001F628',
20: u'\U0001F60F',
21: u'\U0001F60A',
22: u'\U0001F644',
23: u'\U0001F615',
24: u'\U0001F924',
25: u'\U0001F62A',
26: u'\U0001F628',
27: u'\U0001F613',
28: u'\U0001F62C',
29: u'\U0001F911',
30: u'\U0001F44A',
31: u'\U0001F624',
32: u'\U0001F914',
33: u'\U0001F910',
34: u'\U0001F635',
35: u'\U0001F629',
36: u'\U0001F47F',
37: u'\U0001F480',
38: u'\U0001F915',
39: u'\U0001F44B',
50: u'\U0001F641',
51: u'\U0001F913',
53: u'\U0001F624',
54: u'\U0001F92E',
55: u'\U0001F628',
56: u'\U0001F613',
57: u'\U0001F62C',
58: u'\U0001F911',
73: u'\U0001F60F',
74: u'\U0001F60A',
75: u'\U0001F644',
76: u'\U0001F615',
77: u'\U0001F924',
78: u'\U0001F62A',
79: u'\U0001F44A',
80: u'\U0001F624',
81: u'\U0001F914',
82: u'\U0001F910',
83: u'\U0001F635',
84: u'\U0001F629',
85: u'\U0001F47F',
86: u'\U0001F480',
87: u'\U0001F915',
88: u'\U0001F44B',
96: u'\U0001F630',
97: u'\U0001F605',
98: u'\U0001F925',
99: u'\U0001F44F',
100: u'\U0001F922',
101: u'\U0001F62C',
102: u'\U0001F610',
103: u'\U0001F610',
104: u'\U0001F629',
105: u'\U0001F620',
106: u'\U0001F61E',
107: u'\U0001F61F',
108: u'\U0001F60F',
109: u'\U0001F619',
110: u'\U0001F627',
111: u'\U0001F920',
172: u'\U0001F61C',
173: u'\U0001F62D',
174: u'\U0001F636',
175: u'\U0001F609',
176: u'\U0001F913',
177: u'\U0001F635',
178: u'\U0001F61C',
179: u'\U0001F4A9',
180: u'\U0001F633',
181: u'\U0001F913',
182: u'\U0001F602',
183: u'\U0001F913',
212: u'\U0001F633',
}
qq_sface_list = {
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: '[眨眼]'
}
def create_jpg_image(path, name):
"""
convert Telegram webp image to jpg image
:param path: save path
:param name: image name
"""
im = Image.open(os.path.join(path, name)).convert("RGB")
im.save(os.path.join(path, name + ".jpg"), "JPEG")
def create_png_image(path, name):
"""
convert Telegram webp image to png image
:param path: save path
:param name: image name
"""
im = Image.open(os.path.join(path, name)).convert("RGBA")
im.save(os.path.join(path, name + ".png"), "PNG")
def cq_get_pic_url(filename):
"""
get real image url from cqimg file
:param filename:
:return: image url
"""
cqimg = os.path.join(CQ_IMAGE_ROOT, filename+'.cqimg')
parser = ConfigParser()
parser.read(cqimg)
url = parser['image']['url']
return url
def cq_download_pic(filename):
"""
download image by cqimg file
:param filename: cqimg file name
"""
try:
path = os.path.join(CQ_IMAGE_ROOT, filename)
if os.path.exists(path):
return
cqimg = os.path.join(CQ_IMAGE_ROOT, filename + '.cqimg')
parser = ConfigParser()
parser.read(cqimg)
url = parser['image']['url']
urlretrieve(url, path)
except:
logger.error(filename)
traceback.print_exc()