Example #1
0
def on_command_start(message):
    bot.send_chat_action(message.chat.id, 'typing')
    bot.send_message(message.chat.id,
                     logic.get_welcome_message(bot.get_me()),
                     parse_mode="Markdown")
    bot.send_message(message.chat.id,
                     logic.get_help_message(),
                     parse_mode="Markdown")
    logic.register_account(message.from_user.id)
Example #2
0
def on_command_start(message):
    bot.send_chat_action(message.chat.id, 'typing')
    bot.send_message(message.chat.id,
                     util.get_welcome_message(bot.get_me()),
                     parse_mode="Markdown")

    bot.send_message(message.chat.id,
                     util.get_help_message(),
                     parse_mode="Markdown")
Example #3
0
def start(message):
    """
  Sends a greeting message from config file
  and provides some basic bot configuration settings
  """

    chatID = message.chat.id

    language = Language(chatID).lang
    languageMarkup = getLanguageMarkup(language)

    bot.send_sticker(chatID, greetingStickerId)

    greetingString = message.replies.hi.format(message.from_user.first_name,
                                               bot.get_me().username,
                                               commands.h)

    bot.send_message(chatID,
                     greetingString,
                     reply_markup=languageMarkup,
                     parse_mode='html')
Example #4
0
def settingsMarkup(chatID):
  markup = InlineKeyboardMarkup()
  currentSettings = Chats.objects(ID=chatID).get().settings
  settingsStrings = Language(chatID).strs.stg.strings

  for index, setting in enumerate(currentSettings):

    # * Will stop the foop if we have already iterated through all settings.
    # * Has to be stopped because "settings" object contains not only settings values,
    # * but some additional info connected to /settings command

    if index >= len(settingsStrings):
      break

    isOnString = '❌'
    settingObject = currentSettings[setting]

    if isinstance(settingObject, bool) and settingObject:
      isOnString = '✅'
    elif isinstance(settingObject, dict) and settingObject['haveTo']:
      isOnString = '✅'

    # * Creaing and adding all buttons to the markup. Will create using 2D array in config
    newButtons = []
    for index, buttonInfo in enumerate(settingsStrings[index]):
      buttonText = buttonInfo[0]

      # * Formating button text if can be formated
      if canFormat(buttonText):
        buttonText = buttonText.format(settingObject['value'])

      tempButton = InlineKeyboardButton(
        f'{buttonText}',
        callback_data=buttonInfo[1],
      )

      if not index:
        tempButton = InlineKeyboardButton(
          f'{buttonText} {isOnString}',
          callback_data=buttonInfo[1]
        )

      newButtons.append(tempButton)
    markup.row(*newButtons)

  # ? Additional buttons
  buttonText = Language(chatID).strs.stg

  # * Editing button
  markup.row(InlineKeyboardButton(
    buttonText.editButtonValue,
    callback_data=additionalButtonCallbacks[0],
  ))

  # * Button to get more info
  markup.row(InlineKeyboardButton(
    buttonText.moreInfoButtonValue,
    callback_data=additionalButtonCallbacks[1]
  ))

  # * Button to move to Bot's chat
  addUrlButton(markup, Language(chatID).strs.goToBot[0], bot.get_me().username)

    # tempButton = InlineKeyboardButton(
    #   f'{settingsStrings[index][0]} {isOnString}',
    #   callback_data=settingsStrings[index][1]
    # )

    # markup.add(tempButton)

  return markup
Example #5
0
def sendStats(message):
  """
  Sends a message with all words information in a special formated string,
  which is provide by 'stringsForStats' functionm. Gets informations from the
  database and splits the result of the funcion unsing built-in 'untils' methods.
  """

  chatID = message.chat.id
  clearButton = types.InlineKeyboardButton(
    message.replies.skeyboard[0],
    callback_data=dumps(['toClearTrue', chatID])
  )

  # * Getting info from the DB to pass into the function
  currentChat = Chats.getChat(chatID)
  wordObjects = currentChat.words
  wordNumbers = [word.sentTimes for word in wordObjects]
  words = [word.text for word in wordObjects]

  sendToPrivate = Chats.getSettings(chatID)['sendPrivate']

  chatName = None
  if sendToPrivate:
    chatName = message.chat.username

  formatedStrings = stringForStats(chatID, words, wordNumbers, True, chatName)
  markup = None

  # * Allowes to save message ids. More info in the class doc string
  editor = ResponsesManager(currentChat)

  if not formatedStrings:
    tempMessage = bot.send_message(message.chat.id, message.replies.nos)
    editor.addIDs(message.message_id, tempMessage)
    return

  # * If specified in settings will set chatID variable to users chat id,
  # * so the statistics will be sent not to the chat but to user pesonaly.
  if sendToPrivate:
    chatID = message.from_user.id

  if formatedStrings:
    # * Sending a splited message and adding an inline keyboard to the last element,
    # * so the user will be able to everything faster and more comftable.

    try:
      for index, part in enumerate(formatedStrings):
        if index + 1 == len(formatedStrings):
          markup = getDeleteMarkup(commands.s, message, clearButton)
          if message.chat.username and Chats.getSettings(message.chat.id)['sendPrivate']:
            addUrlButton(markup, message.replies.goToChat[0], message.chat.username)


        tempMessage = bot.send_message(
          chatID, part,
          reply_markup=markup, disable_notification=True, parse_mode='html'
        )

        editor.addIDs(message.message_id, tempMessage, chatID)

      if Chats.getSettings(message.chat.id)['sendPrivate'] and message.chat.type != 'private':
        markup = types.InlineKeyboardMarkup()
        addUrlButton(markup, message.replies.goToBot[1], bot.get_me().username)

        editor.addIDs(
          message.message_id,
          bot.send_message(
            message.chat.id,
            message.replies.s[2].format(
              bot.get_me().username
            ),
            reply_markup=markup
          ))

    except apihelper.ApiException as e:
      print(e)
      editor.addIDs(
        message.message_id,
        bot.send_message(
          message.chat.id,
          message.replies.s[3].format(
            bot.get_me().username
      )))