Delete fastapi_app.py
Browse files- fastapi_app.py +0 -1693
fastapi_app.py
DELETED
@@ -1,1693 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException, Depends, Request
|
2 |
-
from fastapi.staticfiles import StaticFiles
|
3 |
-
from fastapi.templating import Jinja2Templates
|
4 |
-
from pydantic import BaseModel, Field
|
5 |
-
from bot import Bot, temp
|
6 |
-
from database.users_chats_db import db
|
7 |
-
from database.ia_filterdb import Media, get_file_details, get_search_results
|
8 |
-
from database.connections_mdb import add_connection, active_connection, all_connections, if_active, make_active, make_inactive, delete_connection
|
9 |
-
from database.filters_mdb import add_filter, find_filter, get_filters, delete_filter, del_all, count_filters, filter_stats
|
10 |
-
from database.gfilters_mdb import add_gfilter, find_gfilter, get_gfilters, delete_gfilter, del_allg, count_gfilters, gfilter_stats
|
11 |
-
from utils import get_settings, save_group_settings, humanbytes, get_size, extract_user, get_file_id, get_poster, parser, get_shortlink, extract_time, admin_check
|
12 |
-
from info import API_ID, API_HASH, BOT_TOKEN, LOG_CHANNEL, UPTIME, WEB_SUPPORT, LOG_MSG, ADMINS, CHANNELS
|
13 |
-
from pyrogram import Client, filters, enums, types
|
14 |
-
from pyrogram.errors import ChatAdminRequired, UserIsBlocked, MessageNotModified, PeerIdInvalid, FloodWait
|
15 |
-
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message, CallbackQuery
|
16 |
-
from telegraph import upload_file
|
17 |
-
from io import BytesIO
|
18 |
-
import aiohttp
|
19 |
-
import asyncio
|
20 |
-
import requests
|
21 |
-
import os
|
22 |
-
import logging
|
23 |
-
import re
|
24 |
-
import traceback
|
25 |
-
import json
|
26 |
-
from googletrans import Translator
|
27 |
-
from gtts import gTTS
|
28 |
-
from youtube_search import YoutubeSearch
|
29 |
-
from youtubesearchpython import SearchVideos
|
30 |
-
from yt_dlp import YoutubeDL
|
31 |
-
import shutil
|
32 |
-
import psutil
|
33 |
-
import wget
|
34 |
-
from datetime import datetime, timedelta
|
35 |
-
from urllib.parse import quote
|
36 |
-
from telegraph import upload_file
|
37 |
-
from PIL import Image, ImageDraw, ImageFont
|
38 |
-
import textwrap
|
39 |
-
|
40 |
-
# Initialize FastAPI
|
41 |
-
app = FastAPI()
|
42 |
-
|
43 |
-
# Configure templates and static files
|
44 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
45 |
-
templates = Jinja2Templates(directory="templates")
|
46 |
-
|
47 |
-
# Shared instance of the Bot class
|
48 |
-
bot_instance = Bot()
|
49 |
-
|
50 |
-
# Initialize Pyrogram client
|
51 |
-
@app.on_event("startup")
|
52 |
-
async def startup_event():
|
53 |
-
asyncio.create_task(bot_instance.start())
|
54 |
-
|
55 |
-
@app.on_event("shutdown")
|
56 |
-
async def shutdown_event():
|
57 |
-
await bot_instance.stop()
|
58 |
-
|
59 |
-
# Dashboard Route
|
60 |
-
@app.get("/", include_in_schema=False)
|
61 |
-
async def dashboard(request: Request):
|
62 |
-
try:
|
63 |
-
# Get statistics
|
64 |
-
total_users = await db.total_users_count()
|
65 |
-
total_chats = await db.total_chat_count()
|
66 |
-
uptime = datetime.now() - datetime.fromtimestamp(temp.UPTIME)
|
67 |
-
|
68 |
-
# System metrics
|
69 |
-
cpu = psutil.cpu_percent()
|
70 |
-
mem = psutil.virtual_memory().percent
|
71 |
-
disk = psutil.disk_usage('/').percent
|
72 |
-
|
73 |
-
return templates.TemplateResponse("dashboard.html", {
|
74 |
-
"request": request,
|
75 |
-
"total_users": total_users,
|
76 |
-
"total_chats": total_chats,
|
77 |
-
"uptime": str(uptime).split('.')[0],
|
78 |
-
"cpu_usage": f"{cpu}%",
|
79 |
-
"mem_usage": f"{mem}%",
|
80 |
-
"disk_usage": f"{disk}%",
|
81 |
-
"bot_username": (await bot_instance.get_me()).username,
|
82 |
-
"version": "PROFESSOR-BOT v4.5.0"
|
83 |
-
})
|
84 |
-
except Exception as e:
|
85 |
-
logging.error(f"Dashboard Error: {str(e)}")
|
86 |
-
return templates.TemplateResponse("error.html", {"request": request})
|
87 |
-
|
88 |
-
|
89 |
-
# Utility functions
|
90 |
-
async def get_chat_member(client, chat_id, user_id):
|
91 |
-
try:
|
92 |
-
return await client.get_chat_member(chat_id, user_id)
|
93 |
-
except Exception as e:
|
94 |
-
logger.error(f"Error getting chat member: {e}")
|
95 |
-
return None
|
96 |
-
|
97 |
-
async def send_message(client, chat_id, text, reply_markup=None, disable_web_page_preview=False):
|
98 |
-
try:
|
99 |
-
return await client.send_message(chat_id, text, reply_markup=reply_markup, disable_web_page_preview=disable_web_page_preview)
|
100 |
-
except Exception as e:
|
101 |
-
logger.error(f"Error sending message: {e}")
|
102 |
-
return None
|
103 |
-
|
104 |
-
async def edit_message(client, message, text, reply_markup=None):
|
105 |
-
try:
|
106 |
-
return await message.edit_text(text, reply_markup=reply_markup)
|
107 |
-
except Exception as e:
|
108 |
-
logger.error(f"Error editing message: {e}")
|
109 |
-
return None
|
110 |
-
|
111 |
-
async def delete_message(client, message):
|
112 |
-
try:
|
113 |
-
return await message.delete()
|
114 |
-
except Exception as e:
|
115 |
-
logger.error(f"Error deleting message: {e}")
|
116 |
-
return None
|
117 |
-
|
118 |
-
# Models
|
119 |
-
class User(BaseModel):
|
120 |
-
user_id: int
|
121 |
-
|
122 |
-
class Group(BaseModel):
|
123 |
-
group_id: int
|
124 |
-
|
125 |
-
class Filter(BaseModel):
|
126 |
-
group_id: int
|
127 |
-
text: str
|
128 |
-
reply_text: str
|
129 |
-
btn: str = Field(default=None)
|
130 |
-
file: str = Field(default=None)
|
131 |
-
alert: str = Field(default=None)
|
132 |
-
|
133 |
-
class GlobalFilter(BaseModel):
|
134 |
-
text: str
|
135 |
-
reply_text: str
|
136 |
-
btn: str = Field(default=None)
|
137 |
-
file: str = Field(default=None)
|
138 |
-
alert: str = Field(default=None)
|
139 |
-
|
140 |
-
class BroadcastMessage(BaseModel):
|
141 |
-
chat_id: int
|
142 |
-
message_id: int
|
143 |
-
|
144 |
-
class ShortenURL(BaseModel):
|
145 |
-
url: str
|
146 |
-
|
147 |
-
class SettingsUpdate(BaseModel):
|
148 |
-
group_id: int
|
149 |
-
setting_key: str
|
150 |
-
setting_value: bool
|
151 |
-
|
152 |
-
class SearchQuery(BaseModel):
|
153 |
-
query: str
|
154 |
-
file_type: str = Field(default=None)
|
155 |
-
offset: int = Field(default=0)
|
156 |
-
max_results: int = Field(default=10)
|
157 |
-
|
158 |
-
class ConnectionRequest(BaseModel):
|
159 |
-
user_id: int
|
160 |
-
group_id: int
|
161 |
-
|
162 |
-
class TextToSpeechRequest(BaseModel):
|
163 |
-
text: str
|
164 |
-
|
165 |
-
class YouTubeDownloadRequest(BaseModel):
|
166 |
-
url: str
|
167 |
-
|
168 |
-
class TelegraphUploadRequest(BaseModel):
|
169 |
-
file_path: str
|
170 |
-
|
171 |
-
class CarbonRequest(BaseModel):
|
172 |
-
text: str
|
173 |
-
|
174 |
-
class FontRequest(BaseModel):
|
175 |
-
text: str
|
176 |
-
style: str
|
177 |
-
|
178 |
-
class PasteRequest(BaseModel):
|
179 |
-
text: str
|
180 |
-
|
181 |
-
class ShareTextRequest(BaseModel):
|
182 |
-
text: str
|
183 |
-
|
184 |
-
class GroupManagerAction(BaseModel):
|
185 |
-
action: str
|
186 |
-
user_id: int = Field(default=None)
|
187 |
-
time: str = Field(default=None)
|
188 |
-
message_id: int = Field(default=None)
|
189 |
-
|
190 |
-
# Endpoints
|
191 |
-
@app.get("/uptime")
|
192 |
-
async def get_uptime():
|
193 |
-
uptime = datetime.now() - datetime.fromtimestamp(temp.UPTIME)
|
194 |
-
return {"uptime": str(uptime)}
|
195 |
-
|
196 |
-
@app.get("/stats")
|
197 |
-
async def get_stats():
|
198 |
-
total_users = await db.total_users_count()
|
199 |
-
total_chats = await db.total_chat_count()
|
200 |
-
return {"total_users": total_users, "total_chats": total_chats}
|
201 |
-
|
202 |
-
@app.post("/ban_user")
|
203 |
-
async def ban_user_endpoint(user: User):
|
204 |
-
await db.ban_user(user.user_id, "No Reason")
|
205 |
-
temp.BANNED_USERS.append(user.user_id)
|
206 |
-
return {"status": "User banned successfully"}
|
207 |
-
|
208 |
-
@app.post("/unban_user")
|
209 |
-
async def unban_user_endpoint(user: User):
|
210 |
-
await db.remove_ban(user.user_id)
|
211 |
-
temp.BANNED_USERS.remove(user.user_id)
|
212 |
-
return {"status": "User unbanned successfully"}
|
213 |
-
|
214 |
-
@app.post("/add_filter")
|
215 |
-
async def add_filter_endpoint(filter_data: Filter):
|
216 |
-
await add_filter(filter_data.group_id, filter_data.text, filter_data.reply_text, filter_data.btn, filter_data.file, filter_data.alert)
|
217 |
-
return {"status": "Filter added successfully"}
|
218 |
-
|
219 |
-
@app.post("/find_filter")
|
220 |
-
async def find_filter_endpoint(filter_data: Filter):
|
221 |
-
reply_text, btn, alert, fileid = await find_filter(filter_data.group_id, filter_data.text)
|
222 |
-
return {"reply_text": reply_text, "btn": btn, "alert": alert, "fileid": fileid}
|
223 |
-
|
224 |
-
@app.post("/get_filters")
|
225 |
-
async def get_filters_endpoint(group_id: int):
|
226 |
-
texts = await get_filters(group_id)
|
227 |
-
return {"filters": texts}
|
228 |
-
|
229 |
-
@app.post("/delete_filter")
|
230 |
-
async def delete_filter_endpoint(filter_data: Filter):
|
231 |
-
await delete_filter(None, filter_data.text, filter_data.group_id)
|
232 |
-
return {"status": "Filter deleted successfully"}
|
233 |
-
|
234 |
-
@app.post("/del_all_filters")
|
235 |
-
async def del_all_filters_endpoint(group_id: int):
|
236 |
-
await del_all(None, group_id, "Group")
|
237 |
-
return {"status": "All filters deleted successfully"}
|
238 |
-
|
239 |
-
@app.post("/add_gfilter")
|
240 |
-
async def add_gfilter_endpoint(gfilter_data: GlobalFilter):
|
241 |
-
await add_gfilter('gfilters', gfilter_data.text, gfilter_data.reply_text, gfilter_data.btn, gfilter_data.file, gfilter_data.alert)
|
242 |
-
return {"status": "Global filter added successfully"}
|
243 |
-
|
244 |
-
@app.post("/find_gfilter")
|
245 |
-
async def find_gfilter_endpoint(gfilter_data: GlobalFilter):
|
246 |
-
reply_text, btn, alert, fileid = await find_gfilter('gfilters', gfilter_data.text)
|
247 |
-
return {"reply_text": reply_text, "btn": btn, "alert": alert, "fileid": fileid}
|
248 |
-
|
249 |
-
@app.post("/get_gfilters")
|
250 |
-
async def get_gfilters_endpoint():
|
251 |
-
texts = await get_gfilters('gfilters')
|
252 |
-
return {"global_filters": texts}
|
253 |
-
|
254 |
-
@app.post("/delete_gfilter")
|
255 |
-
async def delete_gfilter_endpoint(gfilter_data: GlobalFilter):
|
256 |
-
await delete_gfilter(None, gfilter_data.text, 'gfilters')
|
257 |
-
return {"status": "Global filter deleted successfully"}
|
258 |
-
|
259 |
-
@app.post("/del_all_gfilters")
|
260 |
-
async def del_all_gfilters_endpoint():
|
261 |
-
await del_allg(None, 'gfilters')
|
262 |
-
return {"status": "All global filters deleted successfully"}
|
263 |
-
|
264 |
-
@app.post("/broadcast")
|
265 |
-
async def broadcast_endpoint(broadcast_data: BroadcastMessage):
|
266 |
-
users = await db.get_all_users()
|
267 |
-
b_msg = await bot_instance.get_messages(broadcast_data.chat_id, broadcast_data.message_id)
|
268 |
-
sts = await send_message(bot_instance, broadcast_data.chat_id, "Broadcasting your messages...")
|
269 |
-
start_time = time.time()
|
270 |
-
total_users = await db.total_users_count()
|
271 |
-
done = 0
|
272 |
-
blocked = 0
|
273 |
-
deleted = 0
|
274 |
-
failed = 0
|
275 |
-
success = 0
|
276 |
-
async for user in users:
|
277 |
-
pti, sh = await broadcast_messages(int(user['id']), b_msg)
|
278 |
-
if pti:
|
279 |
-
success += 1
|
280 |
-
elif pti == False:
|
281 |
-
if sh == "Blocked":
|
282 |
-
blocked += 1
|
283 |
-
elif sh == "Deleted":
|
284 |
-
deleted += 1
|
285 |
-
elif sh == "Error":
|
286 |
-
failed += 1
|
287 |
-
done += 1
|
288 |
-
if not done % 20:
|
289 |
-
await edit_message(bot_instance, sts, f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
|
290 |
-
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
291 |
-
await delete_message(bot_instance, sts)
|
292 |
-
await send_message(bot_instance, broadcast_data.chat_id, f"Broadcast completed:\nTime taken: {time_taken}\n\nTotal Users: {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
|
293 |
-
return {"status": "Broadcast completed"}
|
294 |
-
|
295 |
-
@app.post("/clear_junk")
|
296 |
-
async def clear_junk_endpoint(user_id: int):
|
297 |
-
sts = await send_message(bot_instance, user_id, "Clearing junk users...")
|
298 |
-
start_time = time.time()
|
299 |
-
total_users = await db.total_users_count()
|
300 |
-
blocked = 0
|
301 |
-
deleted = 0
|
302 |
-
failed = 0
|
303 |
-
done = 0
|
304 |
-
async for user in db.get_all_users():
|
305 |
-
pti, sh = await clear_junk(int(user['id']), None)
|
306 |
-
if pti == False:
|
307 |
-
if sh == "Blocked":
|
308 |
-
blocked += 1
|
309 |
-
elif sh == "Deleted":
|
310 |
-
deleted += 1
|
311 |
-
elif sh == "Error":
|
312 |
-
failed += 1
|
313 |
-
done += 1
|
314 |
-
if not done % 20:
|
315 |
-
await edit_message(bot_instance, sts, f"Clearing junk in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nBlocked: {blocked}\nDeleted: {deleted}")
|
316 |
-
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
317 |
-
await delete_message(bot_instance, sts)
|
318 |
-
await send_message(bot_instance, user_id, f"Clearing junk completed:\nTime taken: {time_taken}\n\nTotal Users: {total_users}\nCompleted: {done} / {total_users}\nBlocked: {blocked}\nDeleted: {deleted}")
|
319 |
-
return {"status": "Junk clearing completed"}
|
320 |
-
|
321 |
-
@app.post("/group_broadcast")
|
322 |
-
async def group_broadcast_endpoint(broadcast_data: BroadcastMessage):
|
323 |
-
groups = await db.get_all_chats()
|
324 |
-
b_msg = await bot_instance.get_messages(broadcast_data.chat_id, broadcast_data.message_id)
|
325 |
-
sts = await send_message(bot_instance, broadcast_data.chat_id, "Broadcasting to groups...")
|
326 |
-
start_time = time.time()
|
327 |
-
total_groups = await db.total_chat_count()
|
328 |
-
done = 0
|
329 |
-
failed = ""
|
330 |
-
success = 0
|
331 |
-
deleted = 0
|
332 |
-
async for group in groups:
|
333 |
-
pti, sh, ex = await broadcast_messages_group(int(group['id']), b_msg)
|
334 |
-
if pti == True:
|
335 |
-
if sh == "Success":
|
336 |
-
success += 1
|
337 |
-
elif pti == False:
|
338 |
-
if sh == "deleted":
|
339 |
-
deleted += 1
|
340 |
-
failed += ex
|
341 |
-
try:
|
342 |
-
await bot_instance.leave_chat(int(group['id']))
|
343 |
-
except Exception as e:
|
344 |
-
logger.error(f"{e} > {group['id']}")
|
345 |
-
done += 1
|
346 |
-
if not done % 20:
|
347 |
-
await edit_message(bot_instance, sts, f"Broadcast in progress:\n\nTotal Groups {total_groups}\nCompleted: {done} / {total_groups}\nSuccess: {success}\nDeleted: {deleted}")
|
348 |
-
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
349 |
-
await delete_message(bot_instance, sts)
|
350 |
-
await send_message(bot_instance, broadcast_data.chat_id, f"Broadcast completed:\nTime taken: {time_taken}\n\nTotal Groups: {total_groups}\nCompleted: {done} / {total_groups}\nSuccess: {success}\nDeleted: {deleted}\n\nFailed reasons: {failed}")
|
351 |
-
return {"status": "Group broadcast completed"}
|
352 |
-
|
353 |
-
@app.post("/junk_group")
|
354 |
-
async def junk_group_endpoint(user_id: int):
|
355 |
-
groups = await db.get_all_chats()
|
356 |
-
sts = await send_message(bot_instance, user_id, "Clearing junk groups...")
|
357 |
-
start_time = time.time()
|
358 |
-
total_groups = await db.total_chat_count()
|
359 |
-
done = 0
|
360 |
-
failed = ""
|
361 |
-
deleted = 0
|
362 |
-
async for group in groups:
|
363 |
-
pti, sh, ex = await junk_group(int(group['id']), None)
|
364 |
-
if pti == False:
|
365 |
-
if sh == "deleted":
|
366 |
-
deleted += 1
|
367 |
-
failed += ex
|
368 |
-
try:
|
369 |
-
await bot_instance.leave_chat(int(group['id']))
|
370 |
-
except Exception as e:
|
371 |
-
logger.error(f"{e} > {group['id']}")
|
372 |
-
done += 1
|
373 |
-
if not done % 20:
|
374 |
-
await edit_message(bot_instance, sts, f"Clearing junk in progress:\n\nTotal Groups {total_groups}\nCompleted: {done} / {total_groups}\nDeleted: {deleted}")
|
375 |
-
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
376 |
-
await delete_message(bot_instance, sts)
|
377 |
-
await send_message(bot_instance, user_id, f"Clearing junk completed:\nTime taken: {time_taken}\n\nTotal Groups: {total_groups}\nCompleted: {done} / {total_groups}\nDeleted: {deleted}\n\nFailed reasons: {failed}")
|
378 |
-
return {"status": "Junk group clearing completed"}
|
379 |
-
|
380 |
-
@app.post("/add_connection")
|
381 |
-
async def add_connection_endpoint(connection_request: ConnectionRequest):
|
382 |
-
result = await add_connection(connection_request.group_id, connection_request.user_id)
|
383 |
-
return {"status": "Connection added successfully" if result else "Connection already exists"}
|
384 |
-
|
385 |
-
@app.post("/active_connection")
|
386 |
-
async def active_connection_endpoint(user_id: int):
|
387 |
-
group_id = await active_connection(user_id)
|
388 |
-
return {"active_group_id": group_id}
|
389 |
-
|
390 |
-
@app.post("/all_connections")
|
391 |
-
async def all_connections_endpoint(user_id: int):
|
392 |
-
group_ids = await all_connections(user_id)
|
393 |
-
return {"group_ids": group_ids}
|
394 |
-
|
395 |
-
@app.post("/if_active")
|
396 |
-
async def if_active_endpoint(connection_request: ConnectionRequest):
|
397 |
-
result = await if_active(connection_request.user_id, connection_request.group_id)
|
398 |
-
return {"is_active": result}
|
399 |
-
|
400 |
-
@app.post("/make_active")
|
401 |
-
async def make_active_endpoint(connection_request: ConnectionRequest):
|
402 |
-
result = await make_active(connection_request.user_id, connection_request.group_id)
|
403 |
-
return {"status": "Made active successfully" if result else "Failed to make active"}
|
404 |
-
|
405 |
-
@app.post("/make_inactive")
|
406 |
-
async def make_inactive_endpoint(user_id: int):
|
407 |
-
result = await make_inactive(user_id)
|
408 |
-
return {"status": "Made inactive successfully" if result else "Failed to make inactive"}
|
409 |
-
|
410 |
-
@app.post("/delete_connection")
|
411 |
-
async def delete_connection_endpoint(connection_request: ConnectionRequest):
|
412 |
-
result = await delete_connection(connection_request.user_id, connection_request.group_id)
|
413 |
-
return {"status": "Connection deleted successfully" if result else "Failed to delete connection"}
|
414 |
-
|
415 |
-
@app.post("/search")
|
416 |
-
async def search_endpoint(search_query: SearchQuery):
|
417 |
-
files, next_offset, total_results = await get_search_results(search_query.query, file_type=search_query.file_type, offset=search_query.offset, max_results=search_query.max_results)
|
418 |
-
return {"files": [file.dict() for file in files], "next_offset": next_offset, "total_results": total_results}
|
419 |
-
|
420 |
-
@app.post("/get_file_details")
|
421 |
-
async def get_file_details_endpoint(file_id: str):
|
422 |
-
file_details = await get_file_details(file_id)
|
423 |
-
if file_details:
|
424 |
-
return {"file_details": [file.dict() for file in file_details]}
|
425 |
-
return {"file_details": None}
|
426 |
-
|
427 |
-
@app.post("/get_settings")
|
428 |
-
async def get_settings_endpoint(group_id: int):
|
429 |
-
settings = await get_settings(group_id)
|
430 |
-
return {"settings": settings}
|
431 |
-
|
432 |
-
@app.post("/save_group_settings")
|
433 |
-
async def save_group_settings_endpoint(settings_update: SettingsUpdate):
|
434 |
-
await save_group_settings(settings_update.group_id, settings_update.setting_key, settings_update.setting_value)
|
435 |
-
return {"status": "Settings updated successfully"}
|
436 |
-
|
437 |
-
@app.post("/send_cached_media")
|
438 |
-
async def send_cached_media_endpoint(chat_id: int, file_id: str, caption: str = None, protect_content: bool = False):
|
439 |
-
await bot_instance.send_cached_media(chat_id=chat_id, file_id=file_id, caption=caption, protect_content=protect_content)
|
440 |
-
return {"status": "Media sent successfully"}
|
441 |
-
|
442 |
-
@app.post("/get_poster")
|
443 |
-
async def get_poster_endpoint(query: str, id: bool = False, file: str = None):
|
444 |
-
poster = await get_poster(query, bulk=False, id=id, file=file)
|
445 |
-
return {"poster": poster}
|
446 |
-
|
447 |
-
@app.post("/parse_text")
|
448 |
-
async def parse_text_endpoint(text: str, keyword: str, cb_data: str):
|
449 |
-
note_data, buttons, alerts = parser(text, keyword, cb_data)
|
450 |
-
return {"note_data": note_data, "buttons": buttons, "alerts": alerts}
|
451 |
-
|
452 |
-
@app.post("/get_shortlink")
|
453 |
-
async def get_shortlink_endpoint(shorten_url: ShortenURL):
|
454 |
-
short_url = await get_shortlink(shorten_url.url)
|
455 |
-
return {"short_url": short_url}
|
456 |
-
|
457 |
-
@app.post("/extract_time")
|
458 |
-
async def extract_time_endpoint(time_val: str):
|
459 |
-
extracted_time = extract_time(time_val)
|
460 |
-
return {"extracted_time": extracted_time}
|
461 |
-
|
462 |
-
@app.post("/admin_check")
|
463 |
-
async def admin_check_endpoint(chat_id: int, user_id: int):
|
464 |
-
is_admin = await admin_check(Message(chat_id=chat_id, from_user=types.User(id=user_id)))
|
465 |
-
return {"is_admin": is_admin}
|
466 |
-
|
467 |
-
@app.post("/auto_filter")
|
468 |
-
async def auto_filter_endpoint(query: str, chat_id: int, user_id: int, offset: int = 0, max_results: int = 10):
|
469 |
-
files, next_offset, total_results = await get_search_results(query, offset=offset, max_results=max_results)
|
470 |
-
if not files:
|
471 |
-
return {"status": "No files found"}
|
472 |
-
pre = 'filep' if await get_settings(chat_id)['file_secure'] else 'file'
|
473 |
-
btn = []
|
474 |
-
for file in files:
|
475 |
-
btn.append([
|
476 |
-
InlineKeyboardButton(text=f"[{humanbytes(file.file_size)}] {file.file_name}", callback_data=f'{pre}#{user_id}#{file.file_id}')
|
477 |
-
])
|
478 |
-
btn.append([InlineKeyboardButton(text="🔗 How to download 🔗", callback_data="howdl")])
|
479 |
-
reply_markup = InlineKeyboardMarkup(btn)
|
480 |
-
return {"files": [file.dict() for file in files], "next_offset": next_offset, "total_results": total_results, "reply_markup": reply_markup.dict()}
|
481 |
-
|
482 |
-
@app.post("/send_telegram_message")
|
483 |
-
async def send_telegram_message_endpoint(chat_id: int, text: str):
|
484 |
-
message = await send_message(bot_instance, chat_id, text)
|
485 |
-
return {"message_id": message.id}
|
486 |
-
|
487 |
-
@app.post("/edit_telegram_message")
|
488 |
-
async def edit_telegram_message_endpoint(chat_id: int, message_id: int, text: str):
|
489 |
-
message = await bot_instance.get_messages(chat_id, message_id)
|
490 |
-
edited_message = await edit_message(bot_instance, message, text)
|
491 |
-
return {"edited_message_id": edited_message.id}
|
492 |
-
|
493 |
-
@app.post("/delete_telegram_message")
|
494 |
-
async def delete_telegram_message_endpoint(chat_id: int, message_id: int):
|
495 |
-
message = await bot_instance.get_messages(chat_id, message_id)
|
496 |
-
await delete_message(bot_instance, message)
|
497 |
-
return {"status": "Message deleted successfully"}
|
498 |
-
|
499 |
-
@app.post("/carbon")
|
500 |
-
async def carbon_endpoint(carbon_request: CarbonRequest):
|
501 |
-
carbon_image = await make_carbon(carbon_request.text, True)
|
502 |
-
return {"carbon_url": carbon_image}
|
503 |
-
|
504 |
-
async def make_carbon(text, tele=False):
|
505 |
-
url = "https://carbonara.solopov.dev/api/cook"
|
506 |
-
async with aiohttp.ClientSession() as session:
|
507 |
-
async with session.post(url, json={"code": text}) as resp:
|
508 |
-
image = BytesIO(await resp.read())
|
509 |
-
image.name = "carbon.png"
|
510 |
-
if tele:
|
511 |
-
uf = upload_file(image)
|
512 |
-
image.close()
|
513 |
-
return f"https://graph.org{uf[0]}"
|
514 |
-
return image
|
515 |
-
|
516 |
-
@app.post("/font")
|
517 |
-
async def font_endpoint(font_request: FontRequest):
|
518 |
-
fonts = {
|
519 |
-
"typewriter": Fonts.typewriter,
|
520 |
-
"outline": Fonts.outline,
|
521 |
-
"serif": Fonts.serief,
|
522 |
-
"bold_cool": Fonts.bold_cool,
|
523 |
-
"cool": Fonts.cool,
|
524 |
-
"small_cap": Fonts.smallcap,
|
525 |
-
"script": Fonts.script,
|
526 |
-
"bold_script": Fonts.bold_script,
|
527 |
-
"tiny": Fonts.tiny,
|
528 |
-
"comic": Fonts.comic,
|
529 |
-
"san": Fonts.san,
|
530 |
-
"slant_san": Fonts.slant_san,
|
531 |
-
"slant": Fonts.slant,
|
532 |
-
"sim": Fonts.sim,
|
533 |
-
"circles": Fonts.circles,
|
534 |
-
"dark_circle": Fonts.dark_circle,
|
535 |
-
"gothic": Fonts.gothic,
|
536 |
-
"bold_gothic": Fonts.bold_gothic,
|
537 |
-
"cloud": Fonts.cloud,
|
538 |
-
"happy": Fonts.happy,
|
539 |
-
"sad": Fonts.sad,
|
540 |
-
"special": Fonts.special,
|
541 |
-
"square": Fonts.square,
|
542 |
-
"dark_square": Fonts.dark_square,
|
543 |
-
"andalucia": Fonts.andalucia,
|
544 |
-
"manga": Fonts.manga,
|
545 |
-
"stinky": Fonts.stinky,
|
546 |
-
"bubbles": Fonts.bubbles,
|
547 |
-
"underline": Fonts.underline,
|
548 |
-
"ladybug": Fonts.ladybug,
|
549 |
-
"rays": Fonts.rays,
|
550 |
-
"birds": Fonts.birds,
|
551 |
-
"slash": Fonts.slash,
|
552 |
-
"stop": Fonts.stop,
|
553 |
-
"skyline": Fonts.skyline,
|
554 |
-
"arrows": Fonts.arrows,
|
555 |
-
"rvnes": Fonts.rvnes,
|
556 |
-
"strike": Fonts.strike,
|
557 |
-
"frozen": Fonts.frozen
|
558 |
-
}
|
559 |
-
cls = fonts.get(font_request.style)
|
560 |
-
if not cls:
|
561 |
-
return {"error": "Invalid style"}
|
562 |
-
new_text = cls(font_request.text)
|
563 |
-
return {"new_text": new_text}
|
564 |
-
|
565 |
-
@app.post("/paste")
|
566 |
-
async def paste_endpoint(paste_request: PasteRequest):
|
567 |
-
paste_response = await p_paste(paste_request.text)
|
568 |
-
return paste_response
|
569 |
-
|
570 |
-
async def p_paste(code, extension=None):
|
571 |
-
siteurl = "https://pasty.lus.pm/api/v1/pastes"
|
572 |
-
data = {"content": code}
|
573 |
-
try:
|
574 |
-
response = requests.post(url=siteurl, data=json.dumps(data), headers={"User-Agent": "Mozilla/5.0", "content-type": "application/json"})
|
575 |
-
except Exception as e:
|
576 |
-
return {"error": str(e)}
|
577 |
-
if response.ok:
|
578 |
-
response = response.json()
|
579 |
-
purl = (
|
580 |
-
f"https://pasty.lus.pm/{response['id']}.{extension}"
|
581 |
-
if extension
|
582 |
-
else f"https://pasty.lus.pm/{response['id']}.txt"
|
583 |
-
)
|
584 |
-
return {
|
585 |
-
"url": purl,
|
586 |
-
"raw": f"https://pasty.lus.pm/{response['id']}/raw",
|
587 |
-
"bin": "Pasty",
|
588 |
-
}
|
589 |
-
return {"error": "Unable to reach pasty.lus.pm"}
|
590 |
-
|
591 |
-
@app.post("/share_text")
|
592 |
-
async def share_text_endpoint(share_request: ShareTextRequest):
|
593 |
-
share_url = f"https://t.me/share/url?url={quote(share_request.text)}"
|
594 |
-
return {"share_url": share_url}
|
595 |
-
|
596 |
-
@app.post("/telegraph_upload")
|
597 |
-
async def telegraph_upload_endpoint(upload_request: TelegraphUploadRequest):
|
598 |
-
try:
|
599 |
-
response = upload_file(upload_request.file_path)
|
600 |
-
except Exception as e:
|
601 |
-
logger.error(f"Error uploading to Telegraph: {e}")
|
602 |
-
return {"error": str(e)}
|
603 |
-
telegraph_url = f"https://graph.org{response[0]}"
|
604 |
-
return {"telegraph_url": telegraph_url}
|
605 |
-
|
606 |
-
@app.post("/text_to_speech")
|
607 |
-
async def text_to_speech_endpoint(tts_request: TextToSpeechRequest):
|
608 |
-
audio = await convert(tts_request.text)
|
609 |
-
return {"audio_url": audio.name}
|
610 |
-
|
611 |
-
async def convert(text):
|
612 |
-
audio = BytesIO()
|
613 |
-
i = Translator().translate(text, dest="en")
|
614 |
-
lang = i.src
|
615 |
-
tts = gTTS(text, lang=lang)
|
616 |
-
audio.name = lang + ".mp3"
|
617 |
-
tts.write_to_fp(audio)
|
618 |
-
return audio
|
619 |
-
|
620 |
-
@app.post("/download_youtube_song")
|
621 |
-
async def download_youtube_song_endpoint(yt_request: YouTubeDownloadRequest):
|
622 |
-
try:
|
623 |
-
results = YoutubeSearch(yt_request.url, max_results=1).to_dict()
|
624 |
-
link = f"https://youtube.com{results[0]['url_suffix']}"
|
625 |
-
title = results[0]["title"][:40]
|
626 |
-
thumbnail = results[0]["thumbnails"][0]
|
627 |
-
thumb_name = f'thumb{title}.jpg'
|
628 |
-
thumb = requests.get(thumbnail, allow_redirects=True)
|
629 |
-
open(thumb_name, 'wb').write(thumb.content)
|
630 |
-
performer = f"[Mᴋɴ Bᴏᴛᴢ™]"
|
631 |
-
duration = results[0]["duration"]
|
632 |
-
url_suffix = results[0]["url_suffix"]
|
633 |
-
views = results[0]["views"]
|
634 |
-
except Exception as e:
|
635 |
-
logger.error(f"Error downloading YouTube song: {e}")
|
636 |
-
return {"error": str(e)}
|
637 |
-
|
638 |
-
ydl_opts = {"format": "bestaudio[ext=m4a]"}
|
639 |
-
try:
|
640 |
-
with YoutubeDL(ydl_opts) as ydl:
|
641 |
-
info_dict = ydl.extract_info(link, download=False)
|
642 |
-
audio_file = ydl.prepare_filename(info_dict)
|
643 |
-
ydl.process_info(info_dict)
|
644 |
-
except Exception as e:
|
645 |
-
logger.error(f"Error processing YouTube song: {e}")
|
646 |
-
return {"error": str(e)}
|
647 |
-
|
648 |
-
cap = "**BY›› [Mᴋɴ Bᴏᴛᴢ™](https://t.me/mkn_bots_updates)**"
|
649 |
-
secmul, dur, dur_arr = 1, 0, duration.split(':')
|
650 |
-
for i in range(len(dur_arr) - 1, -1, -1):
|
651 |
-
dur += (int(dur_arr[i]) * secmul)
|
652 |
-
secmul *= 60
|
653 |
-
|
654 |
-
return {"audio_file": audio_file, "caption": cap, "title": title, "duration": dur, "performer": performer, "thumb": thumb_name}
|
655 |
-
|
656 |
-
@app.post("/download_youtube_video")
|
657 |
-
async def download_youtube_video_endpoint(yt_request: YouTubeDownloadRequest):
|
658 |
-
url = yt_request.url
|
659 |
-
try:
|
660 |
-
search = SearchVideos(f"{url}", offset=1, mode="dict", max_results=1)
|
661 |
-
mi = search.result()
|
662 |
-
mio = mi["search_result"]
|
663 |
-
mo = mio[0]["link"]
|
664 |
-
thum = mio[0]["title"]
|
665 |
-
fridayz = mio[0]["id"]
|
666 |
-
mio[0]["channel"]
|
667 |
-
kekme = f"https://img.youtube.com/vi/{fridayz}/hqdefault.jpg"
|
668 |
-
await asyncio.sleep(0.6)
|
669 |
-
url = mo
|
670 |
-
sedlyf = wget.download(kekme)
|
671 |
-
opts = {
|
672 |
-
"format": "best",
|
673 |
-
"addmetadata": True,
|
674 |
-
"key": "FFmpegMetadata",
|
675 |
-
"prefer_ffmpeg": True,
|
676 |
-
"geo_bypass": True,
|
677 |
-
"nocheckcertificate": True,
|
678 |
-
"postprocessors": [{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}],
|
679 |
-
"outtmpl": "%(id)s.mp4",
|
680 |
-
"logtostderr": False,
|
681 |
-
"quiet": True,
|
682 |
-
}
|
683 |
-
with YoutubeDL(opts) as ytdl:
|
684 |
-
ytdl_data = ytdl.extract_info(url, download=True)
|
685 |
-
except Exception as e:
|
686 |
-
logger.error(f"Error downloading YouTube video: {e}")
|
687 |
-
return {"error": str(e)}
|
688 |
-
|
689 |
-
file_stark = f"{ytdl_data['id']}.mp4"
|
690 |
-
capy = f"""**𝚃𝙸𝚃𝙻𝙴 :** [{thum}]({mo})\n**𝚁𝙴𝚀𝚄𝙴𝚂𝚃𝙴𝙳 𝙱𝚈 :** {await bot_instance.get_me().mention}"""
|
691 |
-
|
692 |
-
return {"video_file": file_stark, "caption": capy, "title": ytdl_data["title"], "duration": int(ytdl_data["duration"]), "thumb": sedlyf}
|
693 |
-
|
694 |
-
@app.post("/group_manager_action")
|
695 |
-
async def group_manager_action_endpoint(action_request: GroupManagerAction):
|
696 |
-
chat_id = action_request.group_id
|
697 |
-
action = action_request.action
|
698 |
-
user_id = action_request.user_id
|
699 |
-
time_val = action_request.time
|
700 |
-
message_id = action_request.message_id
|
701 |
-
|
702 |
-
if action == "ban":
|
703 |
-
await bot_instance.ban_chat_member(chat_id, user_id)
|
704 |
-
return {"status": "User banned successfully"}
|
705 |
-
elif action == "unban":
|
706 |
-
await bot_instance.unban_chat_member(chat_id, user_id)
|
707 |
-
return {"status": "User unbanned successfully"}
|
708 |
-
elif action == "tban":
|
709 |
-
until_date_val = extract_time(time_val)
|
710 |
-
if until_date_val is None:
|
711 |
-
return {"error": "Invalid time type specified. Expected m, h, or d, Got it: {time_val[-1]}"}
|
712 |
-
await bot_instance.ban_chat_member(chat_id, user_id, until_date=until_date_val)
|
713 |
-
return {"status": "User temporarily banned successfully"}
|
714 |
-
elif action == "mute":
|
715 |
-
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions())
|
716 |
-
return {"status": "User muted successfully"}
|
717 |
-
elif action == "unmute":
|
718 |
-
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions(can_send_messages=True))
|
719 |
-
return {"status": "User unmuted successfully"}
|
720 |
-
elif action == "tmute":
|
721 |
-
until_date_val = extract_time(time_val)
|
722 |
-
if until_date_val is None:
|
723 |
-
return {"error": "Invalid time type specified. Expected m, h, or d, Got it: {time_val[-1]}"}
|
724 |
-
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions(), until_date=until_date_val)
|
725 |
-
return {"status": "User temporarily muted successfully"}
|
726 |
-
elif action == "pin":
|
727 |
-
if not message_id:
|
728 |
-
return {"error": "Message ID is required for pin action"}
|
729 |
-
await bot_instance.pin_chat_message(chat_id, message_id)
|
730 |
-
return {"status": "Message pinned successfully"}
|
731 |
-
elif action == "unpin":
|
732 |
-
if not message_id:
|
733 |
-
return {"error": "Message ID is required for unpin action"}
|
734 |
-
await bot_instance.unpin_chat_message(chat_id, message_id)
|
735 |
-
return {"status": "Message unpinned successfully"}
|
736 |
-
elif action == "purge":
|
737 |
-
if not message_id:
|
738 |
-
return {"error": "Message ID is required for purge action"}
|
739 |
-
await purge_messages(bot_instance, chat_id, message_id)
|
740 |
-
return {"status": "Messages purged successfully"}
|
741 |
-
else:
|
742 |
-
return {"error": "Invalid action"}
|
743 |
-
|
744 |
-
async def purge_messages(client, chat_id, message_id):
|
745 |
-
try:
|
746 |
-
message_ids = []
|
747 |
-
count_del_etion_s = 0
|
748 |
-
if message_id:
|
749 |
-
for a_s_message_id in range(message_id, message_id + 100):
|
750 |
-
message_ids.append(a_s_message_id)
|
751 |
-
if len(message_ids) == 100:
|
752 |
-
await client.delete_messages(chat_id=chat_id, message_ids=message_ids, revoke=True)
|
753 |
-
count_del_etion_s += len(message_ids)
|
754 |
-
message_ids = []
|
755 |
-
if len(message_ids) > 0:
|
756 |
-
await client.delete_messages(chat_id=chat_id, message_ids=message_ids, revoke=True)
|
757 |
-
count_del_etion_s += len(message_ids)
|
758 |
-
except Exception as e:
|
759 |
-
logger.error(f"Error purging messages: {e}")
|
760 |
-
return {"error": str(e)}
|
761 |
-
|
762 |
-
@app.post("/get_chat")
|
763 |
-
async def get_chat_endpoint(chat_id: int):
|
764 |
-
chat = await bot_instance.get_chat(chat_id)
|
765 |
-
return {"chat": chat.dict()}
|
766 |
-
|
767 |
-
@app.post("/get_chat_member")
|
768 |
-
async def get_chat_member_endpoint(chat_id: int, user_id: int):
|
769 |
-
chat_member = await bot_instance.get_chat_member(chat_id, user_id)
|
770 |
-
return {"chat_member": chat_member.dict()}
|
771 |
-
|
772 |
-
@app.post("/get_chat_members_count")
|
773 |
-
async def get_chat_members_count_endpoint(chat_id: int):
|
774 |
-
count = await bot_instance.get_chat_members_count(chat_id)
|
775 |
-
return {"members_count": count}
|
776 |
-
|
777 |
-
@app.post("/kick_chat_member")
|
778 |
-
async def kick_chat_member_endpoint(chat_id: int, user_id: int):
|
779 |
-
await bot_instance.kick_chat_member(chat_id, user_id)
|
780 |
-
return {"status": "Chat member kicked successfully"}
|
781 |
-
|
782 |
-
@app.post("/promote_chat_member")
|
783 |
-
async def promote_chat_member_endpoint(chat_id: int, user_id: int, can_change_info: bool = False, can_post_messages: bool = False, can_edit_messages: bool = False, can_delete_messages: bool = False, can_manage_video_chats: bool = False, can_restrict_members: bool = False, can_promote_members: bool = False, can_invite_users: bool = False, can_pin_messages: bool = False, can_manage_chat: bool = False):
|
784 |
-
await bot_instance.promote_chat_member(
|
785 |
-
chat_id,
|
786 |
-
user_id,
|
787 |
-
can_change_info=can_change_info,
|
788 |
-
can_post_messages=can_post_messages,
|
789 |
-
can_edit_messages=can_edit_messages,
|
790 |
-
can_delete_messages=can_delete_messages,
|
791 |
-
can_manage_video_chats=can_manage_video_chats,
|
792 |
-
can_restrict_members=can_restrict_members,
|
793 |
-
can_promote_members=can_promote_members,
|
794 |
-
can_invite_users=can_invite_users,
|
795 |
-
can_pin_messages=can_pin_messages,
|
796 |
-
can_manage_chat=can_manage_chat
|
797 |
-
)
|
798 |
-
return {"status": "Chat member promoted successfully"}
|
799 |
-
|
800 |
-
@app.post("/set_chat_permissions")
|
801 |
-
async def set_chat_permissions_endpoint(chat_id: int, permissions: dict):
|
802 |
-
chat_permissions = enums.ChatPermissions(**permissions)
|
803 |
-
await bot_instance.set_chat_permissions(chat_id, chat_permissions)
|
804 |
-
return {"status": "Chat permissions set successfully"}
|
805 |
-
|
806 |
-
@app.post("/set_chat_photo")
|
807 |
-
async def set_chat_photo_endpoint(chat_id: int, photo_url: str):
|
808 |
-
response = requests.get(photo_url)
|
809 |
-
photo = BytesIO(response.content)
|
810 |
-
photo.name = "photo.jpg"
|
811 |
-
await bot_instance.set_chat_photo(chat_id, photo)
|
812 |
-
return {"status": "Chat photo set successfully"}
|
813 |
-
|
814 |
-
@app.post("/delete_chat_photo")
|
815 |
-
async def delete_chat_photo_endpoint(chat_id: int):
|
816 |
-
await bot_instance.delete_chat_photo(chat_id)
|
817 |
-
return {"status": "Chat photo deleted successfully"}
|
818 |
-
|
819 |
-
@app.post("/set_chat_title")
|
820 |
-
async def set_chat_title_endpoint(chat_id: int, title: str):
|
821 |
-
await bot_instance.set_chat_title(chat_id, title)
|
822 |
-
return {"status": "Chat title set successfully"}
|
823 |
-
|
824 |
-
@app.post("/set_chat_description")
|
825 |
-
async def set_chat_description_endpoint(chat_id: int, description: str):
|
826 |
-
await bot_instance.set_chat_description(chat_id, description)
|
827 |
-
return {"status": "Chat description set successfully"}
|
828 |
-
|
829 |
-
@app.post("/pin_chat_message")
|
830 |
-
async def pin_chat_message_endpoint(chat_id: int, message_id: int, disable_notification: bool = False):
|
831 |
-
await bot_instance.pin_chat_message(chat_id, message_id, disable_notification=disable_notification)
|
832 |
-
return {"status": "Message pinned successfully"}
|
833 |
-
|
834 |
-
@app.post("/unpin_chat_message")
|
835 |
-
async def unpin_chat_message_endpoint(chat_id: int, message_id: int):
|
836 |
-
await bot_instance.unpin_chat_message(chat_id, message_id)
|
837 |
-
return {"status": "Message unpinned successfully"}
|
838 |
-
|
839 |
-
@app.post("/unpin_all_chat_messages")
|
840 |
-
async def unpin_all_chat_messages_endpoint(chat_id: int):
|
841 |
-
await bot_instance.unpin_all_chat_messages(chat_id)
|
842 |
-
return {"status": "All messages unpinned successfully"}
|
843 |
-
|
844 |
-
@app.post("/answer_callback_query")
|
845 |
-
async def answer_callback_query_endpoint(callback_query_id: str, text: str = None, show_alert: bool = False, url: str = None, cache_time: int = 0):
|
846 |
-
await bot_instance.answer_callback_query(callback_query_id, text=text, show_alert=show_alert, url=url, cache_time=cache_time)
|
847 |
-
return {"status": "Callback query answered successfully"}
|
848 |
-
|
849 |
-
@app.post("/copy_message")
|
850 |
-
async def copy_message_endpoint(chat_id: int, from_chat_id: int, message_id: int, caption: str = None, parse_mode: str = None, caption_entities: list = None, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
851 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
852 |
-
message = await bot_instance.copy_message(
|
853 |
-
chat_id,
|
854 |
-
from_chat_id,
|
855 |
-
message_id,
|
856 |
-
caption=caption,
|
857 |
-
parse_mode=parse_mode,
|
858 |
-
caption_entities=caption_entities,
|
859 |
-
reply_to_message_id=reply_to_message_id,
|
860 |
-
allow_sending_without_reply=allow_sending_without_reply,
|
861 |
-
reply_markup=reply_markup_obj
|
862 |
-
)
|
863 |
-
return {"message_id": message.id}
|
864 |
-
|
865 |
-
@app.post("/forward_messages")
|
866 |
-
async def forward_messages_endpoint(chat_id: int, from_chat_id: int, message_ids: list, disable_notification: bool = False):
|
867 |
-
messages = await bot_instance.forward_messages(
|
868 |
-
chat_id,
|
869 |
-
from_chat_id,
|
870 |
-
message_ids,
|
871 |
-
disable_notification=disable_notification
|
872 |
-
)
|
873 |
-
return {"messages": [msg.id for msg in messages]}
|
874 |
-
|
875 |
-
@app.post("/send_poll")
|
876 |
-
async def send_poll_endpoint(chat_id: int, question: str, options: list, is_anonymous: bool = False, type: str = "regular", allows_multiple_answers: bool = False, correct_option_id: int = None, explanation: str = None, explanation_parse_mode: None = None, open_period: int = None, close_date: int = None, is_closed: bool = False):
|
877 |
-
try:
|
878 |
-
message = await bot_instance.send_poll(
|
879 |
-
chat_id,
|
880 |
-
question,
|
881 |
-
options,
|
882 |
-
is_anonymous=is_anonymous,
|
883 |
-
type=type,
|
884 |
-
allows_multiple_answers=allows_multiple_answers,
|
885 |
-
correct_option_id=correct_option_id,
|
886 |
-
explanation=explanation,
|
887 |
-
explanation_parse_mode=explanation_parse_mode,
|
888 |
-
open_period=open_period,
|
889 |
-
close_date=close_date,
|
890 |
-
is_closed=is_closed
|
891 |
-
)
|
892 |
-
return {"message_id": message.id}
|
893 |
-
except Exception as e:
|
894 |
-
logger.error(f"Error sending poll: {e}")
|
895 |
-
return {"error": str(e)}
|
896 |
-
|
897 |
-
@app.post("/send_dice")
|
898 |
-
async def send_dice_endpoint(chat_id: int, reply_to_message_id: int = None, reply_markup: dict = None):
|
899 |
-
try:
|
900 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
901 |
-
message = await bot_instance.send_dice(
|
902 |
-
chat_id,
|
903 |
-
reply_to_message_id=reply_to_message_id,
|
904 |
-
reply_markup=reply_markup_obj
|
905 |
-
)
|
906 |
-
return {"message_id": message.id}
|
907 |
-
except Exception as e:
|
908 |
-
logger.error(f"Error sending dice: {e}")
|
909 |
-
return {"error": str(e)}
|
910 |
-
|
911 |
-
@app.post("/send_game")
|
912 |
-
async def send_game_endpoint(chat_id: int, game_short_name: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
913 |
-
try:
|
914 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
915 |
-
message = await bot_instance.send_game(
|
916 |
-
chat_id,
|
917 |
-
game_short_name,
|
918 |
-
reply_to_message_id=reply_to_message_id,
|
919 |
-
reply_markup=reply_markup_obj
|
920 |
-
)
|
921 |
-
return {"message_id": message.id}
|
922 |
-
except Exception as e:
|
923 |
-
logger.error(f"Error sending game: {e}")
|
924 |
-
return {"error": str(e)}
|
925 |
-
|
926 |
-
@app.post("/send_media_group")
|
927 |
-
async def send_media_group_endpoint(chat_id: int, media: list, reply_to_message_id: int = None, reply_markup: dict = None):
|
928 |
-
try:
|
929 |
-
media_group = []
|
930 |
-
for media_item in media:
|
931 |
-
if media_item["type"] == "photo":
|
932 |
-
response = requests.get(media_item["media"])
|
933 |
-
photo = BytesIO(response.content)
|
934 |
-
photo.name = "photo.jpg"
|
935 |
-
media_group.append(types.InputMediaPhoto(media=photo))
|
936 |
-
elif media_item["type"] == "video":
|
937 |
-
response = requests.get(media_item["media"])
|
938 |
-
video = BytesIO(response.content)
|
939 |
-
video.name = "video.mp4"
|
940 |
-
media_group.append(types.InputMediaVideo(media=video))
|
941 |
-
else:
|
942 |
-
return {"error": "Unsupported media type"}
|
943 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
944 |
-
messages = await bot_instance.send_media_group(
|
945 |
-
chat_id,
|
946 |
-
media_group,
|
947 |
-
reply_to_message_id=reply_to_message_id,
|
948 |
-
reply_markup=reply_markup_obj
|
949 |
-
)
|
950 |
-
return {"messages": [msg.id for msg in messages]}
|
951 |
-
except Exception as e:
|
952 |
-
logger.error(f"Error sending media group: {e}")
|
953 |
-
return {"error": str(e)}
|
954 |
-
|
955 |
-
@app.post("/send_invoice")
|
956 |
-
async def send_invoice_endpoint(chat_id: int, title: str, description: str, payload: str, provider_token: str, currency: str, prices: list, start_parameter: str = None, provider_data: str = None, photo_url: str = None, photo_size: int = None, photo_width: int = None, photo_height: int = None, need_name: bool = False, need_phone_number: bool = False, need_email: bool = False, need_shipping_address: bool = False, send_phone_number_to_provider: bool = False, send_email_to_provider: bool = False, is_flexible: bool = False, disable_notification: bool = False, protect_content: bool = False, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
957 |
-
try:
|
958 |
-
prices_obj = [types.LabeledPrice(label=price["label"], amount=price["amount"]) for price in prices]
|
959 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
960 |
-
message = await bot_instance.send_invoice(
|
961 |
-
chat_id,
|
962 |
-
title,
|
963 |
-
description,
|
964 |
-
payload,
|
965 |
-
provider_token,
|
966 |
-
currency,
|
967 |
-
prices_obj,
|
968 |
-
start_parameter=start_parameter,
|
969 |
-
provider_data=provider_data,
|
970 |
-
photo_url=photo_url,
|
971 |
-
photo_size=photo_size,
|
972 |
-
photo_width=photo_width,
|
973 |
-
photo_height=photo_height,
|
974 |
-
need_name=need_name,
|
975 |
-
need_phone_number=need_phone_number,
|
976 |
-
need_email=need_email,
|
977 |
-
need_shipping_address=need_shipping_address,
|
978 |
-
send_phone_number_to_provider=send_phone_number_to_provider,
|
979 |
-
send_email_to_provider=send_email_to_provider,
|
980 |
-
is_flexible=is_flexible,
|
981 |
-
disable_notification=disable_notification,
|
982 |
-
protect_content=protect_content,
|
983 |
-
reply_to_message_id=reply_to_message_id,
|
984 |
-
allow_sending_without_reply=allow_sending_without_reply,
|
985 |
-
reply_markup=reply_markup_obj
|
986 |
-
)
|
987 |
-
return {"message_id": message.id}
|
988 |
-
except Exception as e:
|
989 |
-
logger.error(f"Error sending invoice: {e}")
|
990 |
-
return {"error": str(e)}
|
991 |
-
|
992 |
-
@app.post("/send_location")
|
993 |
-
async def send_location_endpoint(chat_id: int, latitude: float, longitude: float, reply_to_message_id: int = None, reply_markup: dict = None):
|
994 |
-
try:
|
995 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
996 |
-
message = await bot_instance.send_location(
|
997 |
-
chat_id,
|
998 |
-
latitude,
|
999 |
-
longitude,
|
1000 |
-
reply_to_message_id=reply_to_message_id,
|
1001 |
-
reply_markup=reply_markup_obj
|
1002 |
-
)
|
1003 |
-
return {"message_id": message.id}
|
1004 |
-
except Exception as e:
|
1005 |
-
logger.error(f"Error sending location: {e}")
|
1006 |
-
return {"error": str(e)}
|
1007 |
-
|
1008 |
-
@app.post("/send_contact")
|
1009 |
-
async def send_contact_endpoint(chat_id: int, phone_number: str, first_name: str, last_name: str = None, reply_to_message_id: int = None, reply_markup: dict = None):
|
1010 |
-
try:
|
1011 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1012 |
-
message = await bot_instance.send_contact(
|
1013 |
-
chat_id,
|
1014 |
-
phone_number,
|
1015 |
-
first_name,
|
1016 |
-
last_name=last_name,
|
1017 |
-
reply_to_message_id=reply_to_message_id,
|
1018 |
-
reply_markup=reply_markup_obj
|
1019 |
-
)
|
1020 |
-
return {"message_id": message.id}
|
1021 |
-
except Exception as e:
|
1022 |
-
logger.error(f"Error sending contact: {e}")
|
1023 |
-
return {"error": str(e)}
|
1024 |
-
|
1025 |
-
@app.post("/send_animation")
|
1026 |
-
async def send_animation_endpoint(chat_id: int, animation_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1027 |
-
try:
|
1028 |
-
response = requests.get(animation_url)
|
1029 |
-
animation = BytesIO(response.content)
|
1030 |
-
animation.name = "animation.gif"
|
1031 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1032 |
-
message = await bot_instance.send_animation(
|
1033 |
-
chat_id,
|
1034 |
-
animation,
|
1035 |
-
reply_to_message_id=reply_to_message_id,
|
1036 |
-
reply_markup=reply_markup_obj
|
1037 |
-
)
|
1038 |
-
return {"message_id": message.id}
|
1039 |
-
except Exception as e:
|
1040 |
-
logger.error(f"Error sending animation: {e}")
|
1041 |
-
return {"error": str(e)}
|
1042 |
-
|
1043 |
-
@app.post("/send_video_note")
|
1044 |
-
async def send_video_note_endpoint(chat_id: int, video_note_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1045 |
-
try:
|
1046 |
-
response = requests.get(video_note_url)
|
1047 |
-
video_note = BytesIO(response.content)
|
1048 |
-
video_note.name = "video_note.mp4"
|
1049 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1050 |
-
message = await bot_instance.send_video_note(
|
1051 |
-
chat_id,
|
1052 |
-
video_note,
|
1053 |
-
reply_to_message_id=reply_to_message_id,
|
1054 |
-
reply_markup=reply_markup_obj
|
1055 |
-
)
|
1056 |
-
return {"message_id": message.id}
|
1057 |
-
except Exception as e:
|
1058 |
-
logger.error(f"Error sending video note: {e}")
|
1059 |
-
return {"error": str(e)}
|
1060 |
-
|
1061 |
-
@app.post("/send_voice")
|
1062 |
-
async def send_voice_endpoint(chat_id: int, voice_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1063 |
-
try:
|
1064 |
-
response = requests.get(voice_url)
|
1065 |
-
voice = BytesIO(response.content)
|
1066 |
-
voice.name = "voice.ogg"
|
1067 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1068 |
-
message = await bot_instance.send_voice(
|
1069 |
-
chat_id,
|
1070 |
-
voice,
|
1071 |
-
reply_to_message_id=reply_to_message_id,
|
1072 |
-
reply_markup=reply_markup_obj
|
1073 |
-
)
|
1074 |
-
return {"message_id": message.id}
|
1075 |
-
except Exception as e:
|
1076 |
-
logger.error(f"Error sending voice: {e}")
|
1077 |
-
return {"error": str(e)}
|
1078 |
-
|
1079 |
-
@app.post("/send_video")
|
1080 |
-
async def send_video_endpoint(chat_id: int, video_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1081 |
-
try:
|
1082 |
-
response = requests.get(video_url)
|
1083 |
-
video = BytesIO(response.content)
|
1084 |
-
video.name = "video.mp4"
|
1085 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1086 |
-
message = await bot_instance.send_video(
|
1087 |
-
chat_id,
|
1088 |
-
video,
|
1089 |
-
reply_to_message_id=reply_to_message_id,
|
1090 |
-
reply_markup=reply_markup_obj
|
1091 |
-
)
|
1092 |
-
return {"message_id": message.id}
|
1093 |
-
except Exception as e:
|
1094 |
-
logger.error(f"Error sending video: {e}")
|
1095 |
-
return {"error": str(e)}
|
1096 |
-
|
1097 |
-
@app.post("/send_document")
|
1098 |
-
async def send_document_endpoint(chat_id: int, document_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1099 |
-
try:
|
1100 |
-
response = requests.get(document_url)
|
1101 |
-
document = BytesIO(response.content)
|
1102 |
-
document.name = "document.pdf"
|
1103 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1104 |
-
message = await bot_instance.send_document(
|
1105 |
-
chat_id,
|
1106 |
-
document,
|
1107 |
-
reply_to_message_id=reply_to_message_id,
|
1108 |
-
reply_markup=reply_markup_obj
|
1109 |
-
)
|
1110 |
-
return {"message_id": message.id}
|
1111 |
-
except Exception as e:
|
1112 |
-
logger.error(f"Error sending document: {e}")
|
1113 |
-
return {"error": str(e)}
|
1114 |
-
|
1115 |
-
@app.post("/send_photo")
|
1116 |
-
async def send_photo_endpoint(chat_id: int, photo_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1117 |
-
try:
|
1118 |
-
response = requests.get(photo_url)
|
1119 |
-
photo = BytesIO(response.content)
|
1120 |
-
photo.name = "photo.jpg"
|
1121 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1122 |
-
message = await bot_instance.send_photo(
|
1123 |
-
chat_id,
|
1124 |
-
photo,
|
1125 |
-
reply_to_message_id=reply_to_message_id,
|
1126 |
-
reply_markup=reply_markup_obj
|
1127 |
-
)
|
1128 |
-
return {"message_id": message.id}
|
1129 |
-
except Exception as e:
|
1130 |
-
logger.error(f"Error sending photo: {e}")
|
1131 |
-
return {"error": str(e)}
|
1132 |
-
|
1133 |
-
@app.post("/send_audio")
|
1134 |
-
async def send_audio_endpoint(chat_id: int, audio_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1135 |
-
try:
|
1136 |
-
response = requests.get(audio_url)
|
1137 |
-
audio = BytesIO(response.content)
|
1138 |
-
audio.name = "audio.mp3"
|
1139 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1140 |
-
message = await bot_instance.send_audio(
|
1141 |
-
chat_id,
|
1142 |
-
audio,
|
1143 |
-
reply_to_message_id=reply_to_message_id,
|
1144 |
-
reply_markup=reply_markup_obj
|
1145 |
-
)
|
1146 |
-
return {"message_id": message.id}
|
1147 |
-
except Exception as e:
|
1148 |
-
logger.error(f"Error sending audio: {e}")
|
1149 |
-
return {"error": str(e)}
|
1150 |
-
|
1151 |
-
@app.post("/send_sticker")
|
1152 |
-
async def send_sticker_endpoint(chat_id: int, sticker_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1153 |
-
try:
|
1154 |
-
response = requests.get(sticker_url)
|
1155 |
-
sticker = BytesIO(response.content)
|
1156 |
-
sticker.name = "sticker.webp"
|
1157 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1158 |
-
message = await bot_instance.send_sticker(
|
1159 |
-
chat_id,
|
1160 |
-
sticker,
|
1161 |
-
reply_to_message_id=reply_to_message_id,
|
1162 |
-
reply_markup=reply_markup_obj
|
1163 |
-
)
|
1164 |
-
return {"message_id": message.id}
|
1165 |
-
except Exception as e:
|
1166 |
-
logger.error(f"Error sending sticker: {e}")
|
1167 |
-
return {"error": str(e)}
|
1168 |
-
|
1169 |
-
@app.post("/send_chat_action")
|
1170 |
-
async def send_chat_action_endpoint(chat_id: int, action: str):
|
1171 |
-
actions = {
|
1172 |
-
"typing": enums.ChatAction.TYPING,
|
1173 |
-
"upload_photo": enums.ChatAction.UPLOAD_PHOTO,
|
1174 |
-
"record_video": enums.ChatAction.RECORD_VIDEO,
|
1175 |
-
"upload_video": enums.ChatAction.UPLOAD_VIDEO,
|
1176 |
-
"record_voice": enums.ChatAction.RECORD_VOICE,
|
1177 |
-
"upload_voice": enums.ChatAction.UPLOAD_VOICE,
|
1178 |
-
"upload_document": enums.ChatAction.UPLOAD_DOCUMENT,
|
1179 |
-
"find_location": enums.ChatAction.FIND_LOCATION,
|
1180 |
-
"record_video_note": enums.ChatAction.RECORD_VIDEO_NOTE,
|
1181 |
-
"upload_video_note": enums.ChatAction.UPLOAD_VIDEO_NOTE,
|
1182 |
-
"playing": enums.ChatAction.PLAYING
|
1183 |
-
}
|
1184 |
-
action_enum = actions.get(action)
|
1185 |
-
if not action_enum:
|
1186 |
-
return {"error": "Invalid action"}
|
1187 |
-
try:
|
1188 |
-
await bot_instance.send_chat_action(chat_id, action_enum)
|
1189 |
-
return {"status": "Chat action sent successfully"}
|
1190 |
-
except Exception as e:
|
1191 |
-
logger.error(f"Error sending chat action: {e}")
|
1192 |
-
return {"error": str(e)}
|
1193 |
-
|
1194 |
-
@app.post("/create_chat_invite_link")
|
1195 |
-
async def create_chat_invite_link_endpoint(chat_id: int, name: str = None, expire_date: int = None, member_limit: int = None, creates_join_request: bool = False):
|
1196 |
-
try:
|
1197 |
-
invite_link = await bot_instance.create_chat_invite_link(
|
1198 |
-
chat_id,
|
1199 |
-
name=name,
|
1200 |
-
expire_date=expire_date,
|
1201 |
-
member_limit=member_limit,
|
1202 |
-
creates_join_request=creates_join_request
|
1203 |
-
)
|
1204 |
-
return {"invite_link": invite_link.invite_link}
|
1205 |
-
except Exception as e:
|
1206 |
-
logger.error(f"Error creating chat invite link: {e}")
|
1207 |
-
return {"error": str(e)}
|
1208 |
-
|
1209 |
-
@app.post("/set_chat_photo")
|
1210 |
-
async def set_chat_photo_endpoint(chat_id: int, photo_url: str):
|
1211 |
-
try:
|
1212 |
-
response = requests.get(photo_url)
|
1213 |
-
photo = BytesIO(response.content)
|
1214 |
-
photo.name = "photo.jpg"
|
1215 |
-
await bot_instance.set_chat_photo(chat_id, photo)
|
1216 |
-
return {"status": "Chat photo set successfully"}
|
1217 |
-
except Exception as e:
|
1218 |
-
logger.error(f"Error setting chat photo: {e}")
|
1219 |
-
return {"error": str(e)}
|
1220 |
-
|
1221 |
-
@app.post("/delete_chat_photo")
|
1222 |
-
async def delete_chat_photo_endpoint(chat_id: int):
|
1223 |
-
try:
|
1224 |
-
await bot_instance.delete_chat_photo(chat_id)
|
1225 |
-
return {"status": "Chat photo deleted successfully"}
|
1226 |
-
except Exception as e:
|
1227 |
-
logger.error(f"Error deleting chat photo: {e}")
|
1228 |
-
return {"error": str(e)}
|
1229 |
-
|
1230 |
-
@app.post("/set_chat_title")
|
1231 |
-
async def set_chat_title_endpoint(chat_id: int, title: str):
|
1232 |
-
try:
|
1233 |
-
await bot_instance.set_chat_title(chat_id, title)
|
1234 |
-
return {"status": "Chat title set successfully"}
|
1235 |
-
except Exception as e:
|
1236 |
-
logger.error(f"Error setting chat title: {e}")
|
1237 |
-
return {"error": str(e)}
|
1238 |
-
|
1239 |
-
@app.post("/set_chat_description")
|
1240 |
-
async def set_chat_description_endpoint(chat_id: int, description: str):
|
1241 |
-
try:
|
1242 |
-
await bot_instance.set_chat_description(chat_id, description)
|
1243 |
-
return {"status": "Chat description set successfully"}
|
1244 |
-
except Exception as e:
|
1245 |
-
logger.error(f"Error setting chat description: {e}")
|
1246 |
-
return {"error": str(e)}
|
1247 |
-
|
1248 |
-
@app.post("/pin_chat_message")
|
1249 |
-
async def pin_chat_message_endpoint(chat_id: int, message_id: int, disable_notification: bool = False):
|
1250 |
-
try:
|
1251 |
-
await bot_instance.pin_chat_message(chat_id, message_id, disable_notification=disable_notification)
|
1252 |
-
return {"status": "Message pinned successfully"}
|
1253 |
-
except Exception as e:
|
1254 |
-
logger.error(f"Error pinning chat message: {e}")
|
1255 |
-
return {"error": str(e)}
|
1256 |
-
|
1257 |
-
@app.post("/unpin_chat_message")
|
1258 |
-
async def unpin_chat_message_endpoint(chat_id: int, message_id: int):
|
1259 |
-
try:
|
1260 |
-
await bot_instance.unpin_chat_message(chat_id, message_id)
|
1261 |
-
return {"status": "Message unpinned successfully"}
|
1262 |
-
except Exception as e:
|
1263 |
-
logger.error(f"Error unpinning chat message: {e}")
|
1264 |
-
return {"error": str(e)}
|
1265 |
-
|
1266 |
-
@app.post("/unpin_all_chat_messages")
|
1267 |
-
async def unpin_all_chat_messages_endpoint(chat_id: int):
|
1268 |
-
try:
|
1269 |
-
await bot_instance.unpin_all_chat_messages(chat_id)
|
1270 |
-
return {"status": "All messages unpinned successfully"}
|
1271 |
-
except Exception as e:
|
1272 |
-
logger.error(f"Error unpinning all chat messages: {e}")
|
1273 |
-
return {"error": str(e)}
|
1274 |
-
|
1275 |
-
@app.post("/restrict_chat_member")
|
1276 |
-
async def restrict_chat_member_endpoint(chat_id: int, user_id: int, permissions: dict, until_date: int = None):
|
1277 |
-
try:
|
1278 |
-
chat_permissions = enums.ChatPermissions(**permissions)
|
1279 |
-
await bot_instance.restrict_chat_member(chat_id, user_id, chat_permissions, until_date=until_date)
|
1280 |
-
return {"status": "Chat member restricted successfully"}
|
1281 |
-
except Exception as e:
|
1282 |
-
logger.error(f"Error restricting chat member: {e}")
|
1283 |
-
return {"error": str(e)}
|
1284 |
-
|
1285 |
-
@app.post("/promote_chat_member")
|
1286 |
-
async def promote_chat_member_endpoint(chat_id: int, user_id: int, can_change_info: bool = False, can_post_messages: bool = False, can_edit_messages: bool = False, can_delete_messages: bool = False, can_manage_video_chats: bool = False, can_restrict_members: bool = False, can_promote_members: bool = False, can_invite_users: bool = False, can_pin_messages: bool = False, can_manage_chat: bool = False):
|
1287 |
-
try:
|
1288 |
-
await bot_instance.promote_chat_member(
|
1289 |
-
chat_id,
|
1290 |
-
user_id,
|
1291 |
-
can_change_info=can_change_info,
|
1292 |
-
can_post_messages=can_post_messages,
|
1293 |
-
can_edit_messages=can_edit_messages,
|
1294 |
-
can_delete_messages=can_delete_messages,
|
1295 |
-
can_manage_video_chats=can_manage_video_chats,
|
1296 |
-
can_restrict_members=can_restrict_members,
|
1297 |
-
can_promote_members=can_promote_members,
|
1298 |
-
can_invite_users=can_invite_users,
|
1299 |
-
can_pin_messages=can_pin_messages,
|
1300 |
-
can_manage_chat=can_manage_chat
|
1301 |
-
)
|
1302 |
-
return {"status": "Chat member promoted successfully"}
|
1303 |
-
except Exception as e:
|
1304 |
-
logger.error(f"Error promoting chat member: {e}")
|
1305 |
-
return {"error": str(e)}
|
1306 |
-
|
1307 |
-
@app.post("/kick_chat_member")
|
1308 |
-
async def kick_chat_member_endpoint(chat_id: int, user_id: int):
|
1309 |
-
try:
|
1310 |
-
await bot_instance.kick_chat_member(chat_id, user_id)
|
1311 |
-
return {"status": "Chat member kicked successfully"}
|
1312 |
-
except Exception as e:
|
1313 |
-
logger.error(f"Error kicking chat member: {e}")
|
1314 |
-
return {"error": str(e)}
|
1315 |
-
|
1316 |
-
@app.post("/unban_chat_member")
|
1317 |
-
async def unban_chat_member_endpoint(chat_id: int, user_id: int):
|
1318 |
-
try:
|
1319 |
-
await bot_instance.unban_chat_member(chat_id, user_id)
|
1320 |
-
return {"status": "Chat member unbanned successfully"}
|
1321 |
-
except Exception as e:
|
1322 |
-
logger.error(f"Error unbanning chat member: {e}")
|
1323 |
-
return {"error": str(e)}
|
1324 |
-
|
1325 |
-
@app.post("/set_chat_administrator_custom_title")
|
1326 |
-
async def set_chat_administrator_custom_title_endpoint(chat_id: int, user_id: int, custom_title: str):
|
1327 |
-
try:
|
1328 |
-
await bot_instance.set_chat_administrator_custom_title(chat_id, user_id, custom_title)
|
1329 |
-
return {"status": "Custom title set successfully"}
|
1330 |
-
except Exception as e:
|
1331 |
-
logger.error(f"Error setting custom title: {e}")
|
1332 |
-
return {"error": str(e)}
|
1333 |
-
|
1334 |
-
@app.post("/set_chat_permissions")
|
1335 |
-
async def set_chat_permissions_endpoint(chat_id: int, permissions: dict):
|
1336 |
-
try:
|
1337 |
-
chat_permissions = enums.ChatPermissions(**permissions)
|
1338 |
-
await bot_instance.set_chat_permissions(chat_id, chat_permissions)
|
1339 |
-
return {"status": "Chat permissions set successfully"}
|
1340 |
-
except Exception as e:
|
1341 |
-
logger.error(f"Error setting chat permissions: {e}")
|
1342 |
-
return {"error": str(e)}
|
1343 |
-
|
1344 |
-
@app.post("/set_chat_sticker_set")
|
1345 |
-
async def set_chat_sticker_set_endpoint(chat_id: int, sticker_set_name: str):
|
1346 |
-
try:
|
1347 |
-
await bot_instance.set_chat_sticker_set(chat_id, sticker_set_name)
|
1348 |
-
return {"status": "Chat sticker set set successfully"}
|
1349 |
-
except Exception as e:
|
1350 |
-
logger.error(f"Error setting chat sticker set: {e}")
|
1351 |
-
return {"error": str(e)}
|
1352 |
-
|
1353 |
-
@app.post("/delete_chat_sticker_set")
|
1354 |
-
async def delete_chat_sticker_set_endpoint(chat_id: int):
|
1355 |
-
try:
|
1356 |
-
await bot_instance.delete_chat_sticker_set(chat_id)
|
1357 |
-
return {"status": "Chat sticker set deleted successfully"}
|
1358 |
-
except Exception as e:
|
1359 |
-
logger.error(f"Error deleting chat sticker set: {e}")
|
1360 |
-
return {"error": str(e)}
|
1361 |
-
|
1362 |
-
@app.post("/approve_chat_join_request")
|
1363 |
-
async def approve_chat_join_request_endpoint(chat_id: int, user_id: int):
|
1364 |
-
try:
|
1365 |
-
await bot_instance.approve_chat_join_request(chat_id, user_id)
|
1366 |
-
return {"status": "Join request approved successfully"}
|
1367 |
-
except Exception as e:
|
1368 |
-
logger.error(f"Error approving chat join request: {e}")
|
1369 |
-
return {"error": str(e)}
|
1370 |
-
|
1371 |
-
@app.post("/decline_chat_join_request")
|
1372 |
-
async def decline_chat_join_request_endpoint(chat_id: int, user_id: int):
|
1373 |
-
try:
|
1374 |
-
await bot_instance.decline_chat_join_request(chat_id, user_id)
|
1375 |
-
return {"status": "Join request declined successfully"}
|
1376 |
-
except Exception as e:
|
1377 |
-
logger.error(f"Error declining chat join request: {e}")
|
1378 |
-
return {"error": str(e)}
|
1379 |
-
|
1380 |
-
@app.post("/ban_chat_sender_chat")
|
1381 |
-
async def ban_chat_sender_chat_endpoint(chat_id: int, sender_chat_id: int):
|
1382 |
-
try:
|
1383 |
-
await bot_instance.ban_chat_sender_chat(chat_id, sender_chat_id)
|
1384 |
-
return {"status": "Sender chat banned successfully"}
|
1385 |
-
except Exception as e:
|
1386 |
-
logger.error(f"Error banning chat sender chat: {e}")
|
1387 |
-
return {"error": str(e)}
|
1388 |
-
|
1389 |
-
@app.post("/unban_chat_sender_chat")
|
1390 |
-
async def unban_chat_sender_chat_endpoint(chat_id: int, sender_chat_id: int):
|
1391 |
-
try:
|
1392 |
-
await bot_instance.unban_chat_sender_chat(chat_id, sender_chat_id)
|
1393 |
-
return {"status": "Sender chat unbanned successfully"}
|
1394 |
-
except Exception as e:
|
1395 |
-
logger.error(f"Error unbanning chat sender chat: {e}")
|
1396 |
-
return {"error": str(e)}
|
1397 |
-
|
1398 |
-
@app.post("/set_chat_menu_button")
|
1399 |
-
async def set_chat_menu_button_endpoint(chat_id: int, menu_button: dict = None):
|
1400 |
-
try:
|
1401 |
-
if menu_button:
|
1402 |
-
menu_button_obj = types.MenuButton(**menu_button)
|
1403 |
-
else:
|
1404 |
-
menu_button_obj = None
|
1405 |
-
await bot_instance.set_chat_menu_button(chat_id, menu_button_obj)
|
1406 |
-
return {"status": "Chat menu button set successfully"}
|
1407 |
-
except Exception as e:
|
1408 |
-
logger.error(f"Error setting chat menu button: {e}")
|
1409 |
-
return {"error": str(e)}
|
1410 |
-
|
1411 |
-
@app.post("/get_chat_menu_button")
|
1412 |
-
async def get_chat_menu_button_endpoint(chat_id: int):
|
1413 |
-
try:
|
1414 |
-
menu_button = await bot_instance.get_chat_menu_button(chat_id)
|
1415 |
-
return {"menu_button": menu_button.dict() if menu_button else None}
|
1416 |
-
except Exception as e:
|
1417 |
-
logger.error(f"Error getting chat menu button: {e}")
|
1418 |
-
return {"error": str(e)}
|
1419 |
-
|
1420 |
-
@app.post("/set_my_commands")
|
1421 |
-
async def set_my_commands_endpoint(commands: list):
|
1422 |
-
try:
|
1423 |
-
bot_commands = [types.BotCommand(command=cmd["command"], description=cmd["description"]) for cmd in commands]
|
1424 |
-
await bot_instance.set_my_commands(bot_commands)
|
1425 |
-
return {"status": "Commands set successfully"}
|
1426 |
-
except Exception as e:
|
1427 |
-
logger.error(f"Error setting my commands: {e}")
|
1428 |
-
return {"error": str(e)}
|
1429 |
-
|
1430 |
-
@app.post("/get_my_commands")
|
1431 |
-
async def get_my_commands_endpoint():
|
1432 |
-
try:
|
1433 |
-
commands = await bot_instance.get_my_commands()
|
1434 |
-
return {"commands": [cmd.dict() for cmd in commands]}
|
1435 |
-
except Exception as e:
|
1436 |
-
logger.error(f"Error getting my commands: {e}")
|
1437 |
-
return {"error": str(e)}
|
1438 |
-
|
1439 |
-
@app.post("/send_copy")
|
1440 |
-
async def send_copy_endpoint(chat_id: int, from_chat_id: int, message_id: int, caption: str = None, parse_mode: str = None, caption_entities: list = None, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
1441 |
-
try:
|
1442 |
-
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1443 |
-
message = await bot_instance.copy_message(
|
1444 |
-
chat_id,
|
1445 |
-
from_chat_id,
|
1446 |
-
message_id,
|
1447 |
-
caption=caption,
|
1448 |
-
parse_mode=parse_mode,
|
1449 |
-
caption_entities=caption_entities,
|
1450 |
-
reply_to_message_id=reply_to_message_id,
|
1451 |
-
allow_sending_without_reply=allow_sending_without_reply,
|
1452 |
-
reply_markup=reply_markup_obj
|
1453 |
-
)
|
1454 |
-
return {"message_id": message.id}
|
1455 |
-
except Exception as e:
|
1456 |
-
logger.error(f"Error sending copy: {e}")
|
1457 |
-
return {"error": str(e)}
|
1458 |
-
|
1459 |
-
@app.post("/forward_messages")
|
1460 |
-
async def forward_messages_endpoint(chat_id: int, from_chat_id: int, message_ids: list, disable_notification: bool = False):
|
1461 |
-
try:
|
1462 |
-
messages = await bot_instance.forward_messages(
|
1463 |
-
chat_id,
|
1464 |
-
from_chat_id,
|
1465 |
-
message_ids,
|
1466 |
-
disable_notification=disable_notification
|
1467 |
-
)
|
1468 |
-
return {"messages": [msg.id for msg in messages]}
|
1469 |
-
except Exception as e:
|
1470 |
-
logger.error(f"Error forwarding messages: {e}")
|
1471 |
-
return {"error": str(e)}
|
1472 |
-
|
1473 |
-
@app.post("/text_to_speech")
|
1474 |
-
async def text_to_speech_endpoint(tts_request: TextToSpeechRequest):
|
1475 |
-
try:
|
1476 |
-
audio = await convert(tts_request.text)
|
1477 |
-
return {"audio_url": audio.name}
|
1478 |
-
except Exception as e:
|
1479 |
-
logger.error(f"Error converting text to speech: {e}")
|
1480 |
-
return {"error": str(e)}
|
1481 |
-
|
1482 |
-
async def convert(text):
|
1483 |
-
audio = BytesIO()
|
1484 |
-
i = Translator().translate(text, dest="en")
|
1485 |
-
lang = i.src
|
1486 |
-
tts = gTTS(text, lang=lang)
|
1487 |
-
audio.name = lang + ".mp3"
|
1488 |
-
tts.write_to_fp(audio)
|
1489 |
-
return audio
|
1490 |
-
|
1491 |
-
@app.post("/download_youtube_song")
|
1492 |
-
async def download_youtube_song_endpoint(yt_request: YouTubeDownloadRequest):
|
1493 |
-
try:
|
1494 |
-
results = YoutubeSearch(yt_request.url, max_results=1).to_dict()
|
1495 |
-
link = f"https://youtube.com{results[0]['url_suffix']}"
|
1496 |
-
title = results[0]["title"][:40]
|
1497 |
-
thumbnail = results[0]["thumbnails"][0]
|
1498 |
-
thumb_name = f'thumb{title}.jpg'
|
1499 |
-
thumb = requests.get(thumbnail, allow_redirects=True)
|
1500 |
-
open(thumb_name, 'wb').write(thumb.content)
|
1501 |
-
performer = f"[Mᴋɴ Bᴏᴛᴢ™]"
|
1502 |
-
duration = results[0]["duration"]
|
1503 |
-
url_suffix = results[0]["url_suffix"]
|
1504 |
-
views = results[0]["views"]
|
1505 |
-
except Exception as e:
|
1506 |
-
logger.error(f"Error downloading YouTube song: {e}")
|
1507 |
-
return {"error": str(e)}
|
1508 |
-
|
1509 |
-
ydl_opts = {"format": "bestaudio[ext=m4a]"}
|
1510 |
-
try:
|
1511 |
-
with YoutubeDL(ydl_opts) as ydl:
|
1512 |
-
info_dict = ydl.extract_info(link, download=False)
|
1513 |
-
audio_file = ydl.prepare_filename(info_dict)
|
1514 |
-
ydl.process_info(info_dict)
|
1515 |
-
except Exception as e:
|
1516 |
-
logger.error(f"Error processing YouTube song: {e}")
|
1517 |
-
return {"error": str(e)}
|
1518 |
-
|
1519 |
-
cap = "**BY›› [Mᴋɴ Bᴏᴛᴢ™](https://t.me/mkn_bots_updates)**"
|
1520 |
-
secmul, dur, dur_arr = 1, 0, duration.split(':')
|
1521 |
-
for i in range(len(dur_arr) - 1, -1, -1):
|
1522 |
-
dur += (int(dur_arr[i]) * secmul)
|
1523 |
-
secmul *= 60
|
1524 |
-
|
1525 |
-
return {"audio_file": audio_file, "caption": cap, "title": title, "duration": dur, "performer": performer, "thumb": thumb_name}
|
1526 |
-
|
1527 |
-
@app.post("/download_youtube_video")
|
1528 |
-
async def download_youtube_video_endpoint(yt_request: YouTubeDownloadRequest):
|
1529 |
-
try:
|
1530 |
-
url = yt_request.url
|
1531 |
-
search = SearchVideos(f"{url}", offset=1, mode="dict", max_results=1)
|
1532 |
-
mi = search.result()
|
1533 |
-
mio = mi["search_result"]
|
1534 |
-
mo = mio[0]["link"]
|
1535 |
-
thum = mio[0]["title"]
|
1536 |
-
fridayz = mio[0]["id"]
|
1537 |
-
mio[0]["channel"]
|
1538 |
-
kekme = f"https://img.youtube.com/vi/{fridayz}/hqdefault.jpg"
|
1539 |
-
await asyncio.sleep(0.6)
|
1540 |
-
url = mo
|
1541 |
-
sedlyf = wget.download(kekme)
|
1542 |
-
opts = {
|
1543 |
-
"format": "best",
|
1544 |
-
"addmetadata": True,
|
1545 |
-
"key": "FFmpegMetadata",
|
1546 |
-
"prefer_ffmpeg": True,
|
1547 |
-
"geo_bypass": True,
|
1548 |
-
"nocheckcertificate": True,
|
1549 |
-
"postprocessors": [{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}],
|
1550 |
-
"outtmpl": "%(id)s.mp4",
|
1551 |
-
"logtostderr": False,
|
1552 |
-
"quiet": True,
|
1553 |
-
}
|
1554 |
-
with YoutubeDL(opts) as ytdl:
|
1555 |
-
ytdl_data = ytdl.extract_info(url, download=True)
|
1556 |
-
except Exception as e:
|
1557 |
-
logger.error(f"Error downloading YouTube video: {e}")
|
1558 |
-
return {"error": str(e)}
|
1559 |
-
|
1560 |
-
file_stark = f"{ytdl_data['id']}.mp4"
|
1561 |
-
capy = f"""**𝚃𝙸𝚃𝙻𝙴 :** [{thum}]({mo})\n**𝚁𝙴𝚀𝚄𝙴𝚂𝚃𝙴𝙳 𝙱𝚈 :** {await bot_instance.get_me().mention}"""
|
1562 |
-
|
1563 |
-
return {"video_file": file_stark, "caption": capy, "title": ytdl_data["title"], "duration": int(ytdl_data["duration"]), "thumb": sedlyf}
|
1564 |
-
|
1565 |
-
@app.post("/carbon")
|
1566 |
-
async def carbon_endpoint(carbon_request: CarbonRequest):
|
1567 |
-
try:
|
1568 |
-
carbon_image = await make_carbon(carbon_request.text, True)
|
1569 |
-
return {"carbon_url": carbon_image}
|
1570 |
-
except Exception as e:
|
1571 |
-
logger.error(f"Error generating carbon image: {e}")
|
1572 |
-
return {"error": str(e)}
|
1573 |
-
|
1574 |
-
async def make_carbon(text, tele=False):
|
1575 |
-
url = "https://carbonara.solopov.dev/api/cook"
|
1576 |
-
async with aiohttp.ClientSession() as session:
|
1577 |
-
async with session.post(url, json={"code": text}) as resp:
|
1578 |
-
image = BytesIO(await resp.read())
|
1579 |
-
image.name = "carbon.png"
|
1580 |
-
if tele:
|
1581 |
-
uf = upload_file(image)
|
1582 |
-
image.close()
|
1583 |
-
return f"https://graph.org{uf[0]}"
|
1584 |
-
return image
|
1585 |
-
|
1586 |
-
@app.post("/font")
|
1587 |
-
async def font_endpoint(font_request: FontRequest):
|
1588 |
-
fonts = {
|
1589 |
-
"typewriter": Fonts.typewriter,
|
1590 |
-
"outline": Fonts.outline,
|
1591 |
-
"serif": Fonts.serief,
|
1592 |
-
"bold_cool": Fonts.bold_cool,
|
1593 |
-
"cool": Fonts.cool,
|
1594 |
-
"small_cap": Fonts.smallcap,
|
1595 |
-
"script": Fonts.script,
|
1596 |
-
"bold_script": Fonts.bold_script,
|
1597 |
-
"tiny": Fonts.tiny,
|
1598 |
-
"comic": Fonts.comic,
|
1599 |
-
"san": Fonts.san,
|
1600 |
-
"slant_san": Fonts.slant_san,
|
1601 |
-
"slant": Fonts.slant,
|
1602 |
-
"sim": Fonts.sim,
|
1603 |
-
"circles": Fonts.circles,
|
1604 |
-
"dark_circle": Fonts.dark_circle,
|
1605 |
-
"gothic": Fonts.gothic,
|
1606 |
-
"bold_gothic": Fonts.bold_gothic,
|
1607 |
-
"cloud": Fonts.cloud,
|
1608 |
-
"happy": Fonts.happy,
|
1609 |
-
"sad": Fonts.sad,
|
1610 |
-
"special": Fonts.special,
|
1611 |
-
"square": Fonts.square,
|
1612 |
-
"dark_square": Fonts.dark_square,
|
1613 |
-
"andalucia": Fonts.andalucia,
|
1614 |
-
"manga": Fonts.manga,
|
1615 |
-
"stinky": Fonts.stinky,
|
1616 |
-
"bubbles": Fonts.bubbles,
|
1617 |
-
"underline": Fonts.underline,
|
1618 |
-
"ladybug": Fonts.ladybug,
|
1619 |
-
"rays": Fonts.rays,
|
1620 |
-
"birds": Fonts.birds,
|
1621 |
-
"slash": Fonts.slash,
|
1622 |
-
"stop": Fonts.stop,
|
1623 |
-
"skyline": Fonts.skyline,
|
1624 |
-
"arrows": Fonts.arrows,
|
1625 |
-
"rvnes": Fonts.rvnes,
|
1626 |
-
"strike": Fonts.strike,
|
1627 |
-
"frozen": Fonts.frozen
|
1628 |
-
}
|
1629 |
-
cls = fonts.get(font_request.style)
|
1630 |
-
if not cls:
|
1631 |
-
return {"error": "Invalid style"}
|
1632 |
-
try:
|
1633 |
-
new_text = cls(font_request.text)
|
1634 |
-
return {"new_text": new_text}
|
1635 |
-
except Exception as e:
|
1636 |
-
logger.error(f"Error applying font style: {e}")
|
1637 |
-
return {"error": str(e)}
|
1638 |
-
|
1639 |
-
@app.post("/paste")
|
1640 |
-
async def paste_endpoint(paste_request: PasteRequest):
|
1641 |
-
try:
|
1642 |
-
paste_response = await p_paste(paste_request.text)
|
1643 |
-
return paste_response
|
1644 |
-
except Exception as e:
|
1645 |
-
logger.error(f"Error pasting text: {e}")
|
1646 |
-
return {"error": str(e)}
|
1647 |
-
|
1648 |
-
async def p_paste(code, extension=None):
|
1649 |
-
siteurl = "https://pasty.lus.pm/api/v1/pastes"
|
1650 |
-
data = {"content": code}
|
1651 |
-
try:
|
1652 |
-
response = requests.post(url=siteurl, data=json.dumps(data), headers={"User-Agent": "Mozilla/5.0", "content-type": "application/json"})
|
1653 |
-
except Exception as e:
|
1654 |
-
return {"error": str(e)}
|
1655 |
-
if response.ok:
|
1656 |
-
response = response.json()
|
1657 |
-
purl = (
|
1658 |
-
f"https://pasty.lus.pm/{response['id']}.{extension}"
|
1659 |
-
if extension
|
1660 |
-
else f"https://pasty.lus.pm/{response['id']}.txt"
|
1661 |
-
)
|
1662 |
-
return {
|
1663 |
-
"url": purl,
|
1664 |
-
"raw": f"https://pasty.lus.pm/{response['id']}/raw",
|
1665 |
-
"bin": "Pasty",
|
1666 |
-
}
|
1667 |
-
return {"error": "Unable to reach pasty.lus.pm"}
|
1668 |
-
|
1669 |
-
@app.post("/share_text")
|
1670 |
-
async def share_text_endpoint(share_request: ShareTextRequest):
|
1671 |
-
try:
|
1672 |
-
share_url = f"https://t.me/share/url?url={quote(share_request.text)}"
|
1673 |
-
return {"share_url": share_url}
|
1674 |
-
except Exception as e:
|
1675 |
-
logger.error(f"Error sharing text: {e}")
|
1676 |
-
return {"error": str(e)}
|
1677 |
-
|
1678 |
-
@app.post("/telegraph_upload")
|
1679 |
-
async def telegraph_upload_endpoint(upload_request: TelegraphUploadRequest):
|
1680 |
-
try:
|
1681 |
-
response = upload_file(upload_request.file_path)
|
1682 |
-
telegraph_url = f"https://graph.org{response[0]}"
|
1683 |
-
return {"telegraph_url": telegraph_url}
|
1684 |
-
except Exception as e:
|
1685 |
-
logger.error(f"Error uploading to Telegraph: {e}")
|
1686 |
-
return {"error": str(e)}
|
1687 |
-
|
1688 |
-
# Ensure the Fonts class is imported from the appropriate module
|
1689 |
-
# from image.font_string import Fonts
|
1690 |
-
|
1691 |
-
if __name__ == "__main__":
|
1692 |
-
import uvicorn
|
1693 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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