Skip to content

Commit b5b185d

Browse files
committed
refactor: migrate modules to aiohttp for asynchronous requests and remove risearch module.
1 parent ce1b157 commit b5b185d

145 files changed

Lines changed: 2458 additions & 2148 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

admin/banall.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from pyrogram import Client, filters, enums
1+
import asyncio
2+
3+
from pyrogram import Client, enums, filters
24
from pyrogram.errors.exceptions.flood_420 import FloodWait
35
from pyrogram.types import *
4-
import asyncio
56
from pyrogram.types import Message
7+
68
from utils import modules_help, prefix
7-
import re
8-
import os
99

1010

1111
@Client.on_message(filters.command("banall", prefix) & filters.me)

admin/blacklist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from pyrogram import Client, filters, enums
1+
from pyrogram import Client, enums, filters
22
from pyrogram.types import Message
3+
from utils.scripts import format_exc
34

45
from utils import modules_help, prefix
5-
from utils.scripts import format_exc
66

77

88
@Client.on_message(filters.command(["block"], prefix) & filters.me)

admin/gmute.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from pyrogram import Client, filters, errors, enums
1+
from pyrogram import Client, enums, errors, filters
22
from pyrogram.types import Message
3-
from utils import modules_help, prefix
43
from utils.db import db
54

5+
from utils import modules_help, prefix
6+
67

78
def get_arg(message):
89
msg = message.text

ai/aimage.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# YOu can check it out for uses example
44
import os
55

6-
from pyrogram import Client, filters, enums
6+
from pyrogram import Client, enums, filters
77
from pyrogram.types import Message
8+
from utils.scripts import format_exc, import_library
89

910
from utils import modules_help, prefix
10-
from utils.scripts import format_exc, import_library
1111

1212
genai = import_library("google.genai", "google-genai")
1313

@@ -24,28 +24,32 @@
2424

2525
MODEL_NAME = "gemini-2.5-flash"
2626

27+
2728
@Client.on_message(filters.command("getai", prefix) & filters.me)
2829
async def getai(_, message: Message):
2930
local_file_path = None
3031
uploaded_file = None
3132
try:
3233
await message.edit_text("<code>Please Wait...</code>")
33-
34+
3435
try:
3536
if not message.reply_to_message or not message.reply_to_message.media:
36-
return await message.edit_text("<code>Please reply to an image...</code>")
37-
37+
return await message.edit_text(
38+
"<code>Please reply to an image...</code>"
39+
)
40+
3841
local_file_path = await message.reply_to_message.download()
3942
except Exception:
40-
return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
43+
return await message.edit_text(
44+
"<code>Please reply to an image or media that can be downloaded.</code>"
45+
)
4146

4247
uploaded_file = client.files.upload(file=local_file_path)
43-
48+
4449
prompt = "Get details of given image, be as accurate as possible."
4550

4651
response = client.models.generate_content(
47-
model=MODEL_NAME,
48-
contents=[prompt, uploaded_file]
52+
model=MODEL_NAME, contents=[prompt, uploaded_file]
4953
)
5054

5155
await message.edit_text(
@@ -68,34 +72,32 @@ async def aicook(_, message: Message):
6872
uploaded_file = None
6973
if not message.reply_to_message or not message.reply_to_message.media:
7074
return await message.edit_text("<code>Please reply to an image...</code>")
71-
75+
7276
try:
7377
await message.edit_text("<code>Cooking...</code>")
7478

7579
try:
7680
local_file_path = await message.reply_to_message.download()
7781
except Exception:
78-
return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
82+
return await message.edit_text(
83+
"<code>Please reply to an image or media that can be downloaded.</code>"
84+
)
7985

8086
uploaded_file = client.files.upload(file=local_file_path)
81-
87+
8288
cook_contents = [
8389
"Accurately identify the baked good in the image and provide an appropriate and recipe consistent with your analysis. ",
8490
uploaded_file,
8591
]
8692

8793
response = client.models.generate_content(
88-
model=MODEL_NAME,
89-
contents=cook_contents,
90-
config=generation_config_cook
94+
model=MODEL_NAME, contents=cook_contents, config=generation_config_cook
9195
)
9296

93-
await message.edit_text(
94-
f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN
95-
)
97+
await message.edit_text(f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN)
9698
except Exception as e:
9799
await message.edit_text(f"An error occurred: {format_exc(e)}")
98-
100+
99101
finally:
100102
if uploaded_file:
101103
client.files.delete(name=uploaded_file.name)
@@ -108,11 +110,13 @@ async def aiseller(_, message: Message):
108110
local_file_path = None
109111
uploaded_file = None
110112
if not message.reply_to_message or not message.reply_to_message.media:
111-
return await message.edit_text("<code>Please reply to a product image...</code>")
113+
return await message.edit_text(
114+
"<code>Please reply to a product image...</code>"
115+
)
112116

113117
try:
114118
await message.edit_text("<code>Generating...</code>")
115-
119+
116120
if len(message.command) > 1:
117121
taud = message.text.split(maxsplit=1)[1]
118122
else:
@@ -123,10 +127,12 @@ async def aiseller(_, message: Message):
123127
try:
124128
local_file_path = await message.reply_to_message.download()
125129
except Exception:
126-
return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
130+
return await message.edit_text(
131+
"<code>Please reply to an image or media that can be downloaded.</code>"
132+
)
127133

128134
uploaded_file = client.files.upload(file=local_file_path)
129-
135+
130136
sell_contents = [
131137
"Given an image of a product and its target audience, write an engaging marketing description",
132138
"Product Image: ",
@@ -140,18 +146,17 @@ async def aiseller(_, message: Message):
140146
contents=sell_contents,
141147
)
142148

143-
await message.edit_text(
144-
f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN
145-
)
149+
await message.edit_text(f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN)
146150
except Exception as e:
147151
await message.edit_text(f"An error occurred: {format_exc(e)}")
148-
152+
149153
finally:
150154
if uploaded_file:
151155
client.files.delete(name=uploaded_file.name)
152156
if local_file_path and os.path.exists(local_file_path):
153157
os.remove(local_file_path)
154158

159+
155160
modules_help["aimage"] = {
156161
"getai [reply to image]*": "Get details of image with Ai",
157162
"aicook [reply to image]*": "Generate Cooking instrunctions of the given food image",

ai/blackbox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import uuid
21
import re
2+
import uuid
33

44
from aiohttp import ClientSession, FormData
5-
65
from pyrogram import Client, filters
76

87
from utils import modules_help, prefix

ai/cdxl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import base64, os
1+
import base64
2+
import os
23

34
from pyrogram import Client, filters
45
from pyrogram.types import Message
6+
from utils.scripts import format_exc, import_library
57

68
from utils import modules_help, prefix
7-
from utils.scripts import format_exc, import_library
89

910
clarifai = import_library("clarifai")
1011

ai/chatbot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pyrogram import Client, enums, filters
22
from pyrogram.types import Message
3-
4-
from utils import modules_help, prefix
53
from utils.config import cohere_key
64
from utils.db import db
75
from utils.scripts import format_exc, import_library, restart
86

7+
from utils import modules_help, prefix
8+
99
cohere = import_library("cohere")
1010

1111
co = cohere.Client(cohere_key)

ai/cohere.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import asyncio
22
from json import tool
3-
from utils.scripts import import_library
3+
44
from utils.config import cohere_key
5+
from utils.scripts import import_library
56

67
cohere = import_library("cohere")
78

89
import cohere
910

1011
co = cohere.Client(cohere_key)
1112

12-
from utils import modules_help, prefix
13-
from utils.scripts import format_exc
13+
from pyrogram import Client, enums, filters
14+
from pyrogram.errors import MessageTooLong
15+
from pyrogram.types import Message
1416
from utils.db import db
1517
from utils.rentry import paste as rentry_paste
18+
from utils.scripts import format_exc
1619

17-
18-
from pyrogram import Client, filters, enums
19-
from pyrogram.types import Message
20-
from pyrogram.errors import MessageTooLong
20+
from utils import modules_help, prefix
2121

2222

2323
@Client.on_message(filters.command("cohere", prefix) & filters.me)

ai/copilot.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import aiohttp
22
from pyrogram import Client, enums, filters
33
from pyrogram.types import Message
4+
45
from utils import modules_help, prefix
56

67
COPILOT_API_URL = "https://api.deline.web.id/ai/copilot?text="
78

9+
810
async def fetch_copilot_response(query: str, message: Message, is_self: bool):
9-
response_msg = await (message.edit("<code>Thinking...</code>") if is_self else message.reply("<code>Thinking...</code>"))
11+
response_msg = await (
12+
message.edit("<code>Thinking...</code>")
13+
if is_self
14+
else message.reply("<code>Thinking...</code>")
15+
)
1016
try:
1117
async with aiohttp.ClientSession() as session:
1218
async with session.get(f"{COPILOT_API_URL}{query.strip()}") as resp:
@@ -18,9 +24,14 @@ async def fetch_copilot_response(query: str, message: Message, is_self: bool):
1824
formatted_response = "Failed to fetch a response. Please try again."
1925
if len(formatted_response) > 4000:
2026
formatted_response = formatted_response[:4000] + "…"
21-
await response_msg.edit_text(formatted_response, parse_mode=enums.ParseMode.MARKDOWN)
27+
await response_msg.edit_text(
28+
formatted_response, parse_mode=enums.ParseMode.MARKDOWN
29+
)
2230
except Exception:
23-
await response_msg.edit_text("An error occurred while connecting to the API. Please try again later.")
31+
await response_msg.edit_text(
32+
"An error occurred while connecting to the API. Please try again later."
33+
)
34+
2435

2536
@Client.on_message(filters.command("copilot", prefix))
2637
async def copilot_command(client: Client, message: Message):
@@ -29,10 +40,13 @@ async def copilot_command(client: Client, message: Message):
2940
elif len(message.command) > 1:
3041
query = " ".join(message.command[1:])
3142
else:
32-
await message.reply(f"<b>Usage:</b> <code>{prefix}copilot [prompt]</code> or reply to a message with <code>{prefix}copilot</code>")
43+
await message.reply(
44+
f"<b>Usage:</b> <code>{prefix}copilot [prompt]</code> or reply to a message with <code>{prefix}copilot</code>"
45+
)
3346
return
3447
await fetch_copilot_response(query, message, message.from_user.is_self)
3548

49+
3650
modules_help["copilot"] = {
3751
"copilot [query]*": "Ask anything to Copilot AI",
3852
}

ai/flux.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import os
21
import io
2+
import os
33
import time
4-
import requests
5-
from pyrogram import filters, Client
4+
5+
import aiohttp
6+
from pyrogram import Client, filters
67
from pyrogram.types import Message
8+
from utils.scripts import format_exc, progress
79

810
from utils import modules_help, prefix
9-
from utils.scripts import format_exc, progress
1011

1112

12-
def schellwithflux(args):
13+
async def schellwithflux(args):
1314
API_URL = "https://randydev-ryuzaki-api.hf.space/api/v1/akeno/fluxai"
1415
payload = {"user_id": 1191668125, "args": args} # Please don't edit here
15-
response = requests.post(API_URL, json=payload)
16-
if response.status_code != 200:
17-
print(f"Error status {response.status_code}")
18-
return None
19-
return response.content
16+
async with aiohttp.ClientSession() as session:
17+
async with session.post(API_URL, json=payload) as resp:
18+
if resp.status != 200:
19+
print(f"Error status {resp.status}")
20+
return None
21+
return await resp.read()
2022

2123

2224
@Client.on_message(filters.command("fluxai", prefix) & filters.me)
@@ -25,7 +27,7 @@ async def imgfluxai_(client: Client, message: Message):
2527
if not question:
2628
return await message.reply_text("Please provide a question for Flux.")
2729
try:
28-
image_bytes = schellwithflux(question)
30+
image_bytes = await schellwithflux(question)
2931
if image_bytes is None:
3032
return await message.reply_text("Failed to generate an image.")
3133
pro = await message.reply_text("Generating image, please wait...")

0 commit comments

Comments
 (0)