async def main() -> None: """Register logger and components.""" config = Config() handler = TGChannelLogHandler(config.log_bot_token, config.log_channel_id) await handler.connect() tlog.addHandler(handler) client = Client(str(config.session_name), config.api_id, config.api_hash) # noinspection PyTypeChecker await client.start(config.phone) client.config = config client.kantek_version = __version__ client.plugin_mgr = PluginManager(client) client.plugin_mgr.register_all() logger.info('Connecting to Database') client.db = Database() await client.db.connect(config) tlog.info('Started Kantek v%s [%s]', __version__, helpers.link_commit(helpers.get_commit())) logger.info('Started Kantek v%s', __version__) if config.spamwatch_host and config.spamwatch_token: client.sw = SWClient(config.spamwatch_token, host=config.spamwatch_host) client.sw_url = config.spamwatch_host await client.run_until_disconnected()
async def update(client: Client, event: Command, tags: Tags) -> None: """Run git pull and exit. This command assumes the bot is running under a process manager that automatically restarts it. Tags: update: Set to `silent` to silence any messages Examples: {cmd} """ silent = tags.get('update', False) if not silent: progess_message = await client.respond(event, MDTeXDocument( Section('Updating', f'Running {Code("git pull")}'))) else: await event.delete() subprocess.call(['git', 'pull', '-q']) new_commit = helpers.get_commit() if not silent: await progess_message.delete() await client.respond( event, MDTeXDocument( Section('Updated Kantek', KeyValueItem('New commit', Link(new_commit, helpers.link_commit(new_commit))), Italic('Restarting bot')))) await client.disconnect()
async def main() -> None: """Register logger and components.""" config = Config() handler = TGChannelLogHandler(config.log_bot_token, config.log_channel_id) await handler.connect() tlog.addHandler(handler) db = Database() await db.connect(config) client = Client(str(config.session_name), config.api_id, config.api_hash, request_retries=8, retry_delay=10, auto_reconnect=True, flood_sleep_threshold=60) # noinspection PyTypeChecker await client.connect() if not await client.is_user_authorized(): await client.start() client.config = config client.kantek_version = __version__ client.plugin_mgr = PluginManager(client) client.plugin_mgr.register_all() logger.info('Connecting to Database') client.db = db tlog.info('Started Kantek v%s [%s]', __version__, helpers.link_commit(helpers.get_commit())) logger.info('Started Kantek v%s', __version__) if config.spamwatch_host and config.spamwatch_token: client.sw = SWClient(config.spamwatch_token, host=config.spamwatch_host) try: client.swo = SWClient(config.original_spamwatch_token) except: pass client.sw_url = config.spamwatch_host ich = await client.get_me() if not ich: client.self_id = 12345678 else: client.self_id = ich.id await client.db.hashlist.add_column(self_id=client.self_id) print(config.sudos) #await client.catch_up() await client.run_until_disconnected()
async def update(client: Client, event: Command, tags: Tags) -> None: """Run git pull and exit. This command assumes the bot is running under a process manager that automatically restarts it. Tags: update: Set to `silent` to silence any messages Examples: {cmd} """ silent = tags.get('update', False) old_commit = helpers.get_commit() # region git pull if not silent: progess_message = await client.respond( event, KanTeXDocument(Section('Updating', f'Running {Code("git pull")}'))) else: await event.delete() proc = subprocess.call(['git', 'pull', '-q']) if proc != 0: msg = KanTeXDocument( Section('Error', f'{Code("git")} returned non-zero exit code.', 'Please update manually')) if not silent: await progess_message.edit(str(msg)) else: await client.respond(event, msg) return # endregion new_commit = helpers.get_commit() if old_commit == new_commit: await client.respond( event, KanTeXDocument( Section('No Update Available', Italic('Doing nothing')))) return # region pip install proc = subprocess.call(['pip', 'install', '-r', 'requirements.txt']) if proc != 0: msg = KanTeXDocument( Section('Error', f'{Code("pip")} returned non-zero exit code.', 'Please update manually')) if not silent: await progess_message.edit(str(msg)) else: await client.respond(event, msg) return # endregion # region migrant ''' if not silent: await progess_message.edit(str(KanTeXDocument( Section('Updating', f'Running {Code("migrant apply --all")}')))) proc = subprocess.run(['migrant', 'apply', '--all'], stderr=subprocess.PIPE) if proc.returncode != 0: if b'MigrationComplete' not in proc.stderr: msg = KanTeXDocument( Section('Error', f'{Code("migrant")} returned non-zero exit code.', 'Please update manually')) if not silent: await progess_message.edit(str(msg)) else: await client.respond(event, msg) return # endregion ''' if not silent: await progess_message.delete() await client.respond( event, KanTeXDocument( Section( 'Updated Kantek', KeyValueItem( 'New commit', Link(new_commit, helpers.link_commit(new_commit))), Italic('Restarting bot')))) await client.disconnect()