mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2024-11-16 03:45:23 +00:00
delete bad users for subscription
This commit is contained in:
parent
6a15d6a68d
commit
848ba31668
@ -195,7 +195,8 @@ class MySQL:
|
||||
create table if not exists subscribe
|
||||
(
|
||||
user_id bigint null,
|
||||
channel_id varchar(256) null
|
||||
channel_id varchar(256) null,
|
||||
is_valid boolean default 1 null
|
||||
) CHARSET=utf8mb4;
|
||||
"""
|
||||
|
||||
|
@ -187,14 +187,18 @@ class VIP(Redis, MySQL):
|
||||
|
||||
def group_subscriber(self):
|
||||
# {"channel_id": [user_id, user_id, ...]}
|
||||
self.cur.execute("select * from subscribe")
|
||||
self.cur.execute("select * from subscribe where is_valid=1")
|
||||
data = self.cur.fetchall()
|
||||
group = {}
|
||||
for item in data:
|
||||
group.setdefault(item[1], []).append(item[0])
|
||||
logging.info("Checking peroidic subscriber...")
|
||||
logging.info("Checking periodic subscriber...")
|
||||
return group
|
||||
|
||||
def deactivate_user_subscription(self, user_id: "int"):
|
||||
self.cur.execute("UPDATE subscribe set is_valid=0 WHERE user_id=%s", (user_id,))
|
||||
self.con.commit()
|
||||
|
||||
def sub_count(self):
|
||||
sql = """
|
||||
select user_id, channel.title, channel.link
|
||||
|
@ -334,14 +334,22 @@ def owner_local_callback(client: "Client", callback_query: types.CallbackQuery):
|
||||
|
||||
def periodic_sub_check():
|
||||
vip = VIP()
|
||||
exceptions = pyrogram.errors.exceptions
|
||||
for cid, uids in vip.group_subscriber().items():
|
||||
video_url = vip.has_newer_update(cid)
|
||||
if video_url:
|
||||
logging.info(f"periodic update:{video_url} - {uids}")
|
||||
for uid in uids:
|
||||
bot_msg = app.send_message(uid, f"{video_url} is downloading...", disable_web_page_preview=True)
|
||||
ytdl_download_entrance(bot_msg, app, video_url)
|
||||
time.sleep(random.random())
|
||||
try:
|
||||
bot_msg = app.send_message(uid, f"{video_url} is downloading...", disable_web_page_preview=True)
|
||||
ytdl_download_entrance(bot_msg, app, video_url)
|
||||
except(exceptions.bad_request_400.PeerIdInvalid, exceptions.bad_request_400.UserIsBlocked) as e:
|
||||
logging.warning("User is blocked or deleted. %s", e)
|
||||
vip.deactivate_user_subscription(uid)
|
||||
except Exception as e:
|
||||
logging.error("Unknown error when sending message to user. %s", e)
|
||||
finally:
|
||||
time.sleep(random.random() * 3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user