-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (60 loc) · 1.79 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/env python
#-*-coding:UTF-8-*-
# main.py
#
# Made by LoboGuardian
# Follow me on https://github.com/LoboGuardian
"""
This is the main entry point for the Telegram bot. It sets up the bot
using the Telegram API and manages command handling.
Version Handling:
-----------------
Defines the version of the bot as a global variable.
Dependencies:
-------------
- Third-party libraries: It's using the Telegram API library to
handle messages and commands.
- Local imports: Imports configuration and command modules.
Key Functions:
--------------
1. main: Initializes the bot and sets up command handlers.
2. on_startup: Sends a notification when the bot starts.
Global Variables:
-----------------
- VERSION: The version of the bot.
- TOKEN: The API token for authenticating the bot with the Telegram API.
- COMMANDS: A list of commands supported by the bot.
Usage:
------
Run this script to start the bot.
"""
# Define the version in a variable
VERSION = "Kernel-2024.10.1"
# Third-party libraries
from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
from telegram.ext import (
ApplicationBuilder,
CallbackContext,
CommandHandler,
MessageHandler,
filters)
# Local imports
from config.auth import TOKEN
from modules.modules import *
# List of command strings
COMMANDS = [
"/start", "/help"
]
# Main function to start the bot
def main() -> None:
app = ApplicationBuilder().token(TOKEN).build()
# Register command handlers
for command in COMMANDS:
app.add_handler(CommandHandler(command[1:], globals().get(f"{command[1:]}_command")))
# Error handler
app.add_handler(MessageHandler(filters.COMMAND, unknown_handle_command))
app.add_error_handler(error_handler_command)
# Start polling
app.run_polling()
if __name__ == '__main__':
main()