This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
·68 lines (52 loc) · 1.87 KB
/
bot.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
#!/usr/bin/python3
# Librerías
import logging
import sys
import os
from threading import Thread
from telegram.ext import Updater, CommandHandler, Filters
from settings import TOKEN
from modules.utils import uptime_string, query_emt
# Vars
INIT_MSG = 'Bot iniciado y listo para servir!'
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
logger = logging.getLogger(__name__)
def main():
print("Starting bot!")
updater = Updater(TOKEN, use_context=True)
dp = updater.dispatcher
# Functions
def start(update, context):
context.bot.send_message(chat_id=update.message.chat_id, text=INIT_MSG)
def stop_and_restart():
"""Gracefully stop the Updater & replace curr process with a new one"""
updater.stop()
os.execl(sys.executable, sys.executable, *sys.argv)
def restart(update, context):
update.message.reply_text('Bot is restarting...')
Thread(target=stop_and_restart).start()
def uptime(update, context):
text = uptime_string()
update.message.reply_text(text)
def emt_info(update, context):
msg = update.message.text
args = msg.strip('/emt ')
if args == "":
text = 'Uso: /emt <Parada> [<Linea>]'
else:
text = query_emt(args)
update.message.reply_text(text)
# Handlers
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler('r', restart, filters=Filters.user(username='@xTrece')))
dp.add_handler(CommandHandler("uptime", uptime))
dp.add_handler(CommandHandler("emt", emt_info))
# Start the Bot start_polling() method
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()