async def bully(message: types.Message): global boi global bullysubject args = message.get_full_command() bullysubject.append(int(args[1])) boi = 0 await message.reply("bullying this boi")
async def search(msg: types.Message) -> None: """ This handler will be called when user searches timus profiles """ # TODO: add inline keyboard for beautiful search result message cmd, username = msg.get_full_command() if username == '': await msg.answer( 'Нужно запрос для поиска пользователя\n' 'Например <i>/search georgiysurkov</i>', parse_mode=types.ParseMode.HTML) return try: search_result = await search_timus_user(username) except ClientError: await msg.answer('Не удается подключиться к серварам Тимуса.') return # TODO: use pymorphy2 for right words' forms. result_text = 'Результат поиска:\n' result_text += str(len(search_result)) result_text += ' пользователей' if len( search_result) % 10 != 1 else ' пользователь' result_text += '\n\n' for i, user in enumerate(search_result): user_s = f"{i + 1}) {user.username} - решенных задач: {user.solved_problems_amount}\n/track_{user.id}\n" if len(result_text) + len(user_s) > 4096: break result_text += user_s logger.info( f'Searched for users query="{username}" in group id={msg.chat.id}, title="{msg.chat.title}"' ) await msg.answer(result_text)
async def _base_tracking_command_parser(msg: types.Message) -> int: cmd, args = msg.get_full_command() if args != '': raise CommandParseError('not empty arguments') _, timus_user_id = cmd.split('_', maxsplit=1) bot_user = await bot.get_me() if timus_user_id.endswith(f'@{bot_user.username}'): timus_user_id = timus_user_id[:-len(f'@{bot_user.username}')] if not timus_user_id.isdecimal() or len(timus_user_id) == 0 or timus_user_id[0] == '0': raise CommandParseError('id is not int') return int(timus_user_id)
async def cmd_feedback(message: types.Message) -> None: rmsg = message.reply_to_message if (message.chat.id < 0 and not message.get_command().partition("@")[2] and (not rmsg or rmsg.from_user.id != BOT_ID) or message.forward_from): return arg = message.get_full_command()[1] if not arg: await message.reply("Function: Send feedback to my owner.\n" "Usage: `/feedback@on9wordchainbot feedback`") return await message.forward(ADMIN_GROUP_ID) await message.reply("Feedback sent successfully.")
async def cmd_sql(message: types.Message) -> None: try: async with pool.acquire() as conn: res = await conn.fetch(message.get_full_command()[1]) except Exception as e: await message.reply(f"`{e.__class__.__name__}: {str(e)}`") return if not res: await message.reply("No results returned.") return text = ["*" + " - ".join(res[0].keys()) + "*"] for r in res: text.append("`" + " - ".join([str(i) for i in r.values()]) + "`") await message.reply("\n".join(text))
async def cmd_orders(message: types.Message): arg = message.get_full_command()[1] limit = 10 if len(arg) == 0 else int(arg) os = await back.get_orders(True, True, limit) maxlen = max([len(o.marketSymbol) for o in os]) resp = '' for status, os_st in itertools.groupby(os, lambda o: o.status): os_st = list(os_st) resp += f'==== {status} [{len(os_st)}] ====\n' for dir, os_dir in itertools.groupby(sorted(os_st, key=lambda o: o.direction), key=lambda o: o.direction): os_dir = list(os_dir) resp += f'== {dir} [{len(os_dir)}] ==\n' for o in os_dir: resp += format_order(o, maxlen=maxlen) + '\n' await message.answer(resp, parse_mode='markdown')
async def spotify(message: types.Message): chatid = message.chat.id search = message.get_full_command()[-1] song_info, preview = search_song(search) pprint.pprint(song_info) item = song_info[0] md_song = f"[{item['song']['name']}]({item['song']['url']})" artists = [] for artist in item['artists']: md_artist = f"[{artist['name']}]({artist['url']})" artists.append(md_artist) md_artists = ', '.join(artists) result = md_song + ' by ' + md_artists await bot.send_message( chatid, result, parse_mode='Markdown', )
async def build(message: types.Message): def clone(link, directory, br): repo = Repo.clone_from(link, roms[arglist[0]][1] + '/' + directory, branch=br) args = message.get_full_command() arglist = args[1].split() user = message.from_user.id if user in allowed: await message.reply('building {} for {}, type- {}'.format( arglist[0], arglist[1], arglist[2])) if arglist[0] in roms: if os.path.exists(roms[arglist[0]][1]): await message.reply('seems like {} is already synced!'.format( arglist[0])) romexist = 1 else: await message.reply('syncing {}'.format(arglist[0])) os.makedirs(roms[arglist[0]][1]) repoinit = subprocess.Popen([ 'repo', 'init', '-u', roms[arglist[0]][0][0], '-b', roms[arglist[0]][0][1] ], cwd=roms[arglist[0]][1]) repoinit.wait() reposync = subprocess.Popen(['repo', 'sync'], cwd=roms[arglist[0]][1]) reposync.wait() romexist = 1 else: await message.reply('rom is not available for building yet!') romexist = 0 devicecl = 0 if romexist: if arglist[1] in devices: for i in range(0, len(devices[arglist[1]])): if os.path.isdir(roms[arglist[0]][1] + '/' + devices[arglist[1]][i][1]): await message.reply('{} found! not cloning it'.format( devices[arglist[1]][i][1])) devicecl = 1 else: await message.reply('{} not found! cloning it'.format( devices[arglist[1]][i][1])) clone(*devices[arglist[1]][i]) devicecl = 1 else: await message.reply('device is not available for building yet!' ) devicecl = 0 if arglist[2] not in ('eng', 'userdebug', 'user'): await message.reply('build type incorrect! stopping build') devicecl = 0 if devicecl: if roms[arglist[0]][2] == 1: await message.reply('seems like the rom has brunch! using eet') copyfile('builder.sh', roms[arglist[0]][1] + '/builder.sh') if len(arglist) == 4 and arglist[3] == 'clean': compile = subprocess.Popen([ '/bin/bash', 'builder.sh', arglist[0] + '_' + arglist[1] + '-' + arglist[2], 'clean' ], cwd=roms[arglist[0]][1]) else: compile = subprocess.Popen([ '/bin/bash', 'builder.sh', arglist[0] + '_' + arglist[1] + '-' + arglist[2] ], cwd=roms[arglist[0]][1]) elif roms[arglist[0]][2] != 1: await message.reply('using custom command!') copyfile('builder.sh', 'builder1.sh') with open("builder1.sh", "r") as initshell: buf = initshell.readlines() with open("builder1.sh", "w") as finalshell: for line in buf: if line == "#!/bin/bash\n": line = line + "jabbcmd='{}'\n".format( roms[arglist[0]][2]) finalshell.write(line) copyfile('builder1.sh', roms[arglist[0]][1] + '/builder.sh') if len(arglist) == 4 and arglist[3] == 'clean': compile = subprocess.Popen([ '/bin/bash', 'builder.sh', arglist[0] + '_' + arglist[1] + '-' + arglist[2], 'custom', 'clean' ], cwd=roms[arglist[0]][1]) else: compile = subprocess.Popen([ '/bin/bash', 'builder.sh', arglist[0] + '_' + arglist[1] + '-' + arglist[2], 'custom' ], cwd=roms[arglist[0]][1]) if os.path.isfile('{}/log.txt'.format(roms[arglist[0]][1])): os.remove('{}/log.txt'.format(roms[arglist[0]][1])) compile.wait() try: # to do - make this statement more secure (see drawbacks\of shell=True on google) romzip = subprocess.check_output( 'ls out/target/product/' + arglist[1] + '/' + arglist[0] + '*' + '-' + arglist[1], cwd=roms[arglist[0]][1], shell=True) except subprocess.CalledProcessError: romzip = 'arbitiaryfile.lmfaoxdd' if os.path.isfile(romzip): # to do - process the gdrive output and send the link, replace os.system with subprocess os.system('gdrive upload {}/out/target/product/{}/{}'.format( roms[arglist[0]][1], arglist[1], romzip)) await message.reply('uploaded to gdrive! check your drive') else: # to do - process the gdrive output and send the link, replace os.system with subprocess os.chdir(roms[arglist[0]][1]) os.system('gdrive upload {}'.format(roms[arglist[0]][1] + '/log.txt')) await message.reply( 'got error! log uploaded to gdrive! check eet. If it says completed, then navigate to rom dir manualy and upload' ) else: await message.reply('bish you are not in the allowed list')
async def youtube(message: types.Message): search = message.get_full_command()[-1] video_url, name = get_youtube_vid(search) await message.reply(video_url)