randydev commited on
Commit
e644a22
1 Parent(s): da2517f

Create __main__.py

Browse files
Files changed (1) hide show
  1. chatbot/__main__.py +59 -0
chatbot/__main__.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright 2020-2023 (c) Randy W @xtdevs, @xtsea
4
+ #
5
+ # from : https://github.com/TeamKillerX
6
+ # Channel : @RendyProjects
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+
20
+ import asyncio
21
+ import logging
22
+ import sys
23
+ import importlib
24
+ from pyrogram import idle
25
+ import traceback
26
+
27
+ from chatbot import Randydev
28
+ from database import db
29
+ from logger import LOGS
30
+ from pyrogram.errors import *
31
+ from contextlib import closing, suppress
32
+ from uvloop import install
33
+
34
+ logging.basicConfig(level=logging.INFO)
35
+ logging.getLogger("pyrogram.syncer").setLevel(logging.WARNING)
36
+ logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
37
+ loop = asyncio.get_event_loop()
38
+
39
+ async def main():
40
+ try:
41
+ await db.connect()
42
+ randydev = Randydev(loop=loop)
43
+ await randydev.start()
44
+ await idle()
45
+ except Exception as e:
46
+ traceback.print_exc()
47
+ LOGS.error(f"Error in main: {e}")
48
+ finally:
49
+ for task in asyncio.all_tasks():
50
+ task.cancel()
51
+
52
+ LOGS.info("All tasks completed successfully!")
53
+
54
+ if __name__ == "__main__":
55
+ install()
56
+ with closing(loop):
57
+ with suppress(asyncio.exceptions.CancelledError):
58
+ loop.run_until_complete(main())
59
+ loop.run_until_complete(asyncio.sleep(3.0))