def _bot_start_new_chat(self, upd): _log.info('Access requested by %s', user_desc(upd)) password = self._auth_storage[upd.effective_chat.id].start_auth( user_desc(upd)) self._save_chat_auth_storage() print('\n\nChat ID: %d, User: %s, Password: %s\n\n' % (upd.effective_chat.id, user_desc(upd), password)) self.send_message( upd.effective_chat.id, 'Reply with the pass that you can read on the console.')
def cmd_detect(self, upd, args): if len(args) not in (0, 1): return # More than one argument is not something we handle if self.pwm_led_plugin is None: self.root_telegram_plugin.reply_message( upd, 'Cannot offer LED light, the %s is not loaded.' % PWMLedPlugin.plugin_name()) return elif self.pwm_led_plugin.bcm_pin is None: self.root_telegram_plugin.reply_message( upd, 'Cannot offer LED light, pin number not set.') return if len(args) == 0: light_value = self.pwm_led_plugin.value self.root_telegram_plugin.reply_message( upd, 'Light is %s (set at %d%%).' % (bool_desc(light_value > 0), int(100. * light_value))) elif args[0].strip().lower() in ['pulse', 'test']: self.root_telegram_plugin.reply_message( upd, 'Will pulse the light for testing purposes.') _log.info('[%s] requested to pulse the light.', user_desc(upd)) self.pwm_led_plugin.pulse() else: # Try a float first light_value = None try: light_value = float(args[0]) except ValueError: try: # Try a bool then if fuzzy_bool(args[0]): light_value = 1. else: light_value = 0. except ValueError: self.root_telegram_plugin.reply_message( upd, 'Please specify \'on\' or \'off\' or a valid number.') return if light_value == self.pwm_led_plugin.value: self.root_telegram_plugin.reply_message( upd, 'Light is already set to %d%%.' % int(100. * light_value)) else: self.pwm_led_plugin.value = light_value _log.info('[%s] set the light to %d%%.', user_desc(upd), int(100. * light_value)) self.root_telegram_plugin.reply_message( upd, 'Setting light to %d%%.' % int(100. * light_value))
def cmd_photo(self, upd): if self.still_plugin is None: self.root_telegram_plugin.reply_message( upd, 'Cannot take a picture, %s is not loaded.' % StillPlugin.plugin_name()) else: _log.info('[%s] requested a photo.', user_desc(upd)) self.still_plugin.take_picture(info=upd)
def _bot_try_auth(self, upd): password = upd.message.text result = self._auth_storage[upd.effective_chat.id].try_auth(password) self._save_chat_auth_storage() if result == AuthAttemptResult.AUTHENTICATED: self.reply_message(upd, 'Authenticated.') elif result == AuthAttemptResult.WRONG_TOKEN: self.reply_message(upd, 'Incorrect password.') elif result == AuthAttemptResult.EXPIRED: self.reply_message(upd, 'Your password expired.') elif result == AuthAttemptResult.TOO_MANY_RETRIES: self.reply_message(upd, 'Number of attempts exceeded.') _log.info('Authentication attempt for chat %d, user %s, outcome: %s', upd.effective_chat.id, user_desc(upd), result)
def cmd_detect(self, upd, args): if len(args) not in (0, 1): return # More than one argument is not something we handle if self.motion_detector_plugin is None: self.root_telegram_plugin.reply_message( upd, 'Cannot offer motion detection, the %s is not loaded.' % MotionDetectorCameraPlugin.plugin_name()) return if len(args) == 0: self.root_telegram_plugin.reply_message( upd, 'Motion detection is %s.' % bool_desc(self.motion_detection_enabled)) else: try: enable = fuzzy_bool(args[0]) if enable: if self.motion_detection_enabled: self.root_telegram_plugin.reply_message( upd, 'Motion detection is already on.') else: self.motion_detection_enabled = True _log.info('[%s] turned detection on.', user_desc(upd)) self.root_telegram_plugin.reply_message( upd, 'Motion detection was turned on.') else: if self.motion_detection_enabled: self.motion_detection_enabled = False self.root_telegram_plugin.reply_message( upd, 'Motion detection was turned off.') _log.info('[%s] turned detection off.', user_desc(upd)) else: self.root_telegram_plugin.reply_message( upd, 'Motion detection is already off.') except ValueError: self.root_telegram_plugin.reply_message( upd, 'Please specify \'on\' or \'off\' or nothing.')
def cmd_video(self, upd): if self.buffered_recorder_plugin is None: self.root_telegram_plugin.reply_message( upd, 'Cannot take a video, %s is not loaded.' % BufferedRecorderPlugin.plugin_name()) else: _log.info('[%s] requested a video.', user_desc(upd)) self.set_manual_recording() self.buffered_recorder_plugin.record( info=upd, stop_after_seconds=SETTINGS.ratcam.get('video_duration', cast_to_type=float, ge=1., le=60., default=8.))
def _bot_start_resume_auth(self, upd): _log.info('Authentication resumed for chat %d, user %s.', upd.effective_chat.id, user_desc(upd)) self.send_message( upd.effective_chat.id, 'Reply with the pass that you can read on the console.')