-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (59 loc) · 2.02 KB
/
main.py
File metadata and controls
76 lines (59 loc) · 2.02 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
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
76
import os
import sys
import time
import dotenv
import logging
import datetime
from threading import Thread
from telegram.ext import Updater, CallbackContext, CommandHandler, MessageHandler, Filters
from telegram import Update
from core.commands import start, help_cmd, about, unknown, unknown_text, get
from api_loader import AYIMAGEBOT_API_KEY
# Initialize Bot Key
API_KEY = AYIMAGEBOT_API_KEY
print("[+] APIKEY LOADED.....")
# Initializing Logger
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
print("[+] LOGGER STARTED.....")
# Check for errors
def error(update: Update, context: CallbackContext):
logger.warning('Update "%s" caused error "%s"', update, context.error)
# Stopper
def stop():
'''
This function is used to stop code in a certain amount of time
'''
# Turning off few minutes before 24 hours to restart and update code.
time.sleep(86220)
logging.shutdown()
os._exit(1)
# Main function
def main():
# Initial1ize Updater & Dispatcher
updater = Updater(token=API_KEY, use_context=True)
dispatcher = updater.dispatcher
# Syncing commands with functions
start_handler = CommandHandler('start', start)
about_handler = CommandHandler('about', about)
help_handler = CommandHandler('help', help_cmd)
get_handler = CommandHandler('get', get)
unknown_handler = MessageHandler(Filters.command, unknown)
unknown_text_handler = MessageHandler(Filters.text, unknown_text)
# Adding Handlers
dispatcher.add_handler(start_handler)
dispatcher.add_handler(about_handler)
dispatcher.add_handler(help_handler)
dispatcher.add_handler(get_handler)
dispatcher.add_error_handler(error)
dispatcher.add_handler(unknown_handler)
dispatcher.add_handler(unknown_text_handler)
# Running Threads
t1 = Thread(target = updater.start_polling)
t2 = Thread(target = stop)
t1.start()
t2.start()
updater.idle()
if __name__ == "__main__":
main()