Beispiel #1
0
def welcome_message(bot, update):
  chat_id = get_chat_id(update)
  message_id = get_message_id(update)
  chat_record = TBDB.get_chat_entry(chat_id)

  language = None
  if chat_record is not None:
    language = chat_record["lang"]
  elif update.message is not None and update.message.from_user.language_code is not None:
    # Channel posts do not have a language_code attribute
    logger.debug("Language_code: %s", update.message.from_user.language_code)
    language = update.message.from_user.language_code
  
  message = R.get_string_resource("message_welcome", language)
  message = message.replace("{languages}", "/" + "\n/".join(get_language_list())) #Format them to be a list of commands
  bot.send_message(
    chat_id=chat_id, 
    text=message, 
    reply_to_message_id = message_id, 
    parse_mode = "html",
    is_group = chat_id < 0
  )

  if chat_record is None:
    if language is None:
      language = "en-US"

    if len(language) < 5:
      language = R.iso639_2_to_639_1(language)
    
    logger.debug("No record found for chat {}, creating one with lang {}".format(chat_id, language))
    TBDB.create_default_chat_entry(chat_id, language)
Beispiel #2
0
  def __pre__hook(self, fn, u, c, **kwargs):
    b = c.bot

    m = u.message or u.channel_post
    if not m:
      return

    age = (datetime.utcnow() - m.date.replace(tzinfo=None)).total_seconds()
    if age > config.get_config_prop("app")["antiflood"]["age_threshold"]:
      return

    chat_id = get_chat_id(u)
    antiflood.on_chat_msg_received(chat_id)

    if chat_id in self.floods and self.floods[chat_id] is True:
      return

    if not TBDB.get_chat_entry(chat_id):
      # happens when welcome/joined message is not received
      TBDB.create_default_chat_entry(chat_id, 'en-US')
      
    if chat_id in self.mqbot.active_chats_cache and self.mqbot.active_chats_cache[chat_id] == 0:
      logger.debug("Marking chat {} as active".format(chat_id))
      self.mqbot.active_chats_cache[chat_id] = 1
      TBDB.set_chat_active(chat_id, self.mqbot.active_chats_cache[chat_id])

    return fn(b, u, **kwargs)
def photo(bot, update):
    chat_id = get_chat_id(update)
    chat = TBDB.get_chat_entry(chat_id)
    if chat["qr_enabled"] == 0 and chat["photos_enabled"] == 0:
        return

    message = update.message or update.channel_post

    if message.photo:
        TranscriberBot.get().photos_thread_pool.submit(process_media_photo,
                                                       bot, update,
                                                       message.photo, chat)