24
24
Hope you like it, and you are very welcome to
25
25
upgrade me for more super powers!
26
26
Please wait... I'm trying to login in..."""
27
- HELPER_CONTACT_NAME = '李卓桓 '
27
+ HELPER_CONTACT_NAME = '黄纯洪 '
28
28
29
29
print (welcome )
30
30
log = get_logger ('RoomBot' )
31
31
32
32
33
- async def checkRoomJoin (bot , room , inviteeList , inviter ):
33
+ async def check_room_join (bot , room , invitee_list , inviter ):
34
34
try :
35
35
user_self = bot .user_self ()
36
36
if inviter .id != user_self .contact_id :
37
37
await room .say ('RULE1: Invitation is limited to me, the owner only. '
38
38
'Please do not invite people without notify me.' + inviter )
39
39
await room .say ('Please contact me: by send "ding" to me, I will re-send you a invitation. '
40
- 'Now I will remove you out, sorry.' + '' .join (inviteeList ))
40
+ 'Now I will remove you out, sorry.' + '' .join (invitee_list ))
41
41
await room .topic ('ding - warn ' + inviter .name ())
42
42
scheduler = AsyncIOScheduler ()
43
- for i in inviteeList :
43
+ for i in invitee_list :
44
44
scheduler .add_job (room .delete , args = [i ], seconds = 10 )
45
45
scheduler .start ()
46
46
else :
47
47
await room .say ('Welcome to my room! :)' )
48
- welcomeTopic = ', ' .join (map (lambda c : c .name , inviteeList ))
48
+ welcomeTopic = ', ' .join (map (lambda c : c .name , invitee_list ))
49
49
await room .topic ('ding - welcome ' + welcomeTopic )
50
50
except Exception as e :
51
51
log .exception (e )
52
52
53
53
54
- async def manageDingRoom (bot ):
54
+ async def manage_ding_room (bot ):
55
55
time .sleep (3 )
56
- log .info ('Bot' + 'manageDingRoom ()' )
56
+ log .info ('Bot' + 'manage_ding_room ()' )
57
57
try :
58
58
room = await bot .Room .find (topic = 'ding' )
59
59
if not room :
@@ -63,7 +63,7 @@ async def manageDingRoom(bot):
63
63
64
64
def on_join (inviteeList , inviter ):
65
65
log .info ('room.on(join) id:' , room .room_id )
66
- checkRoomJoin (bot , room , inviteeList , inviter )
66
+ check_room_join (bot , room , inviteeList , inviter )
67
67
68
68
def on_leave (leaverList , remover ):
69
69
log .info ('Bot' + 'Room EVENT: leave - "%s" leave(remover "%s"), bye bye' % (',' .join (leaverList ),
@@ -80,8 +80,8 @@ def on_topic(topic, oldTopic, changer):
80
80
log .exception (e )
81
81
82
82
83
- async def putInRoom (contact , room ):
84
- log .info ('Bot' + 'putInRoom ("%s", "%s")' % (contact .name (), await room .topic ()))
83
+ async def put_in_room (contact , room ):
84
+ log .info ('Bot' + 'put_in_room ("%s", "%s")' % (contact .name (), await room .topic ()))
85
85
try :
86
86
await room .add (contact )
87
87
scheduler = AsyncIOScheduler ()
@@ -91,40 +91,40 @@ async def putInRoom(contact, room):
91
91
log .exception (e )
92
92
93
93
94
- async def getOutRoom (contact , room ):
95
- log .info ('Bot' + 'getOutRoom ("%s", "%s")' % (contact , room ))
94
+ async def get_out_room (contact , room ):
95
+ log .info ('Bot' + 'get_out_room ("%s", "%s")' % (contact , room ))
96
96
try :
97
97
await room .say ('You said "ding" in my room, I will remove you out.' )
98
98
await room .delete (contact )
99
99
except Exception as e :
100
- log .exception ('getOutRoom () exception: ' , e )
100
+ log .exception ('get_out_room () exception: ' , e )
101
101
102
102
103
- def getHelperContact (bot ):
104
- log .info ('Bot' + 'getHelperContact ()' )
103
+ def get_helper_contact (bot ):
104
+ log .info ('Bot' + 'get_helper_contact ()' )
105
105
return bot .Contact .find (HELPER_CONTACT_NAME )
106
106
107
107
108
- async def createDingRoom (bot , contact ):
109
- log .info ('createDingRoom ("%s")' % contact )
108
+ async def create_ding_room (bot , contact ):
109
+ log .info ('create_ding_room ("%s")' % contact )
110
110
try :
111
- helperContact = await getHelperContact (bot )
111
+ helperContact = await get_helper_contact (bot )
112
112
if not helperContact :
113
- log .warning ('getHelperContact () found nobody' )
113
+ log .warning ('get_helper_contact () found nobody' )
114
114
await contact .say ("""You don't have a friend called "%s", because create a new room at
115
115
least need 3 contacts, please set [HELPER_CONTACT_NAME] in the code first!""" % HELPER_CONTACT_NAME )
116
116
return
117
- log .info ('getHelperContact () ok. got: "%s"' % helperContact .name ())
117
+ log .info ('get_helper_contact () ok. got: "%s"' % helperContact .name ())
118
118
contactList = [contact , helperContact ]
119
119
await contact .say (
120
120
"""There isn't ding room. I'm trying to create a room with "{0}" and you""" % helperContact .name ())
121
121
room = await bot .Room .create (contactList , 'ding' )
122
- log .info ('createDingRoom () new ding room created: "%s"' % room )
122
+ log .info ('create_ding_room () new ding room created: "%s"' % room )
123
123
await room .topic ('ding - created' )
124
124
await room .say ('ding - created' )
125
125
return room
126
126
except Exception as e :
127
- log .exception ('getHelperContact () exception:' , e )
127
+ log .exception ('get_helper_contact () exception:' , e )
128
128
129
129
130
130
class MyBot (Wechaty ):
@@ -145,11 +145,11 @@ async def on_login(self, contact: Contact):
145
145
log .info ('bot ' + msg )
146
146
await contact .say (msg )
147
147
148
- msg = "setting to manageDingRoom () after 3 seconds..."
148
+ msg = "setting to manage_ding_room () after 3 seconds..."
149
149
log .info ('Bot' + msg )
150
150
print (self .user_self ())
151
151
await contact .say (msg )
152
- await manageDingRoom (self )
152
+ await manage_ding_room (self )
153
153
154
154
async def on_room_join (self , room : Room , invitees : List [Contact ],
155
155
inviter : Contact , date : datetime ):
@@ -191,7 +191,7 @@ async def on_message(self, msg: Message):
191
191
if re .search ('^ding$' , text ):
192
192
if room :
193
193
if re .search ('^ding' , await room .topic ()):
194
- await getOutRoom (talker , room )
194
+ await get_out_room (talker , room )
195
195
else :
196
196
try :
197
197
dingRoom = await self .Room .find ('^ding' )
@@ -207,12 +207,12 @@ async def on_message(self, msg: Message):
207
207
log .info ('Bot' + 'onMessage: add sender("%s") to dingRoom("%s")' % (
208
208
talker .name , dingRoom .topic ()))
209
209
await talker .say ('ok, I will put you in ding room!' )
210
- await putInRoom (talker , dingRoom )
210
+ await put_in_room (talker , dingRoom )
211
211
else :
212
212
log .info ('Bot' + 'onMessage: dingRoom not found, try to create one' )
213
- newRoom = await createDingRoom (self , talker )
214
- print ('createDingRoom id:' , newRoom .id )
215
- await manageDingRoom (self )
213
+ newRoom = await create_ding_room (self , talker )
214
+ print ('create_ding_room id:' , newRoom .id )
215
+ await manage_ding_room (self )
216
216
except Exception as e :
217
217
log .exception (e )
218
218
0 commit comments