mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2024-11-16 11:52:14 +00:00
VIP limit is done
This commit is contained in:
parent
f37c57d507
commit
835feef5c9
@ -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",
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user