# * _ __ __ _ _ # * / \ _ _ _ __ ___ _ __ __ _| \/ | ___ __| |_ _| | ___ ___ # * / _ \| | | | '__/ _ \| '__/ _` | |\/| |/ _ \ / _` | | | | |/ _ \/ __| # * / ___ \ |_| | | | (_) | | | (_| | | | | (_) | (_| | |_| | | __/\__ \ # * /_/ \_\__,_|_| \___/|_| \__,_|_| |_|\___/ \__,_|\__,_|_|\___||___/ # * # * © Copyright 2024 # * # * https://t.me/AuroraModules # * # * 🔒 Code is licensed under GNU AGPLv3 # * 🌐 https://www.gnu.org/licenses/agpl-3.0.html # * ⛔️ You CANNOT edit this file without direct permission from the author. # * ⛔️ You CANNOT distribute this file if you have modified it without the direct permission of the author. # Name: RPSgame # Author: Felix # Commands: # .sgamerps (.rps) | .cleargames (.clg) # scope: hikka_only # meta developer: @AuroraModules __version__ = (1, 0, 0) import time import random from .. import loader, utils from telethon.utils import get_display_name # type: ignore class RPSgameMod(loader.Module): """With this module, you can play the game «rock, paper, scissors».""" strings = { "name": "RPSgame", "searching": "✌️ The game «Rock, Paper, Scissors» begins!\n👀 Waiting for a second player to join...", "join_game": "👾 Join the game", "rules": "📄 Game rules", "game_started": "⚠ The game has already started", "game_already_running": "🤚 Oops, a game is already running, use {}cleargames to end all active games.", "games_cleared": "🧹 All active games have been ended and cleared.", "turn": "🕹 The game has started!\n👀 The first turn goes to {}!", "next_player": "😱 It's {}'s turn next", "not_your_turn": "⚠ It's not your turn!", "not_player": "❌ You're not participating in the game", "cooldown": "⚠ Not so fast!", "winner": "🎉 Winner: {}\n\n👤 {} chose: {} \n👤{} chose: {}", "draw": "🤝 It's a draw!\n\n👤 {} chose: {}\n👤 {} chose: {}", "error_play_yourself": "⚠ You can't play against yourself", "rock": "🪨 Rock", "scissors": "✂️ Scissors", "paper": "📄 Paper", "random": "🎲 Random choice", "close_button": "🔻 Close", } strings_ru = { "searching": "✌️ Игра «Камень, ножницы, бумага» начинается!\n👀 Ожидание, присоединение 2 игрока...", "join_game": "👾 Присоединиться к игре", "rules": "📄 Правила игры", "game_started": "⚠ Игра уже началась", "game_already_running": "🤚 Упс, игра уже запущена, используйте {}cleargames, чтобы завершить все начатые игры.", "games_cleared": "🧹 Все активные игры были завершены и очищены.", "turn": "🕹 Игра началась!\n👀 Первый ход за {}!", "next_player": "😱 Следующий ходит {}", "not_your_turn": "⚠ Это не ваш ход!", "not_player": "❌ Вы не участвуете в игре", "cooldown": "⚠ Не так быстро!", "winner": "🎉 Победитель: {}\n\n👤 {} выбрал: {} \n👤{} выбрал: {}", "draw": "🤝 Ничья!\n\n👤 {} выбрал: {}\n👤 {} выбрал: {}", "error_play_yourself": "⚠ Вы не можете играть с самим сабой", "rock": "🪨 Камень", "scissors": "✂️ Ножницы", "paper": "📄 Бумага", "random": "🎲 Случайный выбор", "close_button": "🔻 Закрыть", } strings_uz = { "searching": "✌️ «Qog'oz, Qaychi, Tosh» o'yini boshlanmoqda!\n👀 Ikkinchi o'yinchi kutilmoqda...", "join_game": "👾 O'yinga qo'shilish", "rules": "📄 O'yin qoidalari", "game_started": "⚠ O'yin allaqachon boshlangan", "game_already_running": "🤚 Oops, o'yin allaqachon boshlangan, {}cleargames buyruqni ishlating, barcha o'yinlarni tugatish uchun.", "games_cleared": "🧹 Barcha faol o'yinlar tugatildi va tozalandi.", "turn": "🕹 O'yin boshlandi!\n👀 Birinchi yurish {}!", "next_player": "😱 Keyingi yurish {} da", "not_your_turn": "⚠ Bu sizning navbatingiz emas!", "not_player": "❌ Siz o'yinda emassiz", "cooldown": "⚠ Shoshilmang!", "winner": "🎉 G'olib: {}\n\n👤 {} tanladi: {} \n👤{} tanladi: {}", "draw": "🤝 Durrang!\n\n👤 {} tanladi: {}\n👤 {} tanladi: {}", "error_play_yourself": "⚠ O'zingiz bilan o'ynay olmaysiz", "rock": "🪨 Tosh", "scissors": "✂️ Qaychi", "paper": "📄 Qog'oz", "random": "🎲 Tasodifiy tanlash", "close_button": "🔻 Yopish", } strings_de = { "searching": "✌️ Das Spiel «Schere, Stein, Papier» beginnt!\n👀 Warte auf den zweiten Spieler...", "join_game": "👾 Dem Spiel beitreten", "rules": "📄 Spielregeln", "game_started": "⚠ Das Spiel hat bereits begonnen", "game_already_running": "🤚 Ups, ein Spiel läuft bereits, benutze {}cleargames, um alle aktiven Spiele zu beenden.", "games_cleared": "🧹 Alle aktiven Spiele wurden beendet und gelöscht.", "turn": "🕹 Das Spiel hat begonnen!\n👀 Der erste Zug geht an {}!", "next_player": "😱 Der nächste Zug geht an {}", "not_your_turn": "⚠ Es ist nicht dein Zug!", "not_player": "❌ Du nimmst nicht am Spiel teil", "cooldown": "⚠ Nicht so schnell!", "winner": "🎉 Gewinner: {}\n\n👤 {} wählte: {} \n👤{} wählte: {}", "draw": "🤝 Unentschieden!\n\n👤 {} wählte: {}\n👤 {} wählte: {}", "error_play_yourself": "⚠ Du kannst nicht gegen dich selbst spielen", "rock": "🪨 Stein", "scissors": "✂️ Schere", "paper": "📄 Papier", "random": "🎲 Zufällige Wahl", "close_button": "🔻 Schließen", } strings_es = { "searching": "✌️ El juego «Piedra, Papel, Tijeras» comienza!\n👀 Esperando que se una un segundo jugador...", "join_game": "👾 Unirse al juego", "rules": "📄 Reglas del juego", "game_started": "⚠ El juego ya ha comenzado", "game_already_running": "🤚 Ups, un juego ya está en marcha, usa {}cleargames para terminar todos los juegos activos.", "games_cleared": "🧹 Todos los juegos activos han sido terminados y eliminados.", "turn": "🕹 ¡El juego ha comenzado!\n👀 El primer turno es para {}!", "next_player": "😱 El siguiente turno es para {}", "not_your_turn": "⚠ ¡No es tu turno!", "not_player": "❌ No estás participando en el juego", "cooldown": "⚠ ¡No tan rápido!", "winner": "🎉 Ganador: {}\n\n👤 {} eligió: {} \n👤{} eligió: {}", "draw": "🤝 ¡Empate!\n\n👤 {} eligió: {}\n👤 {} eligió: {}", "error_play_yourself": "⚠ No puedes jugar contra ti mismo", "rock": "🪨 Piedra", "scissors": "✂️ Tijeras", "paper": "📄 Papel", "random": "🎲 Elección aleatoria", "close_button": "🔻 Cerrar", } def __init__(self): self.games = {} self.last_click_time = {} @loader.command( ru_doc="- Начать игру «Камень, ножницы, бумага»", uz_doc="- «Tosh, qog'oz, qaychi» o'yinining boshlanishi", de_doc="- Beginn des Spiels «Stein, Papier, Schere»", es_doc="- El comienzo del juego «Piedra, papel o tijera»", alias="rps" ) async def sgamerps(self, message): """- Start the game «Rock, Paper, Scissors»""" chat_id = message.chat_id player1_id = message.sender_id game_id = f"{chat_id}_{player1_id}" prefix = utils.escape_html(self.get_prefix()) if game_id in self.games: await utils.answer(message, self.strings["game_already_running"].format(prefix)) return self.games[game_id] = { "player1": player1_id, "player2": None, "choices": {}, "current_turn": None, } await self.inline.form( message=message, text=self.strings["searching"], reply_markup=[ [ {"text": self.strings['rules'], "url": "https://ru.wikipedia.org/wiki/Камень,_ножницы,_бумага#Правила_игры:~:text=Победитель%20определяется%20по%20следующим%20правилам%3A"} ], [ {"text": self.strings['join_game'], "callback": self.join_game, "args": (game_id,),} ], ], disable_security=True, ) async def join_game(self, call, game_id: str): game = self.games.get(game_id) player2_id = call.from_user.id current_time = time.time() if player2_id in self.last_click_time and current_time - self.last_click_time[player2_id] < 3: await call.answer(self.strings["cooldown"]) return self.last_click_time[player2_id] = current_time if game["player1"] == player2_id: await call.answer(self.strings["error_play_yourself"]) return if game["player2"] is not None: await call.answer(self.strings["game_started"]) return game["player2"] = player2_id game["current_turn"] = random.choice([game["player1"], game["player2"]]) await call.edit( text=self.strings["turn"].format( get_display_name(await self._client.get_entity(game["current_turn"])) ), reply_markup=[ [ {"text": self.strings["rock"], "callback": self.make_choice, "args": (game_id, "rock")}, {"text": self.strings["scissors"], "callback": self.make_choice, "args": (game_id, "scissors")}, {"text": self.strings["paper"], "callback": self.make_choice, "args": (game_id, "paper")}, ], [ {"text": self.strings["random"], "callback": self.make_choice, "args": (game_id, "random")}, ], ] ) async def make_choice(self, call, game_id: str, choice: str): game = self.games.get(game_id) current_time = time.time() if call.from_user.id in self.last_click_time and current_time - self.last_click_time[call.from_user.id] < 2: await call.answer(self.strings["cooldown"]) return self.last_click_time[call.from_user.id] = current_time if call.from_user.id not in [game["player1"], game["player2"]]: await call.answer(self.strings["not_player"]) return is_random = choice == "random" if is_random: choice = random.choice(["rock", "scissors", "paper"]) game["choices"][call.from_user.id] = (choice, "random" if is_random else None) if len(game["choices"]) == 2: await self.resolve_game(call, game_id) else: game["current_turn"] = game["player1"] if call.from_user.id == game["player2"] else game["player2"] next_player = get_display_name(await self._client.get_entity(game['current_turn'])) await call.edit( text=self.strings['next_player'].format(next_player), reply_markup=[ [ {"text": self.strings["rock"], "callback": self.make_choice, "args": (game_id, "rock")}, {"text": self.strings["scissors"], "callback": self.make_choice, "args": (game_id, "scissors")}, {"text": self.strings["paper"], "callback": self.make_choice, "args": (game_id, "paper")}, ], [ {"text": self.strings["random"], "callback": self.make_choice, "args": (game_id, "random")}, ], ] ) async def resolve_game(self, call, game_id: str): game = self.games.get(game_id) if not game: return player1_id = game["player1"] player2_id = game["player2"] player1_choice, player1_random = game["choices"].get(player1_id, (None, None)) player2_choice, player2_random = game["choices"].get(player2_id, (None, None)) if player1_choice is None or player2_choice is None: return player1_choice_text = self.strings[player1_choice] player2_choice_text = self.strings[player2_choice] if player1_random: player1_choice_text += " [🎲RANDOM]" if player2_random: player2_choice_text += " [🎲RANDOM]" if player1_choice == player2_choice: result_message = self.strings["draw"].format( player1_id, utils.escape_html(get_display_name(await self._client.get_entity(player1_id))), player1_choice_text, player2_id, utils.escape_html(get_display_name(await self._client.get_entity(player2_id))), player2_choice_text, ) else: winning_conditions = { "rock": "scissors", "scissors": "paper", "paper": "rock" } winner_id = player1_id if winning_conditions[player1_choice] == player2_choice else player2_id result_message = self.strings["winner"].format( utils.escape_html(get_display_name(await self._client.get_entity(winner_id))), winner_id, utils.escape_html(get_display_name(await self._client.get_entity(player1_id))), player1_choice_text, player2_id, utils.escape_html(get_display_name(await self._client.get_entity(player2_id))), player2_choice_text, ) await call.edit(text=result_message, reply_markup=[ [ {"text": self.strings["close_button"], "callback": self.call_del}, ] ]) del self.games[game_id] async def call_del(self, call): await call.delete() @loader.command( ru_doc=f"- Завершить все активные игры.", uz_doc="- Barcha faol o'yinlarni tugatish.", de_doc="- Alle aktiven Spiele beenden.", es_doc="- Completar todos los juegos en curso.", alias="clg" ) async def cleargames(self, message): """- Complete all running games.""" self.games.clear() await utils.answer(message, self.strings["games_cleared"])