-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
115 lines (95 loc) · 2.9 KB
/
utils.py
File metadata and controls
115 lines (95 loc) · 2.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# coding=utf-8
from pyrogram import Client
import time
from celery import Celery
import pickle
import mysql.connector
def get_token():
return ""
def get_bot_name():
return ""
def get_db_config():
config = {
'user': 'root',
'password': 'root',
'host': 'db',
'port': '3306',
'database': 'tracker',
'charset': 'utf8mb4',
'collation': 'utf8mb4_unicode_ci'
}
return config
def get_tracking_channels():
try:
config = get_db_config()
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
cursor.execute('SELECT owner, bot FROM tracker')
results = [(owner, bot) for (owner, bot) in cursor]
cursor.close()
connection.close()
return results
except Exception:
return []
def get_subs(target):
try:
config = get_db_config()
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
cursor.execute("SELECT id, name FROM subs WHERE bot='{}'".format(target))
results = []
results = [(row[0], row[1]) for row in cursor]
cursor.close()
connection.close()
return results
except Exception:
return []
def add_sub(name, target, uuid):
config = get_db_config()
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
sql = "INSERT INTO subs (name, bot, id) VALUES (%s,%s,%s)"
result = cursor.execute(sql, (name, target, uuid))
connection.commit()
cursor.close()
connection.close()
def delete_sub(uuid, target):
config = get_db_config()
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
sql = "DELETE FROM subs WHERE id=%s and bot=%s"
result = cursor.execute(sql, (uuid, target))
connection.commit()
cursor.close()
connection.close()
def add_tracking_channel(owner, bot):
config = get_db_config()
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
sql = "INSERT INTO tracker (owner, bot) VALUES ({}, '{}')"\
.format(owner, bot)
result = cursor.execute(sql)
connection.commit()
cursor.close()
connection.close()
app = Client(get_bot_name(), bot_token=get_token())
def name(member):
if isinstance(member, str):
return member
res = ""
if member.first_name:
res += member.first_name + " "
if member.last_name:
res += member.last_name + " "
if member.username:
res += "("+member.username+")"
return res
def get_all_subscribers_list(target):
bot = TelegramClient('bot', get_api_id(), get_api_hash()).start(bot_token=get_token())
with bot:
bot.connect()
res = []
all_participants = bot.get_participants(target, aggressive=True)
for user in all_participants:
res.append((user.id, name(user)))
return res