-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot-offline.py
59 lines (47 loc) · 1.61 KB
/
bot-offline.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
# -*- coding: utf-8 -*-
"""
A quick script that responds to all messages that the bot is currently offline.
"""
from config import bot_token, trigger_words
import re
from telegram import (
Update,
MessageEntity,
)
from telegram.ext import (
Updater,
Filters,
CommandHandler,
MessageHandler,
CallbackContext,
)
def handle_message(update: Update, ctx: CallbackContext):
"""
Respond to all messages with a message saying that the bot is offline.
"""
bot_user = ctx.bot.get_me()
if bot_user is not None:
bot_username_fi = bot_user.first_name
bot_username_en = bot_username_fi
else:
bot_username_fi = "Botti"
bot_username_en = "The bot"
msg = f"{bot_username_fi} on huoltokatkolla. Yritä myöhemmin uudelleen.\n\n{bot_username_en} is on a maintenance break. Please try again later."
update.message.reply_text(msg)
if __name__ == "__main__":
if not bot_token:
raise ValueError("Bot token not found, check the config file")
updater = Updater(token=bot_token, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("status", handle_message))
dispatcher.add_handler(CommandHandler("help", handle_message))
trigger_words_regex = re.compile("|".join(trigger_words), re.IGNORECASE)
dispatcher.add_handler(MessageHandler(
Filters.text & (
Filters.chat_type.private # answer any messages in private chat
| Filters.regex(trigger_words_regex)
),
handle_message
))
updater.start_polling(drop_pending_updates=True)
updater.idle()