forked from DeachSword/CHRLINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
85 lines (64 loc) · 2.44 KB
/
example.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
from CHRLINE import *
from CHRLINE.hooks import HooksTracer
cl = CHRLINE(useThrift=True)
#cl = CHRLINE(device="IOSIPAD", version="10.21.3", os_name="iOS", os_ver="11") #with IOSIPAD
#cl = CHRLINE("your email", "your password") #with Email
#cl = CHRLINE(phone="your phone number(0911....)", region="your phone region(TW ,JP, ID..)") #with phone number
token = cl.authToken
print(f"authToken: {token}")
# #
# HooksTracer is implemented in CHRLINE v1.5.0, thanks to the code provided by Domao!
# For more detailed usage, just refer to examples/test_hooks_bot.py
# #
tracer = HooksTracer(
cl, # main account
prefixes=[""], # cmd prefixes
)
class EventHook:
@tracer.Event
def onReady():
print('Ready!')
@tracer.Event
def onInitializePushConn():
print('onInitializePushConn!')
class SquareEventHook(object):
@tracer.Before(tracer.HooksType["SquareEvent"])
def __before(self, op, cl):
pass
@tracer.SquareEvent(29)
def NOTIFICATION_MESSAGE(self, event, cl):
payload = cl.checkAndGetValue(event, 'payload', 4)
notificationMessage = cl.checkAndGetValue(payload, 'notificationMessage', 30)
squareChatMid = cl.checkAndGetValue(notificationMessage, 'squareChatMid', 1)
squareMessage = cl.checkAndGetValue(notificationMessage, 'squareMessage', 2)
senderDisplayName = cl.checkAndGetValue(notificationMessage, 'senderDisplayName', 3)
message = cl.checkAndGetValue(squareMessage, 'message', 1)
text = cl.checkAndGetValue(message, 'text', 10)
self.trace(message, self.HooksType["Content"], cl)
@tracer.After(tracer.HooksType["SquareEvent"])
def __after(self, op, cl):
print(f"{op}")
class OpHook(object):
@tracer.Operation(26)
def recvMessage(self, op, cl):
msg = op.message
self.trace(msg, self.HooksType["Content"], cl)
class ContentHook(object):
@tracer.Content(0)
def TextMessage(self, msg, cl):
text = msg.text
self.trace(msg, self.HooksType['Command'], cl)
class NormalCmd(object):
@tracer.Command(ignoreCase=True)
def ping(self, msg, cl):
'''Ping.'''
cl.replyMessage(msg, "Pong!")
@tracer.Command(ignoreCase=True)
def ping(self, msg, cl, toType=[4]):
'''Ping for OpenChat.'''
cl.replyMessage(msg, "Pong!!!")
tracer.run() # run for Talk only
# run for Square + Talk (use /PUSH path)
# tracer.run(2, **{
# 'initServices': [3, 5]
# })