def start(self): audio_messages = get_attachments_from_attachments_or_fwd( self.vk_event, 'audio_message') if not audio_messages: return "Не нашёл голосового сообщения" self.vk_bot.set_activity(self.vk_event.peer_id, 'audiomessage') audio_message = audio_messages[0] response = requests.get(audio_message['download_url'], stream=True) i = io.BytesIO(response.content) i.seek(0) o = io.BytesIO() o.name = "recognition.wav" AudioSegment.from_file(i, 'mp3').export(o, format='wav') o.seek(0) r = sr.Recognizer() with sr.AudioFile(o) as source: audio = r.record(source) try: msg = r.recognize_google(audio, language='ru_RU') return msg except sr.UnknownValueError: return "Ничего не понял((" except sr.RequestError as e: print(str(e)) return "Проблема с форматом"
def start(self): if self.vk_event.args and self.vk_event.args[0].lower() in ['аватар']: self.check_sender(Role.ADMIN) cat = CatModel.objects.filter(to_send=True).order_by('?').first() cat.to_send = False cat.save() attachments = self.vk_bot.upload_photos(cat.image.path) return { 'msg': "Держи нового кота на аватарку", 'attachments': attachments } images = get_attachments_from_attachments_or_fwd( self.vk_event, 'photo') if len(images) == 0: cat = CatModel.objects.filter().order_by('?').first() attachments = self.vk_bot.upload_photos(cat.image.path) return { 'attachments': attachments, "keyboard": get_inline_keyboard(self.names[0]) } else: self.check_sender(Role.TRUSTED) new_urls = [] for image in images: new_url = self.add_cat(image) new_urls.append(new_url) return "\n".join(new_urls)
def start(self): attachments = get_attachments_from_attachments_or_fwd( self.vk_event, 'photo') if len(attachments) == 0: return "Не нашёл в сообщении фотографий" attachments_vk_url = [ attachment['download_url'] for attachment in attachments ] attachments = self.vk_bot.upload_photos(attachments_vk_url) return {'attachments': attachments}
def start(self): images = get_attachments_from_attachments_or_fwd(self.vk_event, 'photo') if not images: return "Не нашёл картинки" image = images[0] everypixel_api = EveryPixelAPI(image['download_url']) image_quality = everypixel_api.get_image_quality() return f"Качество картинки - {image_quality}"
def start(self): attachments = get_attachments_from_attachments_or_fwd( self.vk_event, from_first_fwd=False) attachments = [att['vk_url'] for att in attachments] if len(attachments) == 0: return "Не нашёл вложений" attachments_parts = parting(attachments, 10) msgs = [{ 'attachments': attachments_part } for attachments_part in attachments_parts] return msgs
def start(self): lang = "rus" if self.vk_event.args: lang = self.vk_event.args[0] google_ocr = OCRApi() images = get_attachments_from_attachments_or_fwd( self.vk_event, 'photo') if not images: return "Не нашёл картинки" image = images[0] return google_ocr.recognize(image['download_url'], lang)
def start(self): images = get_attachments_from_attachments_or_fwd( self.vk_event, 'photo') if not images: return "Не нашёл картинки" image = images[0] everypixel_api = EveryPixelAPI(image['download_url']) faces = everypixel_api.get_faces_on_photo() if len(faces) == 0: return "Не нашёл лиц на фото" file_path = draw_on_images(image['download_url'], faces) attachments = self.vk_bot.upload_photos(file_path) return {"attachments": attachments}
def start(self): audios_att = get_attachments_from_attachments_or_fwd( self.vk_event, ['audio', 'wall']) if audios_att: self.save_attachments(audios_att) return "Добавил" else: count = 5 if self.vk_event.args: count = self.vk_event.args[0] self.check_number_arg_range(count, 1, 10) # Fix issue with delete where limit audios = AudioList.objects.filter(pk__in=AudioList.objects.filter( author=self.vk_event.sender).order_by('?')[:count]) if len(audios) == 0: return "Не нашёл ваших аудио" attachments = [audio.attachment for audio in audios] if len(audios) != count: msg = f"Нашёл только {len(audios)} {decl_of_num(len(audios), ['штуку', 'штуки', 'штук'])}" else: msg = "Лови" audios.delete() return {"msg": msg, "attachments": attachments}