Ejemplo n.º 1
0
def join(update: telegram.Update, context: telegram.ext.CallbackContext):
    user = update.message.from_user
    group_data = context.chat_data
    user_data = context.user_data
    user = update.message.from_user
    language = get_lang(update, context)
    if "active_game" in group_data.keys():
        if has_subscribed(update, context):
            group_game = group_data["active_game"]
            if "active_game" not in user_data.keys():
                group_game.join_game(user, user_data)
            else:
                if user_data["active_game"] == group_game:
                    with codecs.open(os.path.join("Lang", language, "AlreadyJoined"), 'r', encoding='utf8') as file:
                        update.message.reply_markdown(file.read())
                        context.bot.send_message(
                            chat_id=user['id'], text=file.read())
                else:
                    with codecs.open(os.path.join("Lang", language, "AlreadyJoinedAnotherGroup"), 'r',
                                     encoding='utf8') as file:
                        update.message.reply_markdown(file.read())
                        context.bot.send_message(
                            chat_id=user['id'], text=file.read())

        else:
            with codecs.open(os.path.join("Lang", language, "StartPV"), 'r', encoding='utf8') as file:
                update.message.reply_text(file.read())
    else:
        with codecs.open(os.path.join("Lang", language, "NoGame"), 'r', encoding='utf8') as file:
            update.message.reply_text(file.read())
Ejemplo n.º 2
0
 def wrapper_func(update, context):
     if update.effective_chat.id != update.message.from_user["id"]:
         language = get_lang(update, context)
         with codecs.open(os.path.join("Lang", language, "JustForPV"), 'r', encoding='utf8') as file:
             update.message.reply_text(file.read())
     else:
         func(update, context)
Ejemplo n.º 3
0
def new_game(update: telegram.Update, context: telegram.ext.CallbackContext):
    group_id = update.effective_chat.id
    group_data = context.chat_data
    user = update.message.from_user
    user_data = context.user_data
    language = get_lang(update, context)
    if "active_game" not in group_data.keys():
        if has_subscribed(update, context):
            if "active_game" not in user_data.keys():
                game = Game(group_id, group_data, context, update)
                group_data["active_game"] = game
                game.start()
                context.bot.send_sticker(chat_id=game.group_chat_id,
                                         sticker="CAACAgQAAxkBAAEBEGZfEajfE4ubecspTvk_h_MmLWldhwACFwAD1ul3K_CgFM5dUHoRGgQ")

                with codecs.open(os.path.join("Lang", language, "NewGame"), 'r', encoding='utf8') as file:
                    update.message.reply_text(file.read())
                game.join_game(user, user_data)
            else:
                with codecs.open(os.path.join("Lang", language, "AlreadyJoinedAnotherGroup"), 'r',
                                 encoding='utf8') as file:
                    update.message.reply_markdown(file.read())
                    context.bot.send_message(
                        chat_id=user['id'], text=file.read())

        else:
            with codecs.open(os.path.join("Lang", language, "StartPV"), 'r', encoding='utf8') as file:
                update.message.reply_text(file.read())
    else:
        with codecs.open(os.path.join("Lang", language, "UnfinishedGame"), 'r', encoding='utf8') as file:
            update.message.reply_text(file.read())
Ejemplo n.º 4
0
def has_subscribed(update, context):
    user_id = update.message.from_user['id']
    chat_title = update.effective_chat['title']
    language = get_lang(update, context)
    url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
    with codecs.open(os.path.join("Lang", language, "Analyzing"), 'r', encoding='utf8') as file:
        params = {'chat_id': user_id, 'text': f"{file.read()} {chat_title}"}
    r = requests.get(url=url, params=params)
    return r.json()['ok']
Ejemplo n.º 5
0
 def wrapper_func(update, context):
     group_id = update.effective_chat.id
     user_id = update.message.from_user['id']
     role = context.bot.get_chat_member(group_id, user_id).status
     if role == 'creator' or role == 'administrator' or group_id == user_id:
         func(update, context)
     else:
         language = get_lang(update, context)
         with codecs.open(os.path.join("Lang", language, "AdminPermission"), 'r', encoding='utf8') as file:
             update.message.reply_text(file.read())
Ejemplo n.º 6
0
def end_game(update: telegram.Update, context: telegram.ext.CallbackContext):
    group_data = context.chat_data
    language = get_lang(update, context)
    if "active_game" in group_data.keys():
        group_data["active_game"].delete_game()
        with codecs.open(os.path.join("Lang", language, "EndGame"), 'r', encoding='utf8') as file:
            update.message.reply_text(file.read())
    else:
        with codecs.open(os.path.join("Lang", language, "NoGame"), 'r', encoding='utf8') as file:
            update.message.reply_text(file.read())
Ejemplo n.º 7
0
def stats(update: telegram.Update, context: telegram.ext.CallbackContext):
    lang = get_lang(update, context)
    user = update.message.from_user
    player_data = context.user_data
    user_id = user["id"]
    user_name = user.full_name
    mark_down = f"[{user_name}](tg://user?id={str(user_id)})"
    city_total = player_data["city_win"] + player_data["city_lose"]
    mafia_total = player_data["mafia_win"] + player_data["mafia_lose"]
    text = ""
    if lang == 'en':
        text = f"Stats for {mark_down}:\nplayed: {player_data['total_games']} times\nWin rate: {int(player_data['win_percent'])}%\nCity: {city_total} Win rate: {int(player_data['city_win_percent'])}%\nMafia: {mafia_total} Win rate: {int(player_data['mafia_win_percent'])}%\n------------------------"
    else:
        text = f"آمار {mark_down} در بازی:\nبازی های انجام شده: {player_data['total_games']}\nدرصد برد: {int(player_data['win_percent'])}%\n\nدفعاتی که شهروند بوده: {city_total}\n درصد برد شهروندی: {int(player_data['city_win_percent'])}%\n\nدفعاتی که مافیا بوده: {mafia_total}\n درصد برد مافیایی: {int(player_data['mafia_win_percent'])}%\n------------------------"
    update.message.reply_markdown(text=text)
Ejemplo n.º 8
0
def leave(update: telegram.Update, context: telegram.ext.CallbackContext):
    user = update.message.from_user
    group_data = context.chat_data
    user_data = context.user_data
    language = get_lang(update, context)
    if "active_game" in group_data.keys():
        group_game = group_data["active_game"]
        if not group_game.is_started:
            group_game.leave_game(update, user, user_data)
        else:
            with codecs.open(os.path.join("Lang", language, "HasStartedLeave"), 'r', encoding='utf8') as file:
                update.message.reply_text(file.read())

    else:
        with codecs.open(os.path.join("Lang", language, "NoGame"), 'r', encoding='utf8') as file:
            update.message.reply_text(file.read())
Ejemplo n.º 9
0
def help_me(update, context):
    language = get_lang(update, context)
    with codecs.open(os.path.join("Lang", language, "Help"), 'r', encoding='utf8') as file:
        context.bot.send_message(
            chat_id=update.message.chat_id, text=file.read(), parse_mode="Markdown")