async def service_msg(client, message): if message.service == 'voice_chat_started': Config.IS_ACTIVE = True k = scheduler.get_job(str(Config.CHAT), jobstore=None) #scheduled records if k: await start_record_stream() LOGGER.info("Resuming recording..") elif Config.WAS_RECORDING: LOGGER.info( "Previous recording was ended unexpectedly, Now resuming recordings." ) await start_record_stream() #for unscheduled a = await client.send( GetFullChannel(channel=(await client.resolve_peer(Config.CHAT)))) if a.full_chat.call is not None: Config.CURRENT_CALL = a.full_chat.call.id LOGGER.info("Voice chat started.") await sync_to_db() elif message.service == 'voice_chat_scheduled': LOGGER.info("VoiceChat Scheduled") Config.IS_ACTIVE = False Config.HAS_SCHEDULE = True await sync_to_db() elif message.service == 'voice_chat_ended': Config.IS_ACTIVE = False LOGGER.info("Voicechat ended") Config.CURRENT_CALL = None if Config.IS_RECORDING: Config.WAS_RECORDING = True await stop_recording() await sync_to_db() else: pass
async def _get_banned_rights(message: Message) -> ChatBannedRights: peer = await message.client.resolve_peer(message.chat.id) if isinstance(peer, InputPeerChannel): return (await message.client.send(GetFullChannel(channel=peer) )).chats[0].default_banned_rights return (await message.client.send(GetFullChat(chat_id=peer.chat_id) )).chats[0].default_banned_rights
async def get_group_call(message: Message, err_msg: str = "") -> Optional[InputGroupCall]: chat_peer = await userge.resolve_peer(message.chat.id) if isinstance(chat_peer, (InputPeerChannel, InputPeerChat)): if isinstance(chat_peer, InputPeerChannel): full_chat = (await userge.send(GetFullChannel(channel=chat_peer) )).full_chat elif isinstance(chat_peer, InputPeerChat): full_chat = (await userge.send(GetFullChat(chat_id=chat_peer.chat_id) )).full_chat if full_chat is not None: return full_chat.call await message.err(f"**No Voice Chat Found** !{err_msg}", del_in=8) return False
async def get_call( self, chat_id: int, ) -> Optional[InputGroupCall]: chat = await self._app.resolve_peer(chat_id) if isinstance(chat, InputPeerChannel): return ( await self._app.send( GetFullChannel( channel=InputChannel( channel_id=chat.channel_id, access_hash=chat.access_hash, ), ), ) ).full_chat.call else: return ( await self._app.send( GetFullChat(chat_id=chat.chat_id), ) ).full_chat.call
async def get_call( self, chat_id: int, ) -> Optional[InputGroupCall]: chat = await self._app.resolve_peer(chat_id) if isinstance(chat, InputPeerChannel): input_call = (await self._app.send( GetFullChannel(channel=InputChannel( channel_id=chat.channel_id, access_hash=chat.access_hash, ), ), )).full_chat.call else: input_call = (await self._app.send( GetFullChat(chat_id=chat.chat_id), )).full_chat.call if input_call is not None: call: GroupCall = (await self._app.send( GetGroupCall( call=input_call, limit=-1, ), )).call if call.schedule_date is not None: return None return input_call
async def _load_full_chat(self, chat_id: int) -> ChatFull: curr_time = int(time()) load_cache = False if chat_id in self.pytgcalls._cache_full_chat: if curr_time - self.pytgcalls._cache_full_chat[chat_id][ 'last_update'] < 120: load_cache = True if load_cache: full_chat = self.pytgcalls._cache_full_chat[chat_id]['full_chat'] else: chat = await self.pytgcalls._app.resolve_peer(chat_id) full_chat = await self.pytgcalls._app.send( GetFullChannel(channel=chat), ) self.pytgcalls._cache_full_chat[chat_id] = { 'last_update': curr_time, 'full_chat': full_chat, } if self.pytgcalls._log_mode > 1: print( 'Pyrogram -> GetFullChannel', f'executed with {"cache" if load_cache else "Telegram"}', ) return full_chat
async def change_vc_title(title: str, chat_id): peer = await app.resolve_peer(chat_id) chat = await app.send(GetFullChannel(channel=peer)) data = EditGroupCallTitle(call=chat.full_chat.call, title=title) await app.send(data)
async def leave_group_call(client, chat_id): peer = await client.resolve_peer(chat_id) full_chat = await client.send(GetFullChannel(channel=peer)) chat_call = full_chat.full_chat.call await client.send(LeaveGroupCall(call=chat_call, source=0))
async def handle_raw_updates(client: Client, update: Update, user: dict, chat: dict): if isinstance(update, UpdateGroupCallParticipants): if not Config.CURRENT_CALL: a = await client.send( GetFullChannel( channel=(await client.resolve_peer(Config.CHAT)))) if a.full_chat.call is not None: Config.CURRENT_CALL = a.full_chat.call.id if Config.CURRENT_CALL and update.call.id == Config.CURRENT_CALL: all = update.participants old = list( filter( lambda k: k.peer.user_id if hasattr(k.peer, 'user_id') else k.peer.channel_id == Config.USER_ID, all)) if old: for me in old: if me.volume: Config.VOLUME = round(int(me.volume) / 100) if isinstance(update, UpdateGroupCall) and (update.chat_id == int(-1000000000000 - Config.CHAT)): if update.call is None: Config.IS_ACTIVE = False Config.CURRENT_CALL = None LOGGER.warning("No Active Group Calls Found.") if Config.IS_RECORDING: Config.WAS_RECORDING = True await stop_recording() LOGGER.warning( "Group call was ended and hence stoping recording.") Config.HAS_SCHEDULE = False await sync_to_db() return else: call = update.call if isinstance(call, GroupCallDiscarded): Config.CURRENT_CALL = None Config.IS_ACTIVE = False if Config.IS_RECORDING: Config.WAS_RECORDING = True await stop_recording() LOGGER.warning("Group Call Was ended") Config.CALL_STATUS = False await sync_to_db() return Config.IS_ACTIVE = True Config.CURRENT_CALL = call.id if Config.IS_RECORDING and not call.record_video_active: Config.LISTEN = True await stop_recording() LOGGER.warning( "Recording was ended by user, hence stopping the schedules." ) return if call.schedule_date: Config.HAS_SCHEDULE = True else: Config.HAS_SCHEDULE = False await sync_to_db()
async def _load_full_chat(self, chat_id: int) -> ChatFull: chat = await self.pytgcalls._app.resolve_peer(chat_id) full_chat = await self.pytgcalls._app.send( GetFullChannel(channel=chat), ) return full_chat
def allGP(client, message,redis): type = message.chat.type userID = message.from_user.id chatID = message.chat.id username = message.from_user.username if username is None: username = "******" userFN = message.from_user.first_name title = message.chat.title rank = isrank(redis,userID,chatID) text = message.text c = importlib.import_module("lang.arcmd") r = importlib.import_module("lang.arreply") redis.hincrby("{}Nbot:{}:msgs".format(BOT_ID,chatID),userID) if text : if text == "منو ضافني": get = redis.hget("{}Nbot:MowAddMe:{}".format(BOT_ID,chatID),userID) if get: Bot("sendMessage",{"chat_id":chatID,"text":f"تم اضافتك بواسطة ⏺: {get}","reply_to_message_id":message.message_id}) if re.search(c.setGPadmin,text): if re.search("@",text): user = text.split("@")[1] if re.search(c.setGPadmin2,text): user = int(re.search(r'\d+', text).group()) if message.reply_to_message: user = message.reply_to_message.from_user.id if 'user' not in locals():return False if GPranks(userID,chatID) == "member":return False Getus = Bot("getChatMember",{"chat_id":chatID,"user_id":userID})["result"] if Getus["status"] == "administrator" and not Getus["can_promote_members"]:return False try: getUser = client.get_users(user) userId = getUser.id userFn = getUser.first_name if GPranks(userId,chatID) != "member":return False pr = Bot("promoteChatMember",{"chat_id":chatID,"user_id":userId,"can_change_info":1,"can_delete_messages":1,"can_invite_users":1,"can_restrict_members":1,"can_pin_messages":1}) if pr["ok"]: T ="<a href=\"tg://user?id={}\">{}</a>".format(userId,Name(userFn)) Bot("sendMessage",{"chat_id":chatID,"text":r.prGPadmin.format(T),"reply_to_message_id":message.message_id,"parse_mode":"html"}) except Exception as e: Bot("sendMessage",{"chat_id":chatID,"text":r.userNocc,"reply_to_message_id":message.message_id,"parse_mode":"html"}) if re.search(c.sors,text): kb = InlineKeyboardMarkup([[InlineKeyboardButton("قناه السورس 📢", url="t.me/zx_xx")],[InlineKeyboardButton("تواصل السورس 💬", url="t.me/A_5bot")],[InlineKeyboardButton("شروحات السورس 📑", url="t.me/tshaketeam")]]) Botuser = client.get_me().username Bot("sendMessage",{"chat_id":chatID,"text":r.sors.format("@"+Botuser),"disable_web_page_preview":True,"reply_to_message_id":message.message_id,"parse_mode":"markdown","reply_markup":kb}) if re.search(c.dellink,text): kb = InlineKeyboardMarkup([[InlineKeyboardButton(c.dellink2, url="https://telegram.org/deactivate")]]) Botuser = client.get_me().username Bot("sendMessage",{"chat_id":chatID,"text":r.dellink,"disable_web_page_preview":True,"reply_to_message_id":message.message_id,"parse_mode":"markdown","reply_markup":kb}) if re.search(c.ShowO,text) and (rank is not False or rank is not 0 or rank != "vip"): reply_markup = getOR(rank,r,userID) Bot("sendMessage",{"chat_id":chatID,"text":r.Showall,"reply_to_message_id":message.message_id,"parse_mode":"html","disable_web_page_preview":True,"reply_markup":reply_markup}) if text == "عدد الكروب" and (rank is not False or rank is not 0 ): from pyrogram.raw.functions.channels import GetFullChannel chat = client.resolve_peer(chatID) full_chat = client.send(GetFullChannel(channel=chat)).full_chat Bot("sendMessage",{"chat_id":chatID,"text":r.gpinfo.format(message.chat.title,full_chat.participants_count,full_chat.admins_count,full_chat.kicked_count,full_chat.banned_count,message.message_id),"reply_to_message_id":message.message_id,"parse_mode":"html","disable_web_page_preview":True}) if text == c.ID and not redis.sismember("{}Nbot:IDSend".format(BOT_ID),chatID) and not message.reply_to_message: Ch = True t = IDrank(redis,userID,chatID,r) msgs = (redis.hget("{}Nbot:{}:msgs".format(BOT_ID,chatID),userID) or 0) edits = (redis.hget("{}Nbot:{}:edits".format(BOT_ID,chatID),userID) or 0) rate = int(msgs)*100/20000 age = getAge(userID,r) if redis.hget("{}Nbot:SHOWid".format(BOT_ID),chatID): tx = redis.hget("{}Nbot:SHOWid".format(BOT_ID),chatID) rep = {"#age":"{age}","#name":"{name}","#id":"{id}","#username":"******","#msgs":"{msgs}","#stast":"{stast}","#edits":"{edits}","#rate":"{rate}","{us}":"{username}","#us":"{username}"} for v in rep.keys(): tx = tx.replace(v,rep[v]) else: tx = r.IDnPT if not redis.sismember("{}Nbot:IDSendPH".format(BOT_ID),chatID): get = Bot("getUserProfilePhotos",{"user_id":userID,"offset":0,"limit":1}) if get["ok"] == False: Ch = True elif get["result"]["total_count"] == 0: Ch = True else: Ch = False file_id = get["result"]["photos"][0][0]["file_id"] Bot("sendPhoto",{"chat_id":chatID,"photo":file_id,"caption":tx.format(username=("@"+username or "None"),id=userID,stast=t,msgs=msgs,edits=edits,age=age,rate=str(rate)+"%"),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if Ch == True: Bot("sendMessage",{"chat_id":chatID,"text":tx.format(username=("@"+username or "None"),id=userID,stast=t,msgs=msgs,edits=edits,age=age,rate=str(rate)+"%"),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if text == "رتبتي": t = IDrank(redis,userID,chatID,r) Bot("sendMessage",{"chat_id":chatID,"text":f"⏏️꒐ موقعك : {t}","reply_to_message_id":message.message_id,"parse_mode":"html"}) if text == c.ID and not redis.sismember("{}Nbot:IDSend".format(BOT_ID),chatID) and message.reply_to_message: us = message.reply_to_message.from_user.id rusername = message.reply_to_message.from_user.username if rusername is None: rusername = "******" t = IDrank(redis,us,chatID,r) msgs = (redis.hget("{}Nbot:{}:msgs".format(BOT_ID,chatID),us) or 0) edits = (redis.hget("{}Nbot:{}:edits".format(BOT_ID,chatID),us) or 0) rate = int(msgs)*100/20000 age = getAge(us,r) tx = r.ReIDnPT if redis.hget("{}Nbot:SHOWid".format(BOT_ID),chatID): tx = redis.hget("{}Nbot:SHOWid".format(BOT_ID),chatID) rep = {"#age":"{age}","#name":"{name}","#id":"{id}","#username":"******","#msgs":"{msgs}","#stast":"{stast}","#edits":"{edits}","#rate":"{rate}","{us}":"{username}","#us":"{username}"} for v in rep.keys(): tx = tx.replace(v,rep[v]) else: tx = r.ReIDnPT Bot("sendMessage",{"chat_id":chatID,"text":tx.format(username=("@"+rusername or "None"),id=us,stast=t,msgs=msgs,edits=edits,age=age,rate=str(rate)+"%"),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if re.search(c.idus,text) and not redis.sismember("{}Nbot:IDSend".format(BOT_ID),chatID): user = text.split("@")[1] try: getUser = client.get_users(user) us = getUser.id rusername = user if rusername is None: rusername = "******" age = getAge(us,r) t = IDrank(redis,us,chatID,r) msgs = (redis.hget("{}Nbot:{}:msgs".format(BOT_ID,chatID),us) or 0) edits = (redis.hget("{}Nbot:{}:edits".format(BOT_ID,chatID),us) or 0) rate = int(msgs)*100/20000 tx = r.ReIDnPT Bot("sendMessage",{"chat_id":chatID,"text":tx.format(username=("@"+rusername or "None"),id=us,stast=t,msgs=msgs,edits=edits,age=age,rate=str(rate)+"%"),"reply_to_message_id":message.message_id,"parse_mode":"html"}) except Exception as e: print(e) if re.search(c.ShowSudos, text): tx = (redis.get("{}Nbot:SHOWsudos".format(BOT_ID)) or "") Bot("sendMessage",{"chat_id":chatID,"text":tx,"reply_to_message_id":message.message_id,"parse_mode":"html"}) if text == c.mymsgs: get = redis.hget("{}Nbot:{}:msgs".format(BOT_ID,chatID),userID) Bot("sendMessage",{"chat_id":chatID,"text":r.yourmsgs.format((get or 0)),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if text == c.link and not redis.sismember("{}Nbot:showlink".format(BOT_ID),chatID): get = (redis.hget("{}Nbot:links".format(BOT_ID),chatID) or GetLink(chatID) or "none") Bot("sendMessage",{"chat_id":chatID,"text":r.showGPlk.format(get),"reply_to_message_id":message.message_id,"parse_mode":"html","disable_web_page_preview":True}) if text == c.myedits: get = redis.hget("{}Nbot:{}:edits".format(BOT_ID,chatID),userID) Bot("sendMessage",{"chat_id":chatID,"text":r.youredits.format((get or 0)),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if text == c.myaddcontact: get = redis.hget("{}Nbot:{}:addcontact".format(BOT_ID,chatID),userID) Bot("sendMessage",{"chat_id":chatID,"text":r.youraddcontact.format((get or 0)),"reply_to_message_id":message.message_id,"parse_mode":"html"}) if not redis.sismember("{}Nbot:ReplySendBOT".format(BOT_ID),chatID): if redis.hexists("{}Nbot:TXreplys".format(BOT_ID),text): tx = redis.hget("{}Nbot:TXreplys".format(BOT_ID),text) try: rep = {"#cn":"{cn}","#age":"{age}","#fn":"{fn}","#id":"{id}","#username":"******","#msgs":"{msgs}","#stast":"{stast}","#edits":"{edits}","#rate":"{rate}","{us}":"{username}","#us":"{username}"} for v in rep.keys(): tx = tx.replace(v,rep[v]) Bot("sendMessage",{"chat_id":chatID,"text":tx.format(fn=userFN,username=("@"+username or "n"),id=userID,stast=IDrank(redis,userID,chatID,r),cn=title),"reply_to_message_id":message.message_id,"parse_mode":"html"}) except Exception as e: Bot("sendMessage",{"chat_id":chatID,"text":tx,"reply_to_message_id":message.message_id,"parse_mode":"html"}) if not redis.sismember("{}Nbot:ReplyMedia".format(BOT_ID),chatID): if redis.hexists("{}Nbot:STreplys".format(BOT_ID),text): ID = redis.hget("{}Nbot:STreplys".format(BOT_ID),text) Bot("sendSticker",{"chat_id":chatID,"sticker":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:GFreplys".format(BOT_ID),text): ID = redis.hget("{}Nbot:GFreplys".format(BOT_ID),text) Bot("sendanimation",{"chat_id":chatID,"animation":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:VOreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:VOreplys".format(BOT_ID),text) Bot("sendvoice",{"chat_id":chatID,"voice":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:PHreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:PHreplys".format(BOT_ID),text) Bot("sendphoto",{"chat_id":chatID,"photo":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:DOreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:DOreplys".format(BOT_ID),text) Bot("sendDocument",{"chat_id":chatID,"document":ID,"reply_to_message_id":message.message_id}) if not redis.sismember("{}Nbot:ReplySend".format(BOT_ID),chatID): if redis.hexists("{}Nbot:{}:TXreplys".format(BOT_ID,chatID),text): tx = redis.hget("{}Nbot:{}:TXreplys".format(BOT_ID,chatID),text) try: rep = {"#cn":"{cn}","#age":"{age}","#fn":"{fn}","#id":"{id}","#username":"******","#msgs":"{msgs}","#stast":"{stast}","#edits":"{edits}","#rate":"{rate}","{us}":"{username}","#us":"{username}"} for v in rep.keys(): tx = tx.replace(v,rep[v]) Bot("sendMessage",{"chat_id":chatID,"text":tx.format(fn=userFN,username=("@"+username or "n"),id=userID,stast=IDrank(redis,userID,chatID,r),cn=title),"reply_to_message_id":message.message_id,"parse_mode":"html"}) except Exception as e: Bot("sendMessage",{"chat_id":chatID,"text":tx,"reply_to_message_id":message.message_id,"parse_mode":"html"}) if not redis.sismember("{}Nbot:ReplyMedia".format(BOT_ID),chatID): if redis.hexists("{}Nbot:{}:STreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:STreplys".format(BOT_ID,chatID),text) Bot("sendSticker",{"chat_id":chatID,"sticker":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:GFreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:GFreplys".format(BOT_ID,chatID),text) Bot("sendanimation",{"chat_id":chatID,"animation":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:VOreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:VOreplys".format(BOT_ID,chatID),text) Bot("sendvoice",{"chat_id":chatID,"voice":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:AUreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:AUreplys".format(BOT_ID,chatID),text) Bot("sendaudio",{"chat_id":chatID,"audio":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:PHreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:PHreplys".format(BOT_ID,chatID),text) Bot("sendphoto",{"chat_id":chatID,"photo":ID,"reply_to_message_id":message.message_id}) if redis.hexists("{}Nbot:{}:DOreplys".format(BOT_ID,chatID),text): ID = redis.hget("{}Nbot:{}:DOreplys".format(BOT_ID,chatID),text) Bot("sendDocument",{"chat_id":chatID,"document":ID,"reply_to_message_id":message.message_id}) if redis.smembers("{}Nbot:botfiles".format(BOT_ID)): onlyfiles = [f for f in listdir("files") if isfile(join("files", f))] filesR = redis.smembers("{}Nbot:botfiles".format(BOT_ID)) for f in onlyfiles: if f in filesR: fi = f.replace(".py","") UpMs= "files."+fi try: U = importlib.import_module(UpMs) t = threading.Thread(target=U.updateMsgs,args=(client, message,redis)) t.daemon = True t.start() importlib.reload(U) except Exception as e: import traceback traceback.print_exc() print(e) pass