Skip to content

Commit 99b892d

Browse files
committed
change function name style
1 parent 58bc251 commit 99b892d

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

examples/advanced/room_bot.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,36 @@
2424
Hope you like it, and you are very welcome to
2525
upgrade me for more super powers!
2626
Please wait... I'm trying to login in..."""
27-
HELPER_CONTACT_NAME = '李卓桓'
27+
HELPER_CONTACT_NAME = '黄纯洪'
2828

2929
print(welcome)
3030
log = get_logger('RoomBot')
3131

3232

33-
async def checkRoomJoin(bot, room, inviteeList, inviter):
33+
async def check_room_join(bot, room, invitee_list, inviter):
3434
try:
3535
user_self = bot.user_self()
3636
if inviter.id != user_self.contact_id:
3737
await room.say('RULE1: Invitation is limited to me, the owner only. '
3838
'Please do not invite people without notify me.' + inviter)
3939
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))
4141
await room.topic('ding - warn ' + inviter.name())
4242
scheduler = AsyncIOScheduler()
43-
for i in inviteeList:
43+
for i in invitee_list:
4444
scheduler.add_job(room.delete, args=[i], seconds=10)
4545
scheduler.start()
4646
else:
4747
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))
4949
await room.topic('ding - welcome ' + welcomeTopic)
5050
except Exception as e:
5151
log.exception(e)
5252

5353

54-
async def manageDingRoom(bot):
54+
async def manage_ding_room(bot):
5555
time.sleep(3)
56-
log.info('Bot' + 'manageDingRoom()')
56+
log.info('Bot' + 'manage_ding_room()')
5757
try:
5858
room = await bot.Room.find(topic='ding')
5959
if not room:
@@ -63,7 +63,7 @@ async def manageDingRoom(bot):
6363

6464
def on_join(inviteeList, inviter):
6565
log.info('room.on(join) id:', room.room_id)
66-
checkRoomJoin(bot, room, inviteeList, inviter)
66+
check_room_join(bot, room, inviteeList, inviter)
6767

6868
def on_leave(leaverList, remover):
6969
log.info('Bot' + 'Room EVENT: leave - "%s" leave(remover "%s"), bye bye' % (','.join(leaverList),
@@ -80,8 +80,8 @@ def on_topic(topic, oldTopic, changer):
8080
log.exception(e)
8181

8282

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()))
8585
try:
8686
await room.add(contact)
8787
scheduler = AsyncIOScheduler()
@@ -91,40 +91,40 @@ async def putInRoom(contact, room):
9191
log.exception(e)
9292

9393

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))
9696
try:
9797
await room.say('You said "ding" in my room, I will remove you out.')
9898
await room.delete(contact)
9999
except Exception as e:
100-
log.exception('getOutRoom() exception: ', e)
100+
log.exception('get_out_room() exception: ', e)
101101

102102

103-
def getHelperContact(bot):
104-
log.info('Bot' + 'getHelperContact()')
103+
def get_helper_contact(bot):
104+
log.info('Bot' + 'get_helper_contact()')
105105
return bot.Contact.find(HELPER_CONTACT_NAME)
106106

107107

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)
110110
try:
111-
helperContact = await getHelperContact(bot)
111+
helperContact = await get_helper_contact(bot)
112112
if not helperContact:
113-
log.warning('getHelperContact() found nobody')
113+
log.warning('get_helper_contact() found nobody')
114114
await contact.say("""You don't have a friend called "%s", because create a new room at
115115
least need 3 contacts, please set [HELPER_CONTACT_NAME] in the code first!""" % HELPER_CONTACT_NAME)
116116
return
117-
log.info('getHelperContact() ok. got: "%s"' % helperContact.name())
117+
log.info('get_helper_contact() ok. got: "%s"' % helperContact.name())
118118
contactList = [contact, helperContact]
119119
await contact.say(
120120
"""There isn't ding room. I'm trying to create a room with "{0}" and you""" % helperContact.name())
121121
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)
123123
await room.topic('ding - created')
124124
await room.say('ding - created')
125125
return room
126126
except Exception as e:
127-
log.exception('getHelperContact() exception:', e)
127+
log.exception('get_helper_contact() exception:', e)
128128

129129

130130
class MyBot(Wechaty):
@@ -145,11 +145,11 @@ async def on_login(self, contact: Contact):
145145
log.info('bot ' + msg)
146146
await contact.say(msg)
147147

148-
msg = "setting to manageDingRoom() after 3 seconds..."
148+
msg = "setting to manage_ding_room() after 3 seconds..."
149149
log.info('Bot' + msg)
150150
print(self.user_self())
151151
await contact.say(msg)
152-
await manageDingRoom(self)
152+
await manage_ding_room(self)
153153

154154
async def on_room_join(self, room: Room, invitees: List[Contact],
155155
inviter: Contact, date: datetime):
@@ -191,7 +191,7 @@ async def on_message(self, msg: Message):
191191
if re.search('^ding$', text):
192192
if room:
193193
if re.search('^ding', await room.topic()):
194-
await getOutRoom(talker, room)
194+
await get_out_room(talker, room)
195195
else:
196196
try:
197197
dingRoom = await self.Room.find('^ding')
@@ -207,12 +207,12 @@ async def on_message(self, msg: Message):
207207
log.info('Bot' + 'onMessage: add sender("%s") to dingRoom("%s")' % (
208208
talker.name, dingRoom.topic()))
209209
await talker.say('ok, I will put you in ding room!')
210-
await putInRoom(talker, dingRoom)
210+
await put_in_room(talker, dingRoom)
211211
else:
212212
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)
216216
except Exception as e:
217217
log.exception(e)
218218

0 commit comments

Comments
 (0)