forked from neokuze/chatango-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
44 lines (34 loc) · 1.07 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import chatango
import asyncio
import time
import typing
class Config:
user_name = ""
passwd = ""
rooms = ["asynclibraryinpython"]
pm = False
class MyBot(chatango.Client):
async def on_connect(self, room: typing.Union[chatango.Room, chatango.PM]):
print("[info] Connected to {}".format(repr(room)))
async def on_disconnect(self, room):
print("[info] Disconnected from {}".format(repr(room)))
async def on_message(self, room, message):
print(
time.strftime("%b/%d-%H:%M:%S", time.localtime(message.time)),
room.name,
message.user.showname,
ascii(message.body)[1:-1],
)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
bot = MyBot(Config.user_name, Config.passwd, Config.rooms, pm=Config.pm)
try:
loop.run_until_complete(bot.run())
except KeyboardInterrupt:
print("[KeyboardInterrupt] Killed bot.")
finally:
loop.stop()
loop.close()