-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbot.py
115 lines (92 loc) · 3.4 KB
/
bot.py
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
import os
import string
import asyncio
import requests
from mdisky import Mdisk
from database.database import *
from pyrogram import Client, filters
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")
APP_ID = int(os.environ.get("APP_ID", ""))
API_HASH = os.environ.get("API_HASH", "")
#API_KEY = os.environ.get("API_KEY", "")
app = Client("tgid", bot_token=TG_BOT_TOKEN, api_hash=API_HASH, api_id=APP_ID)
@app.on_message(filters.command(['start']))
async def start(client, message):
await message.reply_text(text=f"Hello 👋\n\nI'm a telegram bot which convert MDisk link to your Link", reply_to_message_id=message.message_id)
@app.on_message(filters.command(['mdisk']))
async def mdisk(client, message):
await client.send_chat_action(message.chat.id, "typing")
mt = message.text
if (" " in message.text):
cmd, url = message.text.split(" ", 1)
caption = await get_caption(message.from_user.id)
caption_text = caption.caption
API_KEY = caption_text
mdisk = Mdisk(API_KEY)
link = await mdisk.convert(url)
await message.reply_text(text=f"{link}")
print(link)
@app.on_message(filters.command(['rename']))
async def rename(client, message):
mt = message.text
if (" " in message.text):
cmd, txt = message.text.split(" ", 1)
if ("|" in txt):
url_parts = txt.split("|")
if len(url_parts) == 2:
url = url_parts[0]
file_name = url_parts[1]
caption = await get_caption(message.from_user.id)
caption_text = caption.caption
API_KEY = caption_text
mdisk = Mdisk(API_KEY)
link = await mdisk.change_filename(url, file_name)
await message.reply_text(text=f"**New Filename:** {file_name}\n\n**URL:** {url}")
print(link)
@app.on_message(filters.command(['filename']))
async def filename(client, message):
mt = message.text
if (" " in message.text):
cmd, url = message.text.split(" ", 1)
caption = await get_caption(message.from_user.id)
caption_text = caption.caption
API_KEY = caption_text
mdisk = Mdisk(API_KEY)
filename = await mdisk.get_filename(url)
await message.reply_text(text=f"**Filename:** {filename}")
print(filename)
@app.on_message(filters.command(['auth']))
async def set_caption(client, message):
if len(message.command) == 1:
await message.reply_text(
"Use this command to set your own Mdisk Api Key \n\nEg:- `/auth your mdisk key`",
quote = True
)
else:
command, caption = message.text.split(' ', 1)
await update_caption(message.from_user.id, caption)
await message.reply_text(f"__Authorised Successfully__", quote=True)
@app.on_message(filters.command(['me']))
async def view_caption(client, message):
if (message is not None):
try:
caption = await get_caption(message.from_user.id)
caption_text = caption.caption
except:
caption_text = "Not Authorised"
await message.reply_text(
f"API KEY: {caption_text}",
quote = True
)
@app.on_message(filters.command(['unauth']))
async def view_caption(client, message):
if (message is not None):
try:
caption = await del_caption(message.from_user.id)
except:
caption_text = "Not Authorised me"
await message.reply_text(
"Unauthorised successfully",
quote = True
)
app.run()