def run(self, before_start_callable: Callable = None): if self._app is not None: node_result = self.get_version('node') if node_result['version_int'] == 0: raise Exception('Please install node (15.+)') if node_result['version_int'] < 15: raise Exception( 'Needed node 15.+, ' 'actually installed is ' f"{node_result['version']}", ) if int(__version__.split('.')[2]) < 13 and \ int(__version__.split('.')[1]) == 1 and \ int(__version__.split('.')[0]) == 1: raise Exception( 'Needed pyrogram 1.1.13+, ' 'actually installed is ' f'{__version__}', ) try: # noinspection PyBroadException @self._app.on_raw_update() async def on_close(client, update, _, data2): if isinstance(update, UpdateChannel): chat_id = int(f'-100{update.channel_id}') if len(data2) > 0: if isinstance( data2[update.channel_id], ChannelForbidden, ): for event in self._on_event_update[ 'KICK_HANDLER']: await event['callable'](chat_id, ) # noinspection PyBroadException try: self.leave_group_call( chat_id, 'kicked_from_group', ) except Exception: pass try: del self._cache_user_peer[chat_id] except Exception: pass if isinstance( update, UpdateGroupCall, ): if isinstance( update.call, GroupCallDiscarded, ): chat_id = int(f'-100{update.chat_id}') for event in self._on_event_update[ 'CLOSED_HANDLER']: await event['callable'](chat_id, ) # noinspection PyBroadException try: self.leave_group_call( chat_id, 'closed_voice_chat', ) except Exception: pass try: del self._cache_user_peer[chat_id] except Exception: pass if isinstance( update, UpdateNewChannelMessage, ): try: if isinstance( update.message.action, MessageActionInviteToGroupCall, ): for event in self._on_event_update[ 'GROUP_CALL_HANDLER']: await event['callable']( client, update.message, ) except Exception: pass self._app.start() self._my_id = self._app.get_me()['id'] # noqa self._cache_local_peer = self._app.resolve_peer(self._my_id, ) if before_start_callable is not None: # noinspection PyBroadException try: result = before_start_callable(self._my_id) if isinstance(result, bool): if not result: return except Exception: pass self._spawn_process( self._run_js, ( f'{__file__.replace("pytgcalls.py", "")}js/core.js', f'port={self._port} log_mode={self._log_mode}', ), ) except KeyboardInterrupt: pass self._start_web_app() self.is_running = True else: raise Exception('NEED_PYROGRAM_CLIENT') return self
def run(self, before_start_callable: Callable = None): if self._app is not None: if int(__version__.split('.')[1]) < 2 and \ int(__version__.split('.')[0]) == 1: raise Exception( 'Needed pyrogram 1.2.0+, ' 'actually installed is ' f'{__version__}', ) a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) location = ('127.0.0.1', self._port) result_of_check = a_socket.connect_ex(location) is_already_in_use = result_of_check == 0 a_socket.close() if not is_already_in_use: try: # noinspection PyBroadException @self._app.on_raw_update() async def on_close(client, update, _, data2): if isinstance(update, UpdateGroupCall): if isinstance(update.call, GroupCallDiscarded): chat_id = int(f'-100{update.chat_id}') self._cache_full_chat[chat_id] = { 'last_update': int(time()), 'full_chat': None, } if isinstance(update.call, GroupCall): input_group_call = InputGroupCall( access_hash=update.call.access_hash, id=update.call.id, ) chat_id = int(f'-100{update.chat_id}') self._cache_full_chat[chat_id] = { 'last_update': int(time()), 'full_chat': input_group_call, } if isinstance(update, UpdateChannel): chat_id = int(f'-100{update.channel_id}') if len(data2) > 0: if isinstance( data2[update.channel_id], ChannelForbidden, ): for event in self._on_event_update[ 'KICK_HANDLER']: await event['callable'](chat_id, ) # noinspection PyBroadException try: self.leave_group_call( chat_id, 'kicked_from_group', ) except Exception: pass try: del self._cache_user_peer[chat_id] except Exception: pass if isinstance( update, UpdateGroupCall, ): if isinstance( update.call, GroupCallDiscarded, ): chat_id = int(f'-100{update.chat_id}') for event in self._on_event_update[ 'CLOSED_HANDLER']: await event['callable'](chat_id, ) # noinspection PyBroadException try: self.leave_group_call( chat_id, 'closed_voice_chat', ) except Exception: pass try: del self._cache_user_peer[chat_id] except Exception: pass if isinstance( update, UpdateNewChannelMessage, ): try: if isinstance( update.message.action, MessageActionInviteToGroupCall, ): for event in self._on_event_update[ 'GROUP_CALL_HANDLER']: await event['callable']( client, update.message, ) except Exception: pass self._app.start() self._my_id = self._app.get_me()['id'] # noqa self._cache_local_peer = self._app.resolve_peer( self._my_id, ) if before_start_callable is not None: # noinspection PyBroadException try: result = before_start_callable(self._my_id) if isinstance(result, bool): if not result: return except Exception: pass print(f'Starting on port: {self._port}') except KeyboardInterrupt: pass try: asyncio.get_event_loop().run_until_complete( self._prepare_run( f'{__file__.replace("pytgcalls.py", "")}', f'port={self._port} log_mode={self._log_mode}')) except KeyboardInterrupt: print( f'\n{self.pytgcalls.FAIL} ' f'GO Core Stopped, ' f'press Ctrl+C again to exit!' f'{self.pytgcalls.ENDC}', ) else: raise OSError(f'error while attempting to bind on address ' f'{location}: address already in use') else: raise Exception('NEED_PYROGRAM_CLIENT') return self
import sys from datetime import datetime sys.path.insert(0, os.path.abspath("../..")) from pyrogram import __version__ from pygments.styles.friendly import FriendlyStyle FriendlyStyle.background_color = "#f3f2f1" project = "Pyrogram" copyright = f"2017-present, Dan" author = "Dan" version = ".".join(__version__.split(".")[:-1]) extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx.ext.autosummary", "sphinx_copybutton" ] master_doc = "index" source_suffix = ".rst" autodoc_member_order = "bysource" templates_path = ["_resources/templates"] html_copy_source = False
from pyrogram import (Emoji, InlineQuery, InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, __version__) from ..assistant import Assistant from ..utils import docs NEXT_OFFSET = 25 CACHE_TIME = 5 FIRE_THUMB = "https://i.imgur.com/qhYYqZa.png" ROCKET_THUMB = "https://i.imgur.com/PDaYHd8.png" OPEN_BOOK_THUMB = "https://i.imgur.com/v1XSJ1D.png" VERSION = __version__.split("-")[0] @Assistant.on_inline_query() async def inline(bot: Assistant, query: InlineQuery): string = query.query.lower() if string == "": await query.answer( results=docs.DEFAULT_RESULTS, cache_time=CACHE_TIME, switch_pm_text= f"{Emoji.MAGNIFYING_GLASS_TILTED_RIGHT} Type to search Pyrogram Docs", switch_pm_parameter="start", )
from pyrogram import (Emoji, InlineQuery, InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, __version__) from ..assistant import Assistant from ..utils import docs NEXT_OFFSET = 25 CACHE_TIME = 5 FIRE_THUMB = "https://i.imgur.com/qhYYqZa.png" ROCKET_THUMB = "https://i.imgur.com/PDaYHd8.png" OPEN_BOOK_THUMB = "https://i.imgur.com/v1XSJ1D.png" VERSION = ".".join(__version__.split(".")[:3]) @Assistant.on_inline_query() async def inline(bot: Assistant, query: InlineQuery): string = query.query.lower() if string == "": await query.answer( results=docs.DEFAULT_RESULTS, cache_time=CACHE_TIME, switch_pm_text= f"{Emoji.MAGNIFYING_GLASS_TILTED_RIGHT} Type to search Pyrogram Docs", switch_pm_parameter="start", )