-
Notifications
You must be signed in to change notification settings - Fork 2
/
msg.py
71 lines (65 loc) · 3.22 KB
/
msg.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
import time
import re # Regular Expression
class Msg:
def __init__(self, user, ts, text, subtype=0, **kwargs):
self.user = user
self.ts = ts
self.text = text
self.subtype = subtype
if subtype == 'message_changed':
self.edit_user = kwargs['edit_user']
self.edit_ts = kwargs['edit_ts']
def getTextAs2CH(self, dic):
self.text = re.sub('<@([A-Z0-9]+)>',
lambda x: '@{}'.format(dic[x.group(1)]), self.text)
return self.text.replace('\n', '\n\t')
def writeToFile(self, out, dic, cnt):
if self.subtype != 'bot_message':
out.write(str(cnt) + ' 名前: {0} : {1} ID:{2}\n'.format(
dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user))
if self.subtype == 'bot_message':
out.write(str(cnt) + ' BOT名前: {0} : {1} ID:{2}\n'.format(
dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user))
out.write('\t' + self.getTextAs2CH(dic) + '\n')
elif self.subtype == 'me_message':
out.write('Type: /me message')
out.write('\t' + self.getTextAs2CH(dic) + '\n')
elif self.subtype == 'message_changed':
out.write('\t' + self.getTextAs2CH(dic) + '\n')
out.write('Edited by {0} at {1}\n'.format(dic[self.edit_user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.edit_ts)))))
else:
out.write('\t' + self.getTextAs2CH(dic) + '\n')
def print_(self, dic, cnt):
if self.subtype == 'bot_message':
print(str(cnt) + ' BOT名前: {0} : {1} ID:{2}\n'.format(
dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user))
print('\t' + self.getTextAs2CH(dic) + '\n')
elif self.subtype == 'me_message':
print(str(cnt) + ' 名前: {0} : {1} ID:{2}\n'.format(dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user) +
'Type: /me message')
print('\t' + self.getTextAs2CH(dic) + '\n')
elif self.subtype == 'message_changed':
print(str(cnt) + ' 名前: {0} : {1} ID:{2}\n'.format(dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user) +
'Type: /me message')
print('\t' + self.getTextAs2CH(dic) + '\n')
print('Edited by {0} at {1}\n'.format(
dic[self.edit_user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.edit_ts)))))
else:
print(str(cnt) + ' 名前: {0} : {1} ID:{2}\n'.format(dic[self.user],
time.strftime("%Y/%m/%d %a %H:%M:%S",
time.localtime(float(self.ts))), self.user))
print('\t' + self.getTextAs2CH(dic) + '\n')