-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
50 lines (38 loc) · 1.18 KB
/
test.py
File metadata and controls
50 lines (38 loc) · 1.18 KB
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
import logging
import asyncio
from tbPy.bot import Bot
# from commands.leave_command import LeaveCommand
class Main(Bot):
"""
Main Constructor
"""
def __init__(self):
super().__init__()
self.version = '1.0'
self.logger = logging.getLogger('main')
# Do things
self.subscribe_events()
def start_application(self):
self.loop = asyncio.new_event_loop()
result = self.loop.run_until_complete(self.start())
# Start the bot
async def start(self):
try:
await self.start_bot()
except Exception as e:
self.logger.error(f'Main exception: {e.args}')
# Subscribe to events
def subscribe_events(self):
self.event_handler.on_message += self.on_message
##############################
# Events #
##############################
# On Message Event
def on_message(self, event_args):
message = event_args.message().text().strip()
user = event_args.user().name().lower()
message_split = message.split(' ')
# Main method
if __name__ == "__main__":
main = Main()
main.start_application()