Exemple #1
0
def top(bot: Bot, update: Update, args: list):
    chat_id = update.message.chat_id
    reply_keyboard = [[]]
    if chat_id in locks:
        return
    if chat_id not in core.results_total:
        core.results_total[chat_id] = {}
    if len(args) == 1 and args[0] == "me":
        user = update.message.from_user
        username = core.get_name(user)
        stat = core.results_total[chat_id].get(user.id, 0)
        text = f"Ваша статистика:\n*{username}*: {stat} раз(а)"
    elif update.message.reply_to_message:
        user = update.message.reply_to_message.from_user
        username = core.get_name(user)
        stat = core.results_total[chat_id].get(user.id, 0)
        text = f"Статистика пользователя *{username}*: {stat} раз(а)"
    else:
        text, pages = core.make_top(chat_id, page=1)
        if pages > 1:
            reply_keyboard = [[
                InlineKeyboardButton(">>", callback_data="top:page_2")
            ]]
    update.message.reply_text(
        text=text,
        parse_mode=ParseMode.MARKDOWN,
        reply_markup=InlineKeyboardMarkup(reply_keyboard))
Exemple #2
0
def update_cache(bot: Bot, update: Update):
    msg = core.get_message(update)
    user = msg.from_user
    # Also skip first update when the bot is added
    if not core.is_private(msg.chat_id) and core.chat_users.get(
            msg.chat_id) is not None:
        core.chat_users[msg.chat_id].update({user.id: core.get_name(user)})
Exemple #3
0
def svc_handler(bot: Bot, update: Update):
    chat_id = update.message.chat_id
    migrate_to_id = update.message.migrate_to_chat_id
    new_member = update.message.new_chat_member
    left_member = update.message.left_chat_member
    if update.message.group_chat_created or (bool(new_member) and new_member.id == bot.id):
        chat_users[chat_id] = {}
        core.admins_refresh(can_change_name, bot, chat_id)
    elif bool(new_member):
        if bool(new_member.username) and new_member.username[-3:] == "bot":
            return
        chat_users[chat_id].update({new_member.id: core.get_name(new_member)})
    elif migrate_to_id != 0: # function mb?
        chat_users.update({migrate_to_id: chat_users.get(chat_id)})
        spin_name.update({migrate_to_id: spin_name.get(chat_id)})
        can_change_name.update({migrate_to_id: can_change_name.get(chat_id)})
        results.update({migrate_to_id: results.get(chat_id)})
        core.clear_data(chat_id, chat_users, spin_name, can_change_name, results)
    elif bool(left_member) and left_member.id == bot.id:
        core.clear_data(chat_id, chat_users, spin_name, can_change_name, results)
    elif bool(left_member):
        chat_users[chat_id].pop(left_member.id)
Exemple #4
0
def svc_handler(bot: Bot, update: Update):
    chat_id = update.message.chat_id
    migrate_to_id = update.message.migrate_to_chat_id
    new_member = update.message.new_chat_member
    left_member = update.message.left_chat_member
    if update.message.group_chat_created or (bool(new_member)
                                             and new_member.id == bot.id):
        # TODO: add admins to the list
        log.debug(f"New chat! ({chat_id})")
        core.chat_users[chat_id] = {}
        core.can_change_name[chat_id] = []
    elif bool(new_member):
        if bool(new_member.username) and new_member.username[-3:].lower(
        ) == "bot":
            return
        core.chat_users[chat_id].update(
            {new_member.id: core.get_name(new_member)})
    elif migrate_to_id != 0:
        core.migrate(chat_id, migrate_to_id)
    elif bool(left_member) and left_member.id == bot.id:
        core.clear_data(chat_id)
    elif bool(left_member):
        core.chat_users[chat_id].pop(left_member.id)
Exemple #5
0
def update_cache(bot: Bot, update: Update):
    msg = core.get_message(update)
    user = msg.from_user
    if not core.is_private(msg.chat_id):
        chat_users[msg.chat_id].update({user.id: core.get_name(user)})