-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
71 lines (53 loc) · 1.95 KB
/
bot.py
File metadata and controls
71 lines (53 loc) · 1.95 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
# coding=utf-8
from telegram.ext import Updater, InlineQueryHandler, \
MessageHandler, CommandHandler
from telegram.ext.filters import Filters
import requests
import re
from utils import *
import logging
def start(bot, update):
start_msg = """
Hi! I am bot specifically designed to track \
and notify you about new subscribers/unsubscribers in your channel. \
Before I can do that, please do the following:
1) Add me as an admin to your channel
2) After that, send me the name/URL of your channel
"""
update.message.reply_text(start_msg)
def bop(bot, update):
channel_name = update.message.text
chat_id = update.message.chat_id
if channel_name[0] == "@":
channel_name = channel_name[1:]
if channel_name.startswith("http://"):
channel_name = channel_name[7:]
if channel_name.startswith("https://"):
channel_name = channel_name[8:]
if channel_name.startswith("t.me/"):
channel_name = channel_name[5:]
channel_name = channel_name.lower()
try:
subs = get_subscribers_list(channel_name)
try:
add_tracking_channel(chat_id, channel_name)
success = "Your channel was accepted!"
bot.send_message(chat_id=chat_id, text=success)
except Exception as err:
print(err)
channel_exist = "Are you sure you didn't add this channel before?"
bot.send_message(chat_id=chat_id, text=channel_exist)
except Exception:
admin_right = """Something went wrong. \
Are you sure bot was added as an admin \
and you gave me the right name of the channel?"""
bot.send_message(chat_id=chat_id, text=admin_right)
def main():
updater = Updater(get_token())
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start))
dp.add_handler(MessageHandler(Filters.text, bop))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()