Exemple #1
0
def role_list(update, context):
    user = update.message.from_user
    chat = update.message.chat

    msg = "لیست نقش های ثبت شده \n\n"  # saved role list

    saved_roles = roles[chat.id]
    allowed_players = allow_users[chat.id]

    # get leader
    leader_id = leader[chat.id]
    if leader_id in allowed_players:
        user_obj = bot.get_chat_member(chat_id=chat.id, user_id=int(leader_id))
        msg += "شکارچی : {}\n".format(mention(leader_id, user_obj.user.first_name))

    # list alive roles
    for player in saved_roles:
        # check player is not alive
        if player not in allowed_players:
            continue
        # check player is leader
        if player == leader_id:
            continue

        player_obj = bot.get_chat_member(chat_id=chat.id, user_id=int(player))
        name = player_obj.user.full_name
        msg += f'{mention(player, name)} : {saved_roles[player]}\n'

    # if anyone have not save role
    if not saved_roles:
        msg = "هیشکی نقششو ثبت نکرده 😐 \n با /saveYourRole ازشون بخواه ک نقششونو ثبت بکنن"  # ask role
    context.bot.send_message(chat.id, msg,
                             parse_mode='HTML')
Exemple #2
0
def buttons(update, context):
    query = update.callback_query
    chat_id = query.message.chat.id
    user = query.from_user
    data = query.data.replace('stats ', '', 1).split(' ')
    if data[0] == 'stats':
        player = data[1]
        text = get_player_stats_text(player)
        if not text:
            text = 'کاربر سابقه ای ندارد'
        query.answer(text=text, show_alert=True)
        return
    elif data[0] == 'kills':
        player = data[1]
        text = get_player_kills_text(player)
        query.answer(text=text, show_alert=True)
        return

    elif data[0] == 'killedBy':
        player = data[1]
        text = get_player_killed_by_text(player)
        query.answer(text=text, show_alert=True)
        return
    elif data[0] == 'death':
        player = data[1]
        text = get_player_death_text(player)
        query.answer(text=text, show_alert=True)
        return
    elif data[0] == 'ban':
        player = data[1]
        if bot.get_chat_member(chat_id,
                               user.id).status in ['creator', 'administrator']:
            t = bot.get_chat_member(chat_id=chat_id, user_id=int(player))
            name = t.user.full_name
            bot.kick_chat_member(chat_id, player)
            query.edit_message_text('{} Banned {}'.format(
                mention(user.id, user.first_name), mention(int(player), name)),
                                    parse_mode='Markdown')
        return
Exemple #3
0
def save_your_role(update, context):
    user = update.message.from_user
    chat = update.message.chat

    # check ask role is allow
    group_rules = rules[chat.id]
    if group_rules:
        if not group_rules['save_your_role']:
            update.message.reply_text('امکان استفاده از این دستور غیر فعال است'
                                      )  # this option is disabled
            return

    # if ask role is used before in this game day
    if ask_roles[chat.id] >= 1:
        update.message.reply_text(
            "شما تنها یک بار در هر روز میتوانید درخواست نقش کنید")

    # set ask role used one time in this group
    ask_roles[chat.id] += 1

    allowed_users = allow_users[chat.id]
    saved_roles = roles[chat.id]

    # if no one alive
    if not group_rules['save_your_role']:
        update.message.reply_text('امکان استفاده از این دستور غیر فعال است'
                                  )  # this option is disabled
        return

    # list of users who have not saved role
    not_saved_role_users = [
        user for user in allowed_users if user not in saved_roles
    ]

    # ask role if there are anyone have not saved role
    for user in not_saved_role_users:
        user_obj = bot.get_chat_member(chat_id=chat.id, user_id=int(user))
        name = user_obj.user.full_name
        context.bot.send_message(
            chat.id,
            text="""{} نقشت چیه ؟""".format(mention(
                user, name)),  # what is your role ?
            parse_mode='HTML')
        time.sleep(1)
    msg = f'ببین نقش این {len(not_saved_role_users)}‏ نفر چیه'  # look what is their role

    # check if all users have saved a role
    if not not_saved_role_users:
        msg = 'بچه های خوبی دارید همشون نقشاشونو ثبت کردن 😅'  # every body saved a role

    update.message.reply_text(msg)
Exemple #4
0
def make_user_role_list_v0(chat_id):
    players = get_role_list(chat_id)
    allow_players = get_allow_players(chat_id)
    shekar = get_shekarchi_db(chat_id)
    texts = return_lang(chat_id).List
    shekar_saved = False
    msg = get_from_db('role_list_header')[0]
    role_list_footer = get_from_db('role_list_footer')[0]
    role_list_user = get_from_db('role_list_user')[0]
    if shekar in allow_players:
        u = bot.get_chat_member(chat_id, int(shekar))
        name = u.user.full_name
        ranks = give_rank(u.user)
        shekar_saved = True
        msg += role_list_user.format(name=f'<b>{mention(u.user.id, name)}</b>',
                                     ranks='|'.join(ranks),
                                     role=choice(texts.ch)) + '\n\n'

    saved_role_users = []
    not_saved_role_users = []

    for player in players:
        if player not in allow_players or player == shekar:
            continue
        t = bot.get_chat_member(chat_id=chat_id, user_id=int(player))
        name = t.user.full_name
        role = html.escape(players[player])
        ranks = give_rank(t.user)
        saved_role_users.append(
            role_list_user.format(name=name,
                                  ranks='|'.join(ranks),
                                  role=': ' + role))

    for player in allow_players:
        if player == shekar or player in players:
            continue
        t = bot.get_chat_member(chat_id=chat_id, user_id=int(player))
        name = t.user.full_name
        ranks = give_rank(t.user)
        not_saved_role_users.append(
            role_list_user.format(name=mention(player, name),
                                  ranks='|'.join(ranks),
                                  role=''))

    msg += '\n'.join(saved_role_users) + role_list_footer
    if not saved_role_users and not shekar_saved:
        msg = texts.list_empty
    return msg
Exemple #5
0
def update_list(update, context):
    user = update.message.from_user
    chat = update.message.chat

    # check message is replied to game bot
    if not update.message.reply_to_message or update.message.reply_to_message.from_user.id not in bot_list:
        update.message.reply_text('به لیست بازی ربات ریپلای بزنید')  # reply to game list
        return
    # check game list is not used before
    if update.message.reply_to_message.message_id in used_messages[chat.id]:
        update.message.reply_text('این لیست قبلا ثبت شده است')  # list used before
        return

    message_text = update.message.reply_to_message.text  # game message
    entities = update.message.reply_to_message['entities']  # entities list

    global allow_users, in_game_users, ask_roles, roles

    # check if this message is the last list of the game
    if re.search(game_finish, message_text):
        context.bot.send_message(chat.id, 'بازی خوبی بود')  # gg
        roles.update({chat.id: {}})  # clean roles list
        allow_users.update({chat.id: {}})  # clean player list
        return

    # check if this is game middle list
    elif re.search(death, message_text):
        # list alive players (died players are not mentioned in list)
        alive_users = [ent['user'].id for ent in entities if ent['type'] == 'text_mention']

        # update allowed users to save role
        allow_users[chat.id] = alive_users
        # reset ask role status
        ask_roles[chat.id] = 0
        # add message id into used messages
        used_messages[chat.id].add(update.message.message_id)

        context.bot.send_message(chat.id, 'لیست اپدیت شد')  # role list updated

        saved_roles = roles[chat.id]  # roles list
        allow_players = allow_users[chat.id]  # alive players

        msg = "لیست نقش های ثبت شده \n\n"  # list of saved roles

        # get leader
        leader_id = leader[chat.id]
        if leader_id in allow_players:
            leader_user_obj = bot.get_chat_member(chat_id=chat.id, user_id=int(leader_id))
            msg += "شکارچی : {}\n".format(mention(leader_id, leader_user_obj.user.first_name))

        #  if any role saved
        if not saved_roles:

            # check if leader exists
            if leader_id:
                context.bot.send_message(chat.id, msg, parse_mode='HTML')
                return

            msg = "هیشکی نقششو ثبت نکرده 😐 \n"  # anyone saved role

            # check group rules for response
            group_rules = rules[chat.id]
            if group_rules:
                if group_rules['save_your_role']:
                    msg += 'با /saveYourRole ازشون ک نقششونو بپرسید'  # ask with ask role
                elif group_rules['save_role']:
                    msg += 'با /sn نقش خودتونو ثبت کنید'  # save with /sn
                else:
                    msg = ""
            # if no setting modified
            else:
                msg += 'با /saveYourRole ازشون ک نقششونو بپرسید'

        # list alive roles
        for player in saved_roles:
            # check player is not alive
            if player not in allow_players:
                continue
            # check player is leader
            if player == leader_id:
                continue

            player_obj = bot.get_chat_member(chat_id=chat.id, user_id=int(player))
            name = player_obj.user.full_name
            msg += f'{name} : {saved_roles[player]}\n'

        context.bot.send_message(chat.id, msg, parse_mode='HTML')
        return

    elif re.search(game_list, message_text):
        # list alive players (died players are not mentioned in list)
        alive_users = [ent['user'].id for ent in entities if ent['type'] == 'text_mention']

        # update allowed users to save role and in game users
        allow_users[chat.id] = alive_users
        in_game_users[chat.id] = alive_users
        # reset ask role status
        ask_roles[chat.id] = 0
        # add message id into used messages
        used_messages[chat.id].add(update.message.reply_to_message.message_id)

        # check group rules for response
        group_rules = rules[chat.id]
        msg = f'با {len(alive_users)} بازیکن بازی شروع شد\n'
        if group_rules:
            if group_rules['save_your_role']:
                msg += ' برای اینکه نقش اون هارو بخاهید از دستور /saveYourRole استفاده کنید'  # ask with ask role
            elif group_rules['saverole']:
                msg += 'با /sn نقش خودتونو ثبت کنید'  # save with /sn
            else:
                pass
        else:
            msg += ' برای اینکه نقش اون هارو بخاهید از دستور /saveYourRole استفاده کنید'

        context.bot.send_message(chat.id, msg)
        return
    else:
        context.bot.send_message(chat.id, 'seems its not a game list message')
def inline_handler(update, context):
    texts = update.user_lang
    user = update.effective_user
    info = get_player_info_no_chat(user.id)
    if info:
        my_stats_text = texts.Mystate.template_inline.format(
            name=mention(user.id, user.first_name),
            type=UserStatus(user).status,
            set=info['role_count'],
            gp_set_count=info['group_count'],
            ranks='|'.join(get_cached_user(user).get_all_emoji_ranks()),
            gp='Inline')
    else:
        my_stats_text = texts.Mystate.no_use
    player = user.id
    votes, voted = get_most_votes(player)

    my_votes_text = ''
    if votes:
        my_votes_text += texts.Mostvotes.voted
        for _, voted_player, count in votes:
            try:
                my_votes_text += '‎ {} <i>{}</i>\n'.format(
                    mention(voted_player,
                            context.bot.get_chat(voted_player).first_name),
                    count)
            except:
                my_votes_text += '‎ {} <i>{}</i>\n'.format(
                    get_username_from_id(voted_player), count)
        my_votes_text += '\n'
    else:
        my_votes_text += texts.Mostvotes.no_vote
    if voted:
        my_votes_text += texts.Mostvotes.votes
        for voter_player, _, count in voted:
            try:
                my_votes_text += '‎ {} <i>{}</i>\n'.format(
                    mention(voter_player,
                            context.bot.get_chat(voter_player).first_name),
                    count)
            except:
                my_votes_text += ' {} <i>{}</i>\n'.format(
                    get_username_from_id(voter_player), count)
        my_votes_text += '\n'
    else:
        my_votes_text += texts.Mostvotes.no_votes
    my_votes_text = my_votes_text.format(mention=mention(
        player, user.full_name),
                                         days=7,
                                         where='')
    days = 7
    afks = get_user_afks(user.id, days)
    afks_text = texts.Myafk.header.format(mention_markdown(user.id, 'شما'),
                                          days)
    afk_count = 0
    for gap, afk in afks.items():
        afks_text += f'\n‎{gap} - {afk}'
        afk_count += afk
    if afk_count > 5:
        afks_text += '\n\nDon\'t ruin the games...'
    else:
        afks_text = texts.Myafk.no_afk.format(days)

    res = [
        InlineQueryResultArticle(id='mystate',
                                 title='آمار من',
                                 description='به نظر میرسه ازم استفاده نکردی!'
                                 if not info else None,
                                 input_message_content=InputTextMessageContent(
                                     my_stats_text,
                                     parse_mode='html',
                                     disable_web_page_preview=True)),
        InlineQueryResultArticle(id='myvotes',
                                 title='رای های من',
                                 description='هیچ رای ای یافت نشد!'
                                 if not votes and not voted else None,
                                 input_message_content=InputTextMessageContent(
                                     my_votes_text,
                                     parse_mode='html',
                                     disable_web_page_preview=True)),
        InlineQueryResultArticle(id='myafks',
                                 title='افک های من',
                                 description=afks_text[:40] +
                                 ('...' if afks else ''),
                                 input_message_content=InputTextMessageContent(
                                     afks_text,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True))
    ]
    update.inline_query.answer(res, is_personal=True, cache_time=100)
Exemple #7
0
def make_user_role_list_v1(chat_id):
    from .v3_4 import roles_v2
    all_saved = []
    all_death = []
    all_unsaved = []
    delimiter = '\n\n〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️\n'
    texts = return_lang(chat_id).List
    saved_roles = get_role_list(chat_id)
    all_players = get_all_players(chat_id)
    alive_players = get_allow_players(chat_id)
    shekar = get_shekarchi_db(chat_id)
    role_list_user_rank_less = get_from_db('role_list_user_rank_less')[0]
    role_list_footer = get_from_db('role_list_footer')[0]
    role_list_user = get_from_db('role_list_user')[0]
    for user in all_players:
        if user not in list(saved_roles.keys()) and user in alive_players:
            if user == shekar:
                continue
            u = bot.get_chat_member(chat_id, user)
            name = u.user.full_name
            ranks = give_rank(u.user)
            all_unsaved.append(
                role_list_user.format(name=mention(u.user.id, name),
                                      ranks='|'.join(ranks),
                                      role=''))

    if shekar in alive_players:
        u = bot.get_chat_member(chat_id, shekar)
        name = u.user.full_name
        ranks = give_rank(u.user)
        all_saved.append(
            role_list_user.format(name=f'<b>{mention(u.user.id, name)}</b>',
                                  ranks='|'.join(ranks),
                                  role=choice(texts.ch)))

    for key, value in saved_roles.items():
        if key == shekar or key not in alive_players:
            continue
        user = bot.get_chat_member(chat_id, key)
        name = user.user.full_name
        ranks = give_rank(user.user)
        all_saved.append(
            role_list_user.format(name=f'<b>{html.escape(name)}</b>',
                                  ranks='|'.join(ranks),
                                  role=': ' + value))
        f'<b>{html.escape(name)}</b> : {html.escape(value)}'

    for key, value in roles_v2[chat_id].items():
        if value['role']:
            all_death.append(
                role_list_user_rank_less.format(
                    name=f'<s>{html.escape(key)}</s>',
                    role=': ' + value['role']))
    args = []
    args.append((texts.dead_list if isinstance(texts.dead_list, str) else
                 choice(texts.dead_list)) +
                '\n'.join(all_death)) if all_death else None
    args.append((texts.no_role if isinstance(texts.no_role, str
                                             ) else choice(texts.no_role)) +
                '\n'.join(all_unsaved)) if all_unsaved else None
    args.append((texts.role_list if isinstance(texts.role_list, str) else
                 choice(texts.role_list)) +
                '\n'.join(all_saved)) if all_saved else None
    msg = delimiter.join(args) + role_list_footer
    return msg