xteamki commited on
Commit
b2ff93a
·
verified ·
1 Parent(s): 6ef54f7

Create catbox.py

Browse files
Files changed (1) hide show
  1. plugins/catbox.py +32 -150
plugins/catbox.py CHANGED
@@ -1,161 +1,43 @@
 
1
  import os
2
- import requests
3
- from telethon import TelegramClient, events, Button
4
- from . import *
5
 
6
- def upload_file(file_path):
7
- url = "https://catbox.moe/user/api.php"
8
- data = {"reqtype": "fileupload", "json": "true"}
9
- files = {"fileToUpload": open(file_path, "rb")}
10
- try:
11
- response = requests.post(url, data=data, files=files)
12
- response.raise_for_status() # Raise an exception for bad status codes
13
- return True, response.text.strip()
14
- except requests.exceptions.RequestException as e:
15
- return False, f"ᴇʀʀᴏʀ: {e}"
16
-
17
- @ultroid_cmd(pattern="tgm")
18
- async def get_link_group(event):
19
- if not event.is_reply:
20
- await event.reply("Pʟᴇᴀsᴇ ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴍᴇᴅɪᴀ ᴛᴏ ᴜᴘʟᴏᴀᴅ ᴏɴ Tᴇʟᴇɢʀᴀᴘʜ")
21
- return
22
-
23
- replied_msg = await event.get_reply_message()
24
- media = replied_msg.media
25
- if not media:
26
- await event.reply("Rᴇᴘʟɪᴇᴅ ᴍᴇssᴀɢᴇ ᴅᴏᴇs ɴᴏᴛ ᴄᴏɴᴛᴀɪɴ ᴀ ᴍᴇᴅɪᴀ ғɪʟᴇ.")
27
- return
28
-
29
- file_size = 0
30
- if replied_msg.photo:
31
- # 'sizes' adalah list, kita ambil ukuran terbesar dari list tersebut
32
- if replied_msg.photo.sizes:
33
- file_size = max(s.size for s in replied_msg.photo.sizes if hasattr(s, 'size'))
34
- elif replied_msg.video:
35
- file_size = replied_msg.video.size
36
- elif replied_msg.document:
37
- file_size = replied_msg.document.size
38
-
39
- if file_size > 200 * 1024 * 1024:
40
- await event.reply("Pʟᴇᴀsᴇ ᴘʀᴏᴠɪᴅᴇ ᴀ ᴍᴇᴅɪᴀ ғɪʟᴇ ᴜɴᴅᴇʀ 200MB.")
41
- return
42
-
43
- try:
44
- text_message = await event.reply("❍ ʜᴏʟᴅ ᴏɴ ʙᴀʙʏ....♡")
45
-
46
- async def progress(current, total):
47
- try:
48
- await event.eor(
49
- text_message, f"📥 Dᴏᴡɴʟᴏᴀᴅɪɴɢ... {current * 100 / total:.1f}%"
50
- )
51
- except Exception:
52
- pass
53
-
54
- try:
55
- local_path = await event.download_media(replied_msg, progress_callback=progress)
56
- await event.eor(text_message, "📤 Uᴘʟᴏᴀᴅɪɴɢ ᴛᴏ ᴛᴇʟᴇɢʀᴀᴘʜ...")
57
 
58
- success, upload_path = upload_file(local_path)
 
 
 
 
59
 
60
- if success:
61
- await event.eor(
62
- text_message,
63
- f"🌐 | [👉ʏᴏᴜʀ ʟɪɴᴋ ᴛᴀᴘ ʜᴇʀᴇ👈]({upload_path})",
64
- buttons=[[Button.url(" ᴛᴀᴘ ᴛᴏ sᴇᴇ ", upload_path)]],
65
- )
66
- else:
67
- await event.eor(
68
- text_message,
69
- f"ᴀɴ ᴇʀʀᴏʀ ᴏᴄᴄᴜʀʀᴇᴅ ᴡʜɪʟᴇ ᴜᴘʟᴏᴀᴅɪɴɢ ʏᴏᴜʀ ғɪʟᴇ\n{upload_path}",
70
- )
71
 
72
- try:
73
- os.remove(local_path)
74
- except Exception:
75
- pass
76
 
77
- except Exception as e:
78
- await event.eor(
79
- text_message, f"❌ Fɪʟᴇ ᴜᴘʟᴏᴀᴅ ғᴀɪʟᴇᴅ\n\n<i>Rᴇᴀsᴏɴ: {e}</i>"
80
- )
81
- try:
82
- os.remove(local_path)
83
- except Exception:
84
- pass
85
- return
86
- except Exception as e:
87
- print(f"An error occurred: {e}")
88
-
89
- @ultroid_cmd(pattern="tgh")
90
- async def get_link_group_alt(event):
91
- # This is a duplicate of the .tgm command.
92
- # You can keep it if you want two different command names for the same function.
93
- if not event.is_reply:
94
- await event.reply("Pʟᴇᴀsᴇ ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴍᴇᴅɪᴀ ᴛᴏ ᴜᴘʟᴏᴀᴅ ᴏɴ Tᴇʟᴇɢʀᴀᴘʜ")
95
- return
96
-
97
- replied_msg = await event.get_reply_message()
98
- media = replied_msg.media
99
- if not media:
100
- await event.reply("Rᴇᴘʟɪᴇᴅ ᴍᴇssᴀɢᴇ ᴅᴏᴇs ɴᴏᴛ ᴄᴏɴᴛᴀɪɴ ᴀ ᴍᴇᴅɪᴀ ғɪʟᴇ.")
101
- return
102
-
103
- file_size = 0
104
- if replied_msg.photo:
105
- # 'sizes' adalah list, kita ambil ukuran terbesar dari list tersebut
106
- if replied_msg.photo.sizes:
107
- file_size = max(s.size for s in replied_msg.photo.sizes if hasattr(s, 'size'))
108
- elif replied_msg.video:
109
- file_size = replied_msg.video.size
110
- elif replied_msg.document:
111
- file_size = replied_msg.document.size
112
-
113
- if file_size > 200 * 1024 * 1024:
114
- await event.reply("Pʟᴇᴀsᴇ ᴘʀᴏᴠɪᴅᴇ ᴀ ᴍᴇᴅɪᴀ ғɪʟᴇ ᴜɴᴅᴇʀ 200MB.")
115
- return
116
 
 
117
  try:
118
- text_message = await event.reply("❍ ʜᴏʟᴅ ᴏɴ ʙᴀʙʏ....♡")
119
-
120
- async def progress(current, total):
121
- try:
122
- await event.eor(
123
- text_message, f"📥 Dᴏᴡɴʟᴏᴀᴅɪɴɢ... {current * 100 / total:.1f}%"
124
- )
125
- except Exception:
126
- pass
127
-
128
- try:
129
- local_path = await event.download_media(replied_msg, progress_callback=progress)
130
- await event.eor(text_message, "📤 Uᴘʟᴏᴀᴅɪɴɢ ᴛᴏ ᴛᴇʟᴇɢʀᴀᴘʜ...")
131
-
132
- success, upload_path = upload_file(local_path)
133
-
134
- if success:
135
- await event.eor(
136
- text_message,
137
- f"🌐 | [👉ʏᴏᴜʀ ʟɪɴᴋ ᴛᴀᴘ ʜᴇʀᴇ👈]({upload_path})",
138
- buttons=[[Button.url(" ᴛᴀᴘ ᴛᴏ sᴇᴇ ", upload_path)]],
139
- )
140
- else:
141
- await event.eor(
142
- text_message,
143
- f"ᴀɴ ᴇʀʀᴏʀ ᴏᴄᴄᴜʀʀᴇᴅ ᴡʜɪʟᴇ ᴜᴘʟᴏᴀᴅɪɴɢ ʏᴏᴜʀ ғɪʟᴇ\n{upload_path}",
144
- )
145
 
146
- try:
147
- os.remove(local_path)
148
- except Exception:
149
- pass
150
 
151
- except Exception as e:
152
- await event.eor(
153
- text_message, f"❌ Fɪʟᴇ ᴜᴘʟᴏᴀᴅ ғᴀɪʟᴇᴅ\n\n<i>Rᴇᴀsᴏɴ: {e}</i>"
154
- )
155
- try:
156
- os.remove(local_path)
157
- except Exception:
158
- pass
159
- return
160
  except Exception as e:
161
- print(f"An error occurred: {e}")
 
 
 
 
 
1
+ import asyncio
2
  import os
3
+ from . import ultroid_cmd, eor, ULTROID_IMAGES
4
+ from catbox import CatboxUploader
5
+ from random import choice
6
 
7
+ cat_uploader = CatboxUploader()
8
+ upload_file = cat_uploader.upload_file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Fungsi untuk mendapatkan gambar inline (opsional, dari kode Anda sebelumnya)
11
+ def inline_pic():
12
+ # Anda mungkin perlu menyesuaikan bagaimana Anda mendapatkan INLINE_PIC dari database
13
+ # Untuk contoh ini, saya akan menggunakan ULTROID_IMAGES langsung
14
+ return choice(ULTROID_IMAGES)
15
 
16
+ @ultroid_cmd(pattern="catup(?: |$)(.*)")
17
+ async def catbox_upload_plugin(event):
18
+ """
19
+ Plugin untuk mengunggah file ke Catbox.moe.
20
+ """
21
+ if not event.reply_to_msg_id:
22
+ return await eor(event, "Balas ke media atau file untuk mengunggahnya ke Catbox.moe.")
 
 
 
 
23
 
24
+ reply_message = await event.get_reply_message()
 
 
 
25
 
26
+ if not reply_message.media:
27
+ return await eor(event, "Balas ke media atau file untuk mengunggahnya ke Catbox.moe.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ message = await eor(event, "Mengunduh media...")
30
  try:
31
+ filePath = await reply_message.download_media()
32
+ await message.edit("Mengunggah ke Catbox.moe...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ uploaded_url = await upload_file(filePath)
 
 
 
35
 
36
+ await message.edit(f"Berhasil mengunggah ke Catbox.moe!\nURL: {uploaded_url}",
37
+ file=inline_pic()) # Menggunakan gambar inline jika tersedia
 
 
 
 
 
 
 
38
  except Exception as e:
39
+ await message.edit(f"Terjadi kesalahan saat mengunggah: {e}")
40
+ finally:
41
+ # Hapus file lokal setelah diunggah
42
+ if 'filePath' in locals() and os.path.exists(filePath):
43
+ os.remove(filePath)