VIP limit is done

This commit is contained in:
BennyThink 2022-02-03 19:53:18 +08:00
parent f37c57d507
commit 835feef5c9
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
2 changed files with 13 additions and 9 deletions

View File

@ -83,13 +83,18 @@ class VIP(Redis, MySQL):
self.r.set(user_id, user_quota - traffic, ex=EX)
def subscribe_channel(self, user_id: "int", share_link: "str"):
if ENABLE_VIP:
self.cur.execute("select count(user_id) from subscribe where user_id=%s", (user_id,))
usage = int(self.cur.fetchone()[0])
if usage >= 3 and not self.check_vip(user_id):
return "You have subscribed too many channels. Please upgrade to VIP to subscribe more channels."
data = self.get_channel_info(share_link)
self.cur.execute(
"INSERT INTO channel values(%(link)s,%(title)s,%(description)s,%(channel_id)s,%(playlist)s,%(last_video)s)",
data)
self.cur.execute("INSERT IGNORE INTO channel values("
"%(link)s,%(title)s,%(description)s,%(channel_id)s,%(playlist)s,%(last_video)s)", data)
self.cur.execute("INSERT INTO subscribe values(%s,%s)", (user_id, data["channel_id"]))
self.con.commit()
return data["title"]
return "Subscribed to {}".format(data["title"])
def unsubscribe_channel(self, user_id: "int", channel_id: "str"):
affected_rows = self.cur.execute("DELETE FROM subscribe WHERE user_id=%s AND channel_id=%s",

View File

@ -92,21 +92,20 @@ def help_handler(client: "Client", message: "types.Message"):
client.send_message(chat_id, bot_text.help, disable_web_page_preview=True)
@app.on_message(filters.command(["subscribe"]))
@app.on_message(filters.command(["sub"]))
def subscribe_handler(client: "Client", message: "types.Message"):
vip = VIP()
chat_id = message.chat.id
client.send_chat_action(chat_id, "typing")
if message.text == "/subscribe":
if message.text == "/sub":
result = vip.get_user_subscription(chat_id)
else:
link = message.text.split(" ")[1]
title = vip.subscribe_channel(chat_id, link)
result = f"Subscribed to {title}"
result = vip.subscribe_channel(chat_id, link)
client.send_message(chat_id, result, disable_web_page_preview=True)
@app.on_message(filters.command(["unsubscribe"]))
@app.on_message(filters.command(["unsub"]))
def unsubscribe_handler(client: "Client", message: "types.Message"):
vip = VIP()
chat_id = message.chat.id