This repository was archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Using Hooks to start
YinMo edited this page May 26, 2022
·
13 revisions
More convenient to manage all commands and events
from CHRLINE import * from CHRLINE.hooks import HooksTracer
cl = CHRLINE(useThrift=True)You will get a Url and Qrcode picture, login it on your LINE mobile
tracer = HooksTracer( cl, # main account prefixes=["/"], # cmd prefixes )use HooksTracer to create a new Hooks
class OpHook(object): @tracer.Operation(26) def receiveMessage(self, op, cl): msg = op.message self.trace(msg, self.HooksType["Content"], cl)create a new event in Hook, when event detect, excute bind function
ex. Operation
26
is detect receive messages, excute receiveMessage
class ContentHook(object): @tracer.Content(0) def TextMessage(self, msg, cl): text = msg.text self.trace(msg, self.HooksType['Command'], cl)create a new Message content event in Hook, when event detect, excute bind function
ex. Content
0
is text message, excute function TextMessage
class NormalCmd(object): @tracer.Command(ignoreCase=True) def hi(self, msg, cl): cl.replyMessage(msg, "Hi!")create a new Command event in Hook, when event detect, excute bind function
ex. message is
/hi
,bot can excute function hi to reply youHi!
tracer.run()
from CHRLINE import * from CHRLINE.hooks import HooksTracer cl = CHRLINE(useThrift=True) tracer = HooksTracer( cl, # main account prefixes=["/"], # cmd prefixes ) class OpHook(object): @tracer.Operation(26) def receiveMessage(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 hi(self, msg, cl): cl.replyMessage(msg, "Hi!") tracer.run()