Spaces:
Paused
Paused
Update plugins/catbox.py
Browse files- plugins/catbox.py +12 -7
plugins/catbox.py
CHANGED
@@ -4,16 +4,16 @@ 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="
|
17 |
async def catbox_upload_plugin(event):
|
18 |
"""
|
19 |
Plugin untuk mengunggah file ke Catbox.moe.
|
@@ -27,17 +27,22 @@ async def catbox_upload_plugin(event):
|
|
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 |
-
|
|
|
|
|
|
|
35 |
|
36 |
await message.edit(f"Berhasil mengunggah ke Catbox.moe!\nURL: {uploaded_url}",
|
37 |
-
file=inline_pic())
|
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
|
43 |
os.remove(filePath)
|
|
|
4 |
from catbox import CatboxUploader
|
5 |
from random import choice
|
6 |
|
7 |
+
|
8 |
+
# Inisialisasi CatboxUploader
|
9 |
cat_uploader = CatboxUploader()
|
10 |
+
# upload_file = cat_uploader.upload_file # This line is problematic if upload_file is not async
|
11 |
|
12 |
# Fungsi untuk mendapatkan gambar inline (opsional, dari kode Anda sebelumnya)
|
13 |
def inline_pic():
|
|
|
|
|
14 |
return choice(ULTROID_IMAGES)
|
15 |
|
16 |
+
@ultroid_cmd(pattern="^/uploadcat(?: |$)(.*)")
|
17 |
async def catbox_upload_plugin(event):
|
18 |
"""
|
19 |
Plugin untuk mengunggah file ke Catbox.moe.
|
|
|
27 |
return await eor(event, "Balas ke media atau file untuk mengunggahnya ke Catbox.moe.")
|
28 |
|
29 |
message = await eor(event, "Mengunduh media...")
|
30 |
+
filePath = None # Initialize filePath outside the try block
|
31 |
try:
|
32 |
filePath = await reply_message.download_media()
|
33 |
+
|
34 |
await message.edit("Mengunggah ke Catbox.moe...")
|
35 |
|
36 |
+
# <<< --- FIX IS HERE --- >>>
|
37 |
+
# Call upload_file directly without await, as it's a synchronous method.
|
38 |
+
# If it were an async method, it would be defined with 'async def'.
|
39 |
+
uploaded_url = cat_uploader.upload_file(filePath)
|
40 |
|
41 |
await message.edit(f"Berhasil mengunggah ke Catbox.moe!\nURL: {uploaded_url}",
|
42 |
+
file=inline_pic())
|
43 |
except Exception as e:
|
44 |
await message.edit(f"Terjadi kesalahan saat mengunggah: {e}")
|
45 |
finally:
|
46 |
# Hapus file lokal setelah diunggah
|
47 |
+
if filePath and os.path.exists(filePath):
|
48 |
os.remove(filePath)
|