Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
|
9234e3858f |
3
.gitignore
vendored
|
@ -1,6 +1,3 @@
|
||||||
# Config file
|
|
||||||
config.json
|
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
|
@ -7,8 +7,5 @@
|
||||||
The following wonderful people contributed directly or indirectly to this project:
|
The following wonderful people contributed directly or indirectly to this project:
|
||||||
|
|
||||||
- [imlonghao](https://github.com/imlonghao)
|
- [imlonghao](https://github.com/imlonghao)
|
||||||
- [pan93412](https://github.com/pan93412)
|
|
||||||
- [qubitnerd](https://github.com/qubitnerd)
|
|
||||||
- [SYHGroup](https://github.com/SYHGroup)
|
|
||||||
|
|
||||||
Please add yourself here alphabetically when you submit your first pull request.
|
Please add yourself here alphabetically when you submit your first pull request.
|
13
Pipfile
|
@ -1,13 +0,0 @@
|
||||||
[[source]]
|
|
||||||
name = "pypi"
|
|
||||||
url = "https://pypi.org/simple"
|
|
||||||
verify_ssl = true
|
|
||||||
|
|
||||||
[dev-packages]
|
|
||||||
|
|
||||||
[packages]
|
|
||||||
python-telegram-bot = "==8.1.1"
|
|
||||||
pony = "*"
|
|
||||||
|
|
||||||
[requires]
|
|
||||||
python_version = "3.7"
|
|
49
Pipfile.lock
generated
|
@ -1,49 +0,0 @@
|
||||||
{
|
|
||||||
"_meta": {
|
|
||||||
"hash": {
|
|
||||||
"sha256": "de56c4d5f516205e99d141cd7d372f67b602b6f981306971c01ffe25a5abf5c6"
|
|
||||||
},
|
|
||||||
"pipfile-spec": 6,
|
|
||||||
"requires": {
|
|
||||||
"python_version": "3.7"
|
|
||||||
},
|
|
||||||
"sources": [
|
|
||||||
{
|
|
||||||
"name": "pypi",
|
|
||||||
"url": "https://pypi.org/simple",
|
|
||||||
"verify_ssl": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"default": {
|
|
||||||
"certifi": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:046832c04d4e752f37383b628bc601a7ea7211496b4638f6514d0e5b9acc4939",
|
|
||||||
"sha256:945e3ba63a0b9f577b1395204e13c3a231f9bc0223888be653286534e5873695"
|
|
||||||
],
|
|
||||||
"version": "==2019.6.16"
|
|
||||||
},
|
|
||||||
"future": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8"
|
|
||||||
],
|
|
||||||
"version": "==0.17.1"
|
|
||||||
},
|
|
||||||
"pony": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:55bb9d4d12029d8c2bbbc7a284970e72225035db7e6370c0a15ec93d1886fe88"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"version": "==0.7.10"
|
|
||||||
},
|
|
||||||
"python-telegram-bot": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:238c4a88b09d93c52d413bcf7e7fe14dfeb02f5f9222ffe4cafd4bd3d55489a3",
|
|
||||||
"sha256:997983e5082dc6aa811bce3a6014731201fc64b0a9c02fdb26beac686029d94b"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"version": "==8.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"develop": {}
|
|
||||||
}
|
|
24
README.md
|
@ -1,24 +1,10 @@
|
||||||
# UNO Bot
|
# UNO Bot
|
||||||
|
Telegram Bot that allows you to play the popular card game UNO via inline queries. The bot currently runs as [@mau_mau_bot](http://telegram.me/mau_mau_bot)
|
||||||
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](./LICENSE)
|
|
||||||
|
|
||||||
Telegram Bot that allows you to play the popular card game UNO via inline queries. The bot currently runs as [@unobot](http://telegram.me/unobot).
|
|
||||||
|
|
||||||
To run the bot yourself, you will need:
|
To run the bot yourself, you will need:
|
||||||
- Python (tested with 3.4+)
|
- Python (tested with 3.4 and 3.5)
|
||||||
- The [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) module
|
- The [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) module version 4.1.1
|
||||||
- [Pony ORM](https://ponyorm.com/)
|
|
||||||
|
|
||||||
## Setup
|
Get a bot token from [@BotFather](http://telegram.me/BotFather), place it in `credentials.py` and run the bot with `python3 bot.py`
|
||||||
- Get a bot token from [@BotFather](http://telegram.me/BotFather) and change configurations in `config.json`.
|
|
||||||
- Convert all language files from `.po` files to `.mo` by executing the bash script `compile.sh` located in the `locales` folder.
|
|
||||||
Another option is: `find . -maxdepth 2 -type d -name 'LC_MESSAGES' -exec bash -c 'msgfmt {}/unobot.po -o {}/unobot.mo' \;`.
|
|
||||||
- Use `/setinline` and `/setinlinefeedback` with BotFather for your bot.
|
|
||||||
- Install requirements (using a `virtualenv` is recommended): `pip install -r requirements.txt`
|
|
||||||
|
|
||||||
You can change some gameplay parameters like turn times, minimum amount of players and default gamemode in `config.json`.
|
Code documentation is minimal but there
|
||||||
Current gamemodes available: classic, fast and wild. Check the details with the `/modes` command.
|
|
||||||
|
|
||||||
Then run the bot with `python3 bot.py`.
|
|
||||||
|
|
||||||
Code documentation is minimal but there.
|
|
||||||
|
|
|
@ -2,17 +2,9 @@
|
||||||
|
|
||||||
The following awesome people contributed to this project by translating it:
|
The following awesome people contributed to this project by translating it:
|
||||||
|
|
||||||
| Locale | Translators |
|
| Locale | Translators |
|
||||||
|--------|--------------------------------------------------------------------------------------------------------------|
|
|--------|--------------------------------------------------------|
|
||||||
| de_DE | [Jannes Höke](https://github.com/jh0ker) |
|
| de_DE | [Jannes Höke](https://github.com/jh0ker) |
|
||||||
| es_ES | [José.A Rojo](https://github.com/J4RV), [Ricardo Valverde Hernández](https://telegram.me/rivh1), Victor, Yuga|
|
| it_IT | Carola Mariano, nick |
|
||||||
| id_ID | [Erwin Guo](https://www.facebook.com/erwinfransiscus) |
|
|
||||||
| it_IT | Carola Mariano, ɳick |
|
|
||||||
| pt_BR | [João Rodrigo Couto de Oliveira](http://twitter.com/JoaoRodrigoJR)
|
|
||||||
| tr_TR | [Kasım Ağca](https://telegram.me/Holytotem)
|
|
||||||
|
|
|
||||||
| zh_CN | [imlonghao](https://github.com/imlonghao) |
|
|
||||||
| zh_HK | [Jed Cheng](https://www.facebook.com/profile.php?id=100002258388821) |
|
|
||||||
| zh_TW | [Eugene Lam](https://www.facebook.com/eugenelam1118), [jimchen5209](https://www.youtube.com/user/jimchen5209), [pan93412](https://www.github.com/pan93412)|
|
|
||||||
|
|
||||||
Please add yourself here alphabetically when you submit your first translation.
|
Please add yourself here alphabetically when you submit your first translation.
|
213
actions.py
|
@ -1,213 +0,0 @@
|
||||||
import random
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import card as c
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from telegram import Message, Chat
|
|
||||||
|
|
||||||
from config import TIME_REMOVAL_AFTER_SKIP, MIN_FAST_TURN_TIME
|
|
||||||
from errors import DeckEmptyError, NotEnoughPlayersError
|
|
||||||
from internationalization import __, _
|
|
||||||
from shared_vars import gm
|
|
||||||
from user_setting import UserSetting
|
|
||||||
from utils import send_async, display_name, game_is_running
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class Countdown(object):
|
|
||||||
player = None
|
|
||||||
job_queue = None
|
|
||||||
|
|
||||||
def __init__(self, player, job_queue):
|
|
||||||
self.player = player
|
|
||||||
self.job_queue = job_queue
|
|
||||||
|
|
||||||
|
|
||||||
# TODO do_skip() could get executed in another thread (it can be a job), so it looks like it can't use game.translate?
|
|
||||||
def do_skip(bot, player, job_queue=None):
|
|
||||||
game = player.game
|
|
||||||
chat = game.chat
|
|
||||||
skipped_player = game.current_player
|
|
||||||
next_player = game.current_player.next
|
|
||||||
|
|
||||||
if skipped_player.waiting_time > 0:
|
|
||||||
skipped_player.anti_cheat += 1
|
|
||||||
skipped_player.waiting_time -= TIME_REMOVAL_AFTER_SKIP
|
|
||||||
if (skipped_player.waiting_time < 0):
|
|
||||||
skipped_player.waiting_time = 0
|
|
||||||
|
|
||||||
try:
|
|
||||||
skipped_player.draw()
|
|
||||||
except DeckEmptyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
n = skipped_player.waiting_time
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("Waiting time to skip this player has "
|
|
||||||
"been reduced to {time} seconds.\n"
|
|
||||||
"Next player: {name}", multi=game.translate)
|
|
||||||
.format(time=n,
|
|
||||||
name=display_name(next_player.user))
|
|
||||||
)
|
|
||||||
logger.info("{player} was skipped! "
|
|
||||||
.format(player=display_name(player.user)))
|
|
||||||
game.turn()
|
|
||||||
if job_queue:
|
|
||||||
start_player_countdown(bot, game, job_queue)
|
|
||||||
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
gm.leave_game(skipped_player.user, chat)
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("{name1} ran out of time "
|
|
||||||
"and has been removed from the game!\n"
|
|
||||||
"Next player: {name2}", multi=game.translate)
|
|
||||||
.format(name1=display_name(skipped_player.user),
|
|
||||||
name2=display_name(next_player.user)))
|
|
||||||
logger.info("{player} was skipped! "
|
|
||||||
.format(player=display_name(player.user)))
|
|
||||||
if job_queue:
|
|
||||||
start_player_countdown(bot, game, job_queue)
|
|
||||||
|
|
||||||
except NotEnoughPlayersError:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("{name} ran out of time "
|
|
||||||
"and has been removed from the game!\n"
|
|
||||||
"The game ended.", multi=game.translate)
|
|
||||||
.format(name=display_name(skipped_player.user)))
|
|
||||||
|
|
||||||
gm.end_game(chat, skipped_player.user)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def do_play_card(bot, player, result_id):
|
|
||||||
"""Plays the selected card and sends an update to the group if needed"""
|
|
||||||
card = c.from_str(result_id)
|
|
||||||
player.play(card)
|
|
||||||
game = player.game
|
|
||||||
chat = game.chat
|
|
||||||
user = player.user
|
|
||||||
|
|
||||||
us = UserSetting.get(id=user.id)
|
|
||||||
if not us:
|
|
||||||
us = UserSetting(id=user.id)
|
|
||||||
|
|
||||||
if us.stats:
|
|
||||||
us.cards_played += 1
|
|
||||||
|
|
||||||
if game.choosing_color:
|
|
||||||
send_async(bot, chat.id, text=__("Please choose a color", multi=game.translate))
|
|
||||||
|
|
||||||
if len(player.cards) == 1:
|
|
||||||
send_async(bot, chat.id, text="UNO!")
|
|
||||||
|
|
||||||
if len(player.cards) == 0:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("{name} won!", multi=game.translate)
|
|
||||||
.format(name=user.first_name))
|
|
||||||
|
|
||||||
if us.stats:
|
|
||||||
us.games_played += 1
|
|
||||||
|
|
||||||
if game.players_won is 0:
|
|
||||||
us.first_places += 1
|
|
||||||
|
|
||||||
game.players_won += 1
|
|
||||||
|
|
||||||
try:
|
|
||||||
gm.leave_game(user, chat)
|
|
||||||
except NotEnoughPlayersError:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("Game ended!", multi=game.translate))
|
|
||||||
|
|
||||||
us2 = UserSetting.get(id=game.current_player.user.id)
|
|
||||||
if us2 and us2.stats:
|
|
||||||
us2.games_played += 1
|
|
||||||
|
|
||||||
gm.end_game(chat, user)
|
|
||||||
|
|
||||||
|
|
||||||
def do_draw(bot, player):
|
|
||||||
"""Does the drawing"""
|
|
||||||
game = player.game
|
|
||||||
draw_counter_before = game.draw_counter
|
|
||||||
|
|
||||||
try:
|
|
||||||
player.draw()
|
|
||||||
except DeckEmptyError:
|
|
||||||
send_async(bot, player.game.chat.id,
|
|
||||||
text=__("There are no more cards in the deck.",
|
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
if (game.last_card.value == c.DRAW_TWO or
|
|
||||||
game.last_card.special == c.DRAW_FOUR) and \
|
|
||||||
draw_counter_before > 0:
|
|
||||||
game.turn()
|
|
||||||
|
|
||||||
|
|
||||||
def do_call_bluff(bot, player):
|
|
||||||
"""Handles the bluff calling"""
|
|
||||||
game = player.game
|
|
||||||
chat = game.chat
|
|
||||||
|
|
||||||
if player.prev.bluffing:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("Bluff called! Giving 4 cards to {name}",
|
|
||||||
multi=game.translate)
|
|
||||||
.format(name=player.prev.user.first_name))
|
|
||||||
|
|
||||||
try:
|
|
||||||
player.prev.draw()
|
|
||||||
except DeckEmptyError:
|
|
||||||
send_async(bot, player.game.chat.id,
|
|
||||||
text=__("There are no more cards in the deck.",
|
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
else:
|
|
||||||
game.draw_counter += 2
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
|
|
||||||
multi=game.translate)
|
|
||||||
.format(name1=player.prev.user.first_name,
|
|
||||||
name2=player.user.first_name))
|
|
||||||
try:
|
|
||||||
player.draw()
|
|
||||||
except DeckEmptyError:
|
|
||||||
send_async(bot, player.game.chat.id,
|
|
||||||
text=__("There are no more cards in the deck.",
|
|
||||||
multi=game.translate))
|
|
||||||
|
|
||||||
game.turn()
|
|
||||||
|
|
||||||
|
|
||||||
def start_player_countdown(bot, game, job_queue):
|
|
||||||
player = game.current_player
|
|
||||||
time = player.waiting_time
|
|
||||||
|
|
||||||
if time < MIN_FAST_TURN_TIME:
|
|
||||||
time = MIN_FAST_TURN_TIME
|
|
||||||
|
|
||||||
if game.mode == 'fast':
|
|
||||||
if game.job:
|
|
||||||
game.job.schedule_removal()
|
|
||||||
|
|
||||||
job = job_queue.run_once(
|
|
||||||
#lambda x,y: do_skip(bot, player),
|
|
||||||
skip_job,
|
|
||||||
time,
|
|
||||||
context=Countdown(player, job_queue)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("Started countdown for player: {player}. {time} seconds."
|
|
||||||
.format(player=display_name(player.user), time=time))
|
|
||||||
player.game.job = job
|
|
||||||
|
|
||||||
|
|
||||||
def skip_job(bot, job):
|
|
||||||
player = job.context.player
|
|
||||||
game = player.game
|
|
||||||
if game_is_running(game):
|
|
||||||
job_queue = job.context.job_queue
|
|
||||||
do_skip(bot, player, job_queue)
|
|
484
bot.py
|
@ -17,54 +17,39 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from random import randint
|
||||||
|
|
||||||
from telegram import ParseMode, InlineKeyboardMarkup, \
|
from telegram import ParseMode, Message, Chat, InlineKeyboardMarkup, \
|
||||||
InlineKeyboardButton
|
InlineKeyboardButton
|
||||||
from telegram.ext import InlineQueryHandler, ChosenInlineResultHandler, \
|
from telegram.ext import InlineQueryHandler, ChosenInlineResultHandler, \
|
||||||
CommandHandler, MessageHandler, Filters, CallbackQueryHandler
|
CommandHandler, MessageHandler, Filters, CallbackQueryHandler
|
||||||
from telegram.ext.dispatcher import run_async
|
from telegram.ext.dispatcher import run_async
|
||||||
|
|
||||||
import card as c
|
from start_bot import start_bot
|
||||||
import settings
|
|
||||||
import simple_commands
|
|
||||||
from actions import do_skip, do_play_card, do_draw, do_call_bluff, start_player_countdown
|
|
||||||
from config import WAITING_TIME, DEFAULT_GAMEMODE, MIN_PLAYERS
|
|
||||||
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
|
|
||||||
NotEnoughPlayersError, DeckEmptyError)
|
|
||||||
from internationalization import _, __, user_locale, game_locales
|
|
||||||
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
|
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
|
||||||
add_no_game, add_not_started, add_other_cards, add_pass,
|
add_no_game, add_not_started, add_other_cards, add_pass,
|
||||||
add_card, add_mode_classic, add_mode_fast, add_mode_wild)
|
add_card)
|
||||||
from shared_vars import gm, updater, dispatcher
|
from user_setting import UserSetting
|
||||||
from simple_commands import help_handler
|
|
||||||
from start_bot import start_bot
|
|
||||||
from utils import display_name
|
from utils import display_name
|
||||||
from utils import send_async, answer_async, error, TIMEOUT, user_is_creator_or_admin, user_is_creator, game_is_running
|
import card as c
|
||||||
|
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
|
||||||
|
NotEnoughPlayersError, DeckEmptyError)
|
||||||
|
from utils import _, __, send_async, answer_async, user_locale, game_locales, \
|
||||||
|
error, TIMEOUT
|
||||||
|
from shared_vars import botan, gm, updater, dispatcher
|
||||||
|
|
||||||
|
import simple_commands, settings
|
||||||
|
from simple_commands import help
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.INFO
|
level=logging.DEBUG)
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@user_locale
|
|
||||||
def notify_me(bot, update):
|
|
||||||
"""Handler for /notify_me command, pm people for next game"""
|
|
||||||
chat_id = update.message.chat_id
|
|
||||||
if update.message.chat.type == 'private':
|
|
||||||
send_async(bot,
|
|
||||||
chat_id,
|
|
||||||
text=_("Send this command in a group to be notified "
|
|
||||||
"when a new game is started there."))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
gm.remind_dict[chat_id].add(update.message.from_user.id)
|
|
||||||
except KeyError:
|
|
||||||
gm.remind_dict[chat_id] = {update.message.from_user.id}
|
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
def new_game(bot, update):
|
def new_game(bot, update):
|
||||||
|
@ -72,63 +57,18 @@ def new_game(bot, update):
|
||||||
chat_id = update.message.chat_id
|
chat_id = update.message.chat_id
|
||||||
|
|
||||||
if update.message.chat.type == 'private':
|
if update.message.chat.type == 'private':
|
||||||
help_handler(bot, update)
|
help(bot, update)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if update.message.chat_id in gm.remind_dict:
|
|
||||||
for user in gm.remind_dict[update.message.chat_id]:
|
|
||||||
send_async(bot,
|
|
||||||
user,
|
|
||||||
text=_("A new game has been started in {title}").format(
|
|
||||||
title=update.message.chat.title))
|
|
||||||
|
|
||||||
del gm.remind_dict[update.message.chat_id]
|
|
||||||
|
|
||||||
game = gm.new_game(update.message.chat)
|
game = gm.new_game(update.message.chat)
|
||||||
game.starter = update.message.from_user
|
game.owner = update.message.from_user
|
||||||
game.owner.append(update.message.from_user.id)
|
|
||||||
game.mode = DEFAULT_GAMEMODE
|
|
||||||
send_async(bot, chat_id,
|
send_async(bot, chat_id,
|
||||||
text=_("Created a new game! Join the game with /join "
|
text=_("Created a new game! Join the game with /join "
|
||||||
"and start the game with /start"))
|
"and start the game with /start"))
|
||||||
|
|
||||||
|
if botan:
|
||||||
|
botan.track(update.message, 'New games')
|
||||||
|
|
||||||
@user_locale
|
|
||||||
def kill_game(bot, update):
|
|
||||||
"""Handler for the /kill command"""
|
|
||||||
chat = update.message.chat
|
|
||||||
user = update.message.from_user
|
|
||||||
games = gm.chatid_games.get(chat.id)
|
|
||||||
|
|
||||||
if update.message.chat.type == 'private':
|
|
||||||
help_handler(bot, update)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not games:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("There is no running game in this chat."))
|
|
||||||
return
|
|
||||||
|
|
||||||
game = games[-1]
|
|
||||||
|
|
||||||
if user_is_creator_or_admin(user, game, bot, chat):
|
|
||||||
|
|
||||||
try:
|
|
||||||
gm.end_game(chat, user)
|
|
||||||
send_async(bot, chat.id, text=__("Game ended!", multi=game.translate))
|
|
||||||
|
|
||||||
except NoGameInChatError:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("The game is not started yet. "
|
|
||||||
"Join the game with /join and start the game with /start"),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
|
|
||||||
else:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
|
||||||
.format(name=game.starter.first_name),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
def join_game(bot, update):
|
def join_game(bot, update):
|
||||||
|
@ -136,7 +76,7 @@ def join_game(bot, update):
|
||||||
chat = update.message.chat
|
chat = update.message.chat
|
||||||
|
|
||||||
if update.message.chat.type == 'private':
|
if update.message.chat.type == 'private':
|
||||||
help_handler(bot, update)
|
help(bot, update)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -196,93 +136,16 @@ def leave_game(bot, update):
|
||||||
|
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
gm.end_game(chat, user)
|
gm.end_game(chat, user)
|
||||||
send_async(bot, chat.id, text=__("Game ended!", multi=game.translate))
|
send_async(bot, chat.id, text=__("Game ended!", game.translate))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if game.started:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("Okay. Next Player: {name}",
|
|
||||||
multi=game.translate).format(
|
|
||||||
name=display_name(game.current_player.user)),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
else:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("{name} left the game before it started.",
|
|
||||||
multi=game.translate).format(
|
|
||||||
name=display_name(user)),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
|
||||||
def kick_player(bot, update):
|
|
||||||
"""Handler for the /kick command"""
|
|
||||||
|
|
||||||
if update.message.chat.type == 'private':
|
|
||||||
help_handler(bot, update)
|
|
||||||
return
|
|
||||||
|
|
||||||
chat = update.message.chat
|
|
||||||
user = update.message.from_user
|
|
||||||
|
|
||||||
try:
|
|
||||||
game = gm.chatid_games[chat.id][-1]
|
|
||||||
|
|
||||||
except (KeyError, IndexError):
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("No game is running at the moment. "
|
|
||||||
"Create a new game with /new"),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not game.started:
|
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("The game is not started yet. "
|
text=__("Okay. Next Player: {name}", game.translate).format(
|
||||||
"Join the game with /join and start the game with /start"),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
if user_is_creator_or_admin(user, game, bot, chat):
|
|
||||||
|
|
||||||
if update.message.reply_to_message:
|
|
||||||
kicked = update.message.reply_to_message.from_user
|
|
||||||
|
|
||||||
try:
|
|
||||||
gm.leave_game(kicked, chat)
|
|
||||||
|
|
||||||
except NoGameInChatError:
|
|
||||||
send_async(bot, chat.id, text=_("Player {name} is not found in the current game.".format(name=display_name(kicked))),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
except NotEnoughPlayersError:
|
|
||||||
gm.end_game(chat, user)
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("{0} was kicked by {1}".format(display_name(kicked), display_name(user))))
|
|
||||||
send_async(bot, chat.id, text=__("Game ended!", multi=game.translate))
|
|
||||||
return
|
|
||||||
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("{0} was kicked by {1}".format(display_name(kicked), display_name(user))))
|
|
||||||
|
|
||||||
else:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("Please reply to the person you want to kick and type /kick again."),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=__("Okay. Next Player: {name}",
|
|
||||||
multi=game.translate).format(
|
|
||||||
name=display_name(game.current_player.user)),
|
name=display_name(game.current_player.user)),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
else:
|
|
||||||
send_async(bot, chat.id,
|
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
|
||||||
.format(name=game.starter.first_name),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
|
||||||
|
|
||||||
|
|
||||||
|
@run_async
|
||||||
def select_game(bot, update):
|
def select_game(bot, update):
|
||||||
"""Handler for callback queries to select the current game"""
|
"""Handler for callback queries to select the current game"""
|
||||||
|
|
||||||
|
@ -294,31 +157,28 @@ def select_game(bot, update):
|
||||||
gm.userid_current[user_id] = player
|
gm.userid_current[user_id] = player
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
send_async(bot,
|
bot.sendMessage(update.callback_query.message.chat_id,
|
||||||
update.callback_query.message.chat_id,
|
text=_("Game not found."),
|
||||||
text=_("Game not found."))
|
timeout=TIMEOUT)
|
||||||
return
|
return
|
||||||
|
|
||||||
@run_async
|
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
||||||
def selected(bot):
|
switch_inline_query='')]]
|
||||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
|
||||||
switch_inline_query='')]]
|
|
||||||
bot.answerCallbackQuery(update.callback_query.id,
|
|
||||||
text=_("Please switch to the group you selected!"),
|
|
||||||
show_alert=False,
|
|
||||||
timeout=TIMEOUT)
|
|
||||||
|
|
||||||
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
bot.answerCallbackQuery(update.callback_query.id,
|
||||||
message_id=update.callback_query.message.message_id,
|
text=_("Please switch to the group you selected!"),
|
||||||
text=_("Selected group: {group}\n"
|
show_alert=False,
|
||||||
"<b>Make sure that you switch to the correct "
|
|
||||||
"group!</b>").format(
|
|
||||||
group=gm.userid_current[user_id].game.chat.title),
|
|
||||||
reply_markup=InlineKeyboardMarkup(back),
|
|
||||||
parse_mode=ParseMode.HTML,
|
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
selected(bot)
|
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
||||||
|
message_id=update.callback_query.message.message_id,
|
||||||
|
text=_("Selected group: {group}\n"
|
||||||
|
"<b>Make sure that you switch to the correct "
|
||||||
|
"group!</b>").format(
|
||||||
|
group=gm.userid_current[user_id].game.chat.title),
|
||||||
|
reply_markup=InlineKeyboardMarkup(back),
|
||||||
|
parse_mode=ParseMode.HTML,
|
||||||
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
|
@ -337,17 +197,16 @@ def status_update(bot, update):
|
||||||
pass
|
pass
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
gm.end_game(chat, user)
|
gm.end_game(chat, user)
|
||||||
send_async(bot, chat.id, text=__("Game ended!",
|
send_async(bot, chat.id, text=__("Game ended!", game.translate))
|
||||||
multi=game.translate))
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id, text=__("Removing {name} from the game",
|
send_async(bot, chat.id, text=__("Removing {name} from the game",
|
||||||
multi=game.translate)
|
game.translate)
|
||||||
.format(name=display_name(user)))
|
.format(name=display_name(user)))
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
@user_locale
|
@user_locale
|
||||||
def start_game(bot, update, args, job_queue):
|
def start_game(bot, update, args):
|
||||||
"""Handler for the /start command"""
|
"""Handler for the /start command"""
|
||||||
|
|
||||||
if update.message.chat.type != 'private':
|
if update.message.chat.type != 'private':
|
||||||
|
@ -364,23 +223,20 @@ def start_game(bot, update, args, job_queue):
|
||||||
if game.started:
|
if game.started:
|
||||||
send_async(bot, chat.id, text=_("The game has already started"))
|
send_async(bot, chat.id, text=_("The game has already started"))
|
||||||
|
|
||||||
elif len(game.players) < MIN_PLAYERS:
|
elif len(game.players) < 2:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("At least {minplayers} players must /join the game "
|
text=_("At least two players must /join the game "
|
||||||
"before you can start it").format(minplayers=MIN_PLAYERS))
|
"before you can start it"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Starting a game
|
game.play_card(game.last_card)
|
||||||
game.start()
|
game.started = True
|
||||||
|
|
||||||
for player in game.players:
|
|
||||||
player.draw_first_hand()
|
|
||||||
choice = [[InlineKeyboardButton(text=_("Make your choice!"), switch_inline_query_current_chat='')]]
|
|
||||||
first_message = (
|
first_message = (
|
||||||
__("First player: {name}\n"
|
__("First player: {name}\n"
|
||||||
"Use /close to stop people from joining the game.\n"
|
"Use /close to stop people from joining the game.\n"
|
||||||
"Enable multi-translations with /enable_translations",
|
"Enable multi-translations with /enable_translations",
|
||||||
multi=game.translate)
|
game.translate)
|
||||||
.format(name=display_name(game.current_player.user)))
|
.format(name=display_name(game.current_player.user)))
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
|
@ -393,11 +249,9 @@ def start_game(bot, update, args, job_queue):
|
||||||
|
|
||||||
bot.sendMessage(chat.id,
|
bot.sendMessage(chat.id,
|
||||||
text=first_message,
|
text=first_message,
|
||||||
reply_markup=InlineKeyboardMarkup(choice),
|
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
send_first()
|
send_first()
|
||||||
start_player_countdown(bot, game, job_queue)
|
|
||||||
|
|
||||||
elif len(args) and args[0] == 'select':
|
elif len(args) and args[0] == 'select':
|
||||||
players = gm.userid_players[update.message.from_user.id]
|
players = gm.userid_players[update.message.from_user.id]
|
||||||
|
@ -419,7 +273,7 @@ def start_game(bot, update, args, job_queue):
|
||||||
reply_markup=InlineKeyboardMarkup(groups))
|
reply_markup=InlineKeyboardMarkup(groups))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
help_handler(bot, update)
|
help(bot, update)
|
||||||
|
|
||||||
|
|
||||||
@user_locale
|
@user_locale
|
||||||
|
@ -436,7 +290,7 @@ def close_game(bot, update):
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if user.id in game.owner:
|
if game.owner.id == user.id:
|
||||||
game.open = False
|
game.open = False
|
||||||
send_async(bot, chat.id, text=_("Closed the lobby. "
|
send_async(bot, chat.id, text=_("Closed the lobby. "
|
||||||
"No more players can join this game."))
|
"No more players can join this game."))
|
||||||
|
@ -444,8 +298,8 @@ def close_game(bot, update):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
text=_("Only the game creator ({name}) can do that")
|
||||||
.format(name=game.starter.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -464,15 +318,15 @@ def open_game(bot, update):
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if user.id in game.owner:
|
if game.owner.id == user.id:
|
||||||
game.open = True
|
game.open = True
|
||||||
send_async(bot, chat.id, text=_("Opened the lobby. "
|
send_async(bot, chat.id, text=_("Opened the lobby. "
|
||||||
"New players may /join the game."))
|
"New players may /join the game."))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
text=_("Only the game creator ({name}) can do that")
|
||||||
.format(name=game.starter.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -491,7 +345,7 @@ def enable_translations(bot, update):
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if user.id in game.owner:
|
if game.owner.id == user.id:
|
||||||
game.translate = True
|
game.translate = True
|
||||||
send_async(bot, chat.id, text=_("Enabled multi-translations. "
|
send_async(bot, chat.id, text=_("Enabled multi-translations. "
|
||||||
"Disable with /disable_translations"))
|
"Disable with /disable_translations"))
|
||||||
|
@ -499,8 +353,8 @@ def enable_translations(bot, update):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
text=_("Only the game creator ({name}) can do that")
|
||||||
.format(name=game.starter.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -519,7 +373,7 @@ def disable_translations(bot, update):
|
||||||
|
|
||||||
game = games[-1]
|
game = games[-1]
|
||||||
|
|
||||||
if user.id in game.owner:
|
if game.owner.id == user.id:
|
||||||
game.translate = False
|
game.translate = False
|
||||||
send_async(bot, chat.id, text=_("Disabled multi-translations. "
|
send_async(bot, chat.id, text=_("Disabled multi-translations. "
|
||||||
"Enable them again with "
|
"Enable them again with "
|
||||||
|
@ -528,8 +382,8 @@ def disable_translations(bot, update):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Only the game creator ({name}) and admin can do that.")
|
text=_("Only the game creator ({name}) can do that")
|
||||||
.format(name=game.starter.first_name),
|
.format(name=game.owner.first_name),
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -549,23 +403,52 @@ def skip_player(bot, update):
|
||||||
|
|
||||||
game = player.game
|
game = player.game
|
||||||
skipped_player = game.current_player
|
skipped_player = game.current_player
|
||||||
|
next_player = game.current_player.next
|
||||||
|
|
||||||
started = skipped_player.turn_started
|
started = skipped_player.turn_started
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
delta = (now - started).seconds
|
delta = (now - started).seconds
|
||||||
|
|
||||||
# You can't skip if the current player still has time left
|
if delta < skipped_player.waiting_time:
|
||||||
# You can skip yourself even if you have time left (you'll still draw)
|
|
||||||
if delta < skipped_player.waiting_time and player != skipped_player:
|
|
||||||
n = skipped_player.waiting_time - delta
|
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=_("Please wait {time} second",
|
text=_("Please wait {time} seconds")
|
||||||
"Please wait {time} seconds",
|
.format(time=(skipped_player.waiting_time - delta)),
|
||||||
n)
|
|
||||||
.format(time=n),
|
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
|
elif skipped_player.waiting_time > 0:
|
||||||
|
skipped_player.anti_cheat += 1
|
||||||
|
skipped_player.waiting_time -= 30
|
||||||
|
try:
|
||||||
|
skipped_player.draw()
|
||||||
|
except DeckEmptyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("Waiting time to skip this player has "
|
||||||
|
"been reduced to {time} seconds.\n"
|
||||||
|
"Next player: {name}", game.translate)
|
||||||
|
.format(time=skipped_player.waiting_time,
|
||||||
|
name=display_name(next_player.user)))
|
||||||
|
game.turn()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
do_skip(bot, player)
|
try:
|
||||||
|
gm.leave_game(skipped_player.user, chat)
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("{name1} was skipped four times in a row "
|
||||||
|
"and has been removed from the game.\n"
|
||||||
|
"Next player: {name2}", game.translate)
|
||||||
|
.format(name1=display_name(skipped_player.user),
|
||||||
|
name2=display_name(next_player.user)))
|
||||||
|
|
||||||
|
except NotEnoughPlayersError:
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("{name} was skipped four times in a row "
|
||||||
|
"and has been removed from the game.\n"
|
||||||
|
"The game ended.", game.translate)
|
||||||
|
.format(name=display_name(skipped_player.user)))
|
||||||
|
|
||||||
|
gm.end_game(chat.id, skipped_player.user)
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
|
@ -576,33 +459,24 @@ def reply_to_query(bot, update):
|
||||||
Builds the result list for inline queries and answers to the client.
|
Builds the result list for inline queries and answers to the client.
|
||||||
"""
|
"""
|
||||||
results = list()
|
results = list()
|
||||||
|
playable = list()
|
||||||
switch = None
|
switch = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = update.inline_query.from_user
|
user_id = update.inline_query.from_user.id
|
||||||
user_id = user.id
|
|
||||||
players = gm.userid_players[user_id]
|
players = gm.userid_players[user_id]
|
||||||
player = gm.userid_current[user_id]
|
player = gm.userid_current[user_id]
|
||||||
game = player.game
|
game = player.game
|
||||||
except KeyError:
|
except KeyError:
|
||||||
add_no_game(results)
|
add_no_game(results)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# The game has not started.
|
|
||||||
# The creator may change the game mode, other users just get a "game has not started" message.
|
|
||||||
if not game.started:
|
if not game.started:
|
||||||
if user_is_creator(user, game):
|
add_not_started(results)
|
||||||
add_mode_classic(results)
|
|
||||||
add_mode_fast(results)
|
|
||||||
add_mode_wild(results)
|
|
||||||
else:
|
|
||||||
add_not_started(results)
|
|
||||||
|
|
||||||
|
|
||||||
elif user_id == game.current_player.user.id:
|
elif user_id == game.current_player.user.id:
|
||||||
if game.choosing_color:
|
if game.choosing_color:
|
||||||
add_choose_color(results, game)
|
add_choose_color(results, game)
|
||||||
add_other_cards(player, results, game)
|
add_other_cards(playable, player, results, game)
|
||||||
else:
|
else:
|
||||||
if not player.drew:
|
if not player.drew:
|
||||||
add_draw(player, results)
|
add_draw(player, results)
|
||||||
|
@ -622,8 +496,6 @@ def reply_to_query(bot, update):
|
||||||
str(card) not in added_ids))
|
str(card) not in added_ids))
|
||||||
added_ids.append(str(card))
|
added_ids.append(str(card))
|
||||||
|
|
||||||
add_gameinfo(game, results)
|
|
||||||
|
|
||||||
elif user_id != game.current_player.user.id or not game.started:
|
elif user_id != game.current_player.user.id or not game.started:
|
||||||
for card in sorted(player.cards):
|
for card in sorted(player.cards):
|
||||||
add_card(game, card, results, can_play=False)
|
add_card(game, card, results, can_play=False)
|
||||||
|
@ -643,7 +515,7 @@ def reply_to_query(bot, update):
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
@user_locale
|
@user_locale
|
||||||
def process_result(bot, update, job_queue):
|
def process_result(bot, update):
|
||||||
"""
|
"""
|
||||||
Handler for chosen inline results.
|
Handler for chosen inline results.
|
||||||
Checks the players actions and acts accordingly.
|
Checks the players actions and acts accordingly.
|
||||||
|
@ -654,7 +526,7 @@ def process_result(bot, update, job_queue):
|
||||||
game = player.game
|
game = player.game
|
||||||
result_id = update.chosen_inline_result.result_id
|
result_id = update.chosen_inline_result.result_id
|
||||||
chat = game.chat
|
chat = game.chat
|
||||||
except (KeyError, AttributeError):
|
except KeyError:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("Selected result: " + result_id)
|
logger.debug("Selected result: " + result_id)
|
||||||
|
@ -665,18 +537,11 @@ def process_result(bot, update, job_queue):
|
||||||
|
|
||||||
if result_id in ('hand', 'gameinfo', 'nogame'):
|
if result_id in ('hand', 'gameinfo', 'nogame'):
|
||||||
return
|
return
|
||||||
elif result_id.startswith('mode_'):
|
|
||||||
# First 5 characters are 'mode_', the rest is the gamemode.
|
|
||||||
mode = result_id[5:]
|
|
||||||
game.set_mode(mode)
|
|
||||||
logger.info("Gamemode changed to {mode}".format(mode = mode))
|
|
||||||
send_async(bot, chat.id, text=__("Gamemode changed to {mode}".format(mode = mode)))
|
|
||||||
return
|
|
||||||
elif len(result_id) == 36: # UUID result
|
elif len(result_id) == 36: # UUID result
|
||||||
return
|
return
|
||||||
elif int(anti_cheat) != last_anti_cheat:
|
elif int(anti_cheat) != last_anti_cheat:
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Cheat attempt by {name}", multi=game.translate)
|
text=__("Cheat attempt by {name}", game.translate)
|
||||||
.format(name=display_name(player.user)))
|
.format(name=display_name(player.user)))
|
||||||
return
|
return
|
||||||
elif result_id == 'call_bluff':
|
elif result_id == 'call_bluff':
|
||||||
|
@ -693,39 +558,133 @@ def process_result(bot, update, job_queue):
|
||||||
reset_waiting_time(bot, player)
|
reset_waiting_time(bot, player)
|
||||||
do_play_card(bot, player, result_id)
|
do_play_card(bot, player, result_id)
|
||||||
|
|
||||||
if game_is_running(game):
|
if game in gm.chatid_games.get(chat.id, list()):
|
||||||
nextplayer_message = (
|
|
||||||
__("Next player: {name}", multi=game.translate)
|
|
||||||
.format(name=display_name(game.current_player.user)))
|
|
||||||
choice = [[InlineKeyboardButton(text=_("Make your choice!"), switch_inline_query_current_chat='')]]
|
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=nextplayer_message,
|
text=__("Next player: {name}", game.translate)
|
||||||
reply_markup=InlineKeyboardMarkup(choice))
|
.format(name=display_name(game.current_player.user)))
|
||||||
start_player_countdown(bot, game, job_queue)
|
|
||||||
|
|
||||||
|
|
||||||
def reset_waiting_time(bot, player):
|
def reset_waiting_time(bot, player):
|
||||||
"""Resets waiting time for a player and sends a notice to the group"""
|
"""Resets waiting time for a player and sends a notice to the group"""
|
||||||
chat = player.game.chat
|
chat = player.game.chat
|
||||||
|
|
||||||
if player.waiting_time < WAITING_TIME:
|
if player.waiting_time < 90:
|
||||||
player.waiting_time = WAITING_TIME
|
player.waiting_time = 90
|
||||||
send_async(bot, chat.id,
|
send_async(bot, chat.id,
|
||||||
text=__("Waiting time for {name} has been reset to {time} "
|
text=__("Waiting time for {name} has been reset to 90 "
|
||||||
"seconds", multi=player.game.translate)
|
"seconds", player.game.translate)
|
||||||
.format(name=display_name(player.user), time=WAITING_TIME))
|
.format(name=display_name(player.user)))
|
||||||
|
|
||||||
|
|
||||||
|
def do_play_card(bot, player, result_id):
|
||||||
|
"""Plays the selected card and sends an update to the group if needed"""
|
||||||
|
card = c.from_str(result_id)
|
||||||
|
player.play(card)
|
||||||
|
game = player.game
|
||||||
|
chat = game.chat
|
||||||
|
user = player.user
|
||||||
|
|
||||||
|
us = UserSetting.get(id=user.id)
|
||||||
|
if not us:
|
||||||
|
us = UserSetting(id=user.id)
|
||||||
|
|
||||||
|
us.cards_played += 1
|
||||||
|
|
||||||
|
if game.choosing_color:
|
||||||
|
send_async(bot, chat.id, text=_("Please choose a color"))
|
||||||
|
|
||||||
|
if len(player.cards) == 1:
|
||||||
|
send_async(bot, chat.id, text="UNO!")
|
||||||
|
|
||||||
|
if len(player.cards) == 0:
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("{name} won!", game.translate)
|
||||||
|
.format(name=user.first_name))
|
||||||
|
|
||||||
|
if us.stats:
|
||||||
|
us.games_played += 1
|
||||||
|
|
||||||
|
if game.players_won is 0:
|
||||||
|
us.first_places += 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
gm.leave_game(user, chat)
|
||||||
|
except NotEnoughPlayersError:
|
||||||
|
send_async(bot, chat.id, text=__("Game ended!", game.translate))
|
||||||
|
|
||||||
|
us2 = UserSetting.get(id=game.current_player.next.user.id)
|
||||||
|
if us2 and us2.stats:
|
||||||
|
us2.games_played += 1
|
||||||
|
|
||||||
|
gm.end_game(chat, user)
|
||||||
|
|
||||||
|
if botan:
|
||||||
|
botan.track(Message(randint(1, 1000000000), user, datetime.now(),
|
||||||
|
Chat(chat.id, 'group')),
|
||||||
|
'Played cards')
|
||||||
|
|
||||||
|
|
||||||
|
def do_draw(bot, player):
|
||||||
|
"""Does the drawing"""
|
||||||
|
game = player.game
|
||||||
|
draw_counter_before = game.draw_counter
|
||||||
|
|
||||||
|
try:
|
||||||
|
player.draw()
|
||||||
|
except DeckEmptyError:
|
||||||
|
send_async(bot, player.game.chat.id,
|
||||||
|
text=__("There are no more cards in the deck.",
|
||||||
|
game.translate))
|
||||||
|
|
||||||
|
if (game.last_card.value == c.DRAW_TWO or
|
||||||
|
game.last_card.special == c.DRAW_FOUR) and \
|
||||||
|
draw_counter_before > 0:
|
||||||
|
game.turn()
|
||||||
|
|
||||||
|
|
||||||
|
def do_call_bluff(bot, player):
|
||||||
|
"""Handles the bluff calling"""
|
||||||
|
game = player.game
|
||||||
|
chat = game.chat
|
||||||
|
|
||||||
|
if player.prev.bluffing:
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("Bluff called! Giving 4 cards to {name}",
|
||||||
|
game.translate)
|
||||||
|
.format(name=player.prev.user.first_name))
|
||||||
|
|
||||||
|
try:
|
||||||
|
player.prev.draw()
|
||||||
|
except DeckEmptyError:
|
||||||
|
send_async(bot, player.game.chat.id,
|
||||||
|
text=__("There are no more cards in the deck.",
|
||||||
|
game.translate))
|
||||||
|
|
||||||
|
else:
|
||||||
|
game.draw_counter += 2
|
||||||
|
send_async(bot, chat.id,
|
||||||
|
text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
|
||||||
|
game.translate)
|
||||||
|
.format(name1=player.prev.user.first_name,
|
||||||
|
name2=player.user.first_name))
|
||||||
|
try:
|
||||||
|
player.draw()
|
||||||
|
except DeckEmptyError:
|
||||||
|
send_async(bot, player.game.chat.id,
|
||||||
|
text=__("There are no more cards in the deck.",
|
||||||
|
game.translate))
|
||||||
|
|
||||||
|
game.turn()
|
||||||
|
|
||||||
|
|
||||||
# Add all handlers to the dispatcher and run the bot
|
# Add all handlers to the dispatcher and run the bot
|
||||||
dispatcher.add_handler(InlineQueryHandler(reply_to_query))
|
dispatcher.add_handler(InlineQueryHandler(reply_to_query))
|
||||||
dispatcher.add_handler(ChosenInlineResultHandler(process_result, pass_job_queue=True))
|
dispatcher.add_handler(ChosenInlineResultHandler(process_result))
|
||||||
dispatcher.add_handler(CallbackQueryHandler(select_game))
|
dispatcher.add_handler(CallbackQueryHandler(select_game))
|
||||||
dispatcher.add_handler(CommandHandler('start', start_game, pass_args=True, pass_job_queue=True))
|
dispatcher.add_handler(CommandHandler('start', start_game, pass_args=True))
|
||||||
dispatcher.add_handler(CommandHandler('new', new_game))
|
dispatcher.add_handler(CommandHandler('new', new_game))
|
||||||
dispatcher.add_handler(CommandHandler('kill', kill_game))
|
|
||||||
dispatcher.add_handler(CommandHandler('join', join_game))
|
dispatcher.add_handler(CommandHandler('join', join_game))
|
||||||
dispatcher.add_handler(CommandHandler('leave', leave_game))
|
dispatcher.add_handler(CommandHandler('leave', leave_game))
|
||||||
dispatcher.add_handler(CommandHandler('kick', kick_player))
|
|
||||||
dispatcher.add_handler(CommandHandler('open', open_game))
|
dispatcher.add_handler(CommandHandler('open', open_game))
|
||||||
dispatcher.add_handler(CommandHandler('close', close_game))
|
dispatcher.add_handler(CommandHandler('close', close_game))
|
||||||
dispatcher.add_handler(CommandHandler('enable_translations',
|
dispatcher.add_handler(CommandHandler('enable_translations',
|
||||||
|
@ -733,10 +692,7 @@ dispatcher.add_handler(CommandHandler('enable_translations',
|
||||||
dispatcher.add_handler(CommandHandler('disable_translations',
|
dispatcher.add_handler(CommandHandler('disable_translations',
|
||||||
disable_translations))
|
disable_translations))
|
||||||
dispatcher.add_handler(CommandHandler('skip', skip_player))
|
dispatcher.add_handler(CommandHandler('skip', skip_player))
|
||||||
dispatcher.add_handler(CommandHandler('notify_me', notify_me))
|
dispatcher.add_handler(MessageHandler([Filters.status_update], status_update))
|
||||||
simple_commands.register()
|
|
||||||
settings.register()
|
|
||||||
dispatcher.add_handler(MessageHandler(Filters.status_update, status_update))
|
|
||||||
dispatcher.add_error_handler(error)
|
dispatcher.add_error_handler(error)
|
||||||
|
|
||||||
start_bot(updater)
|
start_bot(updater)
|
||||||
|
|
15
card.py
|
@ -18,6 +18,8 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from telegram.emoji import Emoji
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
RED = 'r'
|
RED = 'r'
|
||||||
BLUE = 'b'
|
BLUE = 'b'
|
||||||
|
@ -28,10 +30,10 @@ BLACK = 'x'
|
||||||
COLORS = (RED, BLUE, GREEN, YELLOW)
|
COLORS = (RED, BLUE, GREEN, YELLOW)
|
||||||
|
|
||||||
COLOR_ICONS = {
|
COLOR_ICONS = {
|
||||||
RED: '❤️',
|
RED: Emoji.HEAVY_BLACK_HEART,
|
||||||
BLUE: '💙',
|
BLUE: Emoji.BLUE_HEART,
|
||||||
GREEN: '💚',
|
GREEN: Emoji.GREEN_HEART,
|
||||||
YELLOW: '💛',
|
YELLOW: Emoji.YELLOW_HEART,
|
||||||
BLACK: '⬛️'
|
BLACK: '⬛️'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,6 @@ SKIP = 'skip'
|
||||||
|
|
||||||
VALUES = (ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAW_TWO,
|
VALUES = (ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAW_TWO,
|
||||||
REVERSE, SKIP)
|
REVERSE, SKIP)
|
||||||
WILD_VALUES = (ONE, TWO, THREE, FOUR, FIVE, DRAW_TWO, REVERSE, SKIP)
|
|
||||||
|
|
||||||
# Special cards
|
# Special cards
|
||||||
CHOOSE = 'colorchooser'
|
CHOOSE = 'colorchooser'
|
||||||
|
@ -115,8 +116,8 @@ STICKERS = {
|
||||||
'y_reverse': 'BQADBAADQQIAAl9XmQABZdQFahGG6UQC',
|
'y_reverse': 'BQADBAADQQIAAl9XmQABZdQFahGG6UQC',
|
||||||
'draw_four': 'BQADBAAD9QEAAl9XmQABVlkSNfhn76cC',
|
'draw_four': 'BQADBAAD9QEAAl9XmQABVlkSNfhn76cC',
|
||||||
'colorchooser': 'BQADBAAD8wEAAl9XmQABl9rUOPqx4E4C',
|
'colorchooser': 'BQADBAAD8wEAAl9XmQABl9rUOPqx4E4C',
|
||||||
'option_draw': 'BQADBAAD-AIAAl9XmQABxEjEcFM-VHIC',
|
'option_draw': 'BQADBAADzAIAAl9XmQABTkPaOqA5HIMC',
|
||||||
'option_pass': 'BQADBAAD-gIAAl9XmQABcEkAAbaZ4SicAg',
|
'option_pass': 'BQADBAADzgIAAl9XmQABWSDq3RIg3c0C',
|
||||||
'option_bluff': 'BQADBAADygIAAl9XmQABJoLfB9ntI2UC',
|
'option_bluff': 'BQADBAADygIAAl9XmQABJoLfB9ntI2UC',
|
||||||
'option_info': 'BQADBAADxAIAAl9XmQABC5v3Z77VLfEC'
|
'option_info': 'BQADBAADxAIAAl9XmQABC5v3Z77VLfEC'
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,4 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import json
|
pass
|
||||||
|
|
||||||
with open("config.json","r") as f:
|
|
||||||
config = json.loads(f.read())
|
|
||||||
|
|
||||||
TOKEN=config.get("token")
|
|
||||||
WORKERS=config.get("workers", 32)
|
|
||||||
ADMIN_LIST = config.get("admin_list", None)
|
|
||||||
OPEN_LOBBY = config.get("open_lobby", True)
|
|
||||||
ENABLE_TRANSLATIONS = config.get("enable_translations", False)
|
|
||||||
DEFAULT_GAMEMODE = config.get("default_gamemode", "fast")
|
|
||||||
WAITING_TIME = config.get("waiting_time", 120)
|
|
||||||
TIME_REMOVAL_AFTER_SKIP = config.get("time_removal_after_skip", 20)
|
|
||||||
MIN_FAST_TURN_TIME = config.get("min_fast_turn_time", 15)
|
|
||||||
MIN_PLAYERS = config.get("min_players", 2)
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"token": "token_here",
|
|
||||||
"admin_list": [0],
|
|
||||||
"open_lobby": true,
|
|
||||||
"enable_translations": false,
|
|
||||||
"workers": 32,
|
|
||||||
"default_gamemode": "fast",
|
|
||||||
"waiting_time": 120,
|
|
||||||
"time_removal_after_skip": 20,
|
|
||||||
"min_fast_turn_time": 15,
|
|
||||||
"min_players": 2
|
|
||||||
}
|
|
21
credentials.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Telegram bot to play UNO in group chats
|
||||||
|
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
TOKEN = 'TOKEN'
|
||||||
|
BOTAN_TOKEN = '' # Optional: Add a botan.io token if you want bot statistics
|
|
@ -18,7 +18,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from pony.orm import Database
|
from pony.orm import Database, db_session, Optional, Required, Set, PrimaryKey
|
||||||
|
|
||||||
# Database singleton
|
# Database singleton
|
||||||
db = Database()
|
db = Database()
|
||||||
|
|
38
deck.py
|
@ -34,7 +34,18 @@ class Deck(object):
|
||||||
self.graveyard = list()
|
self.graveyard = list()
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Fill deck
|
||||||
|
for color in c.COLORS:
|
||||||
|
for value in c.VALUES:
|
||||||
|
self.cards.append(Card(color, value))
|
||||||
|
if not value == c.ZERO:
|
||||||
|
self.cards.append(Card(color, value))
|
||||||
|
|
||||||
|
for special in c.SPECIALS * 4:
|
||||||
|
self.cards.append(Card(None, None, special=special))
|
||||||
|
|
||||||
self.logger.debug(self.cards)
|
self.logger.debug(self.cards)
|
||||||
|
self.shuffle()
|
||||||
|
|
||||||
def shuffle(self):
|
def shuffle(self):
|
||||||
"""Shuffles the deck"""
|
"""Shuffles the deck"""
|
||||||
|
@ -58,31 +69,4 @@ class Deck(object):
|
||||||
|
|
||||||
def dismiss(self, card):
|
def dismiss(self, card):
|
||||||
"""Returns a card to the deck"""
|
"""Returns a card to the deck"""
|
||||||
if card.special:
|
|
||||||
card.color = None
|
|
||||||
self.graveyard.append(card)
|
self.graveyard.append(card)
|
||||||
|
|
||||||
def _fill_classic_(self):
|
|
||||||
# Fill deck with the classic card set
|
|
||||||
self.cards.clear()
|
|
||||||
for color in c.COLORS:
|
|
||||||
for value in c.VALUES:
|
|
||||||
self.cards.append(Card(color, value))
|
|
||||||
if not value == c.ZERO:
|
|
||||||
self.cards.append(Card(color, value))
|
|
||||||
for special in c.SPECIALS:
|
|
||||||
for _ in range(4):
|
|
||||||
self.cards.append(Card(None, None, special=special))
|
|
||||||
self.shuffle()
|
|
||||||
|
|
||||||
def _fill_wild_(self):
|
|
||||||
# Fill deck with a wild card set
|
|
||||||
self.cards.clear()
|
|
||||||
for color in c.COLORS:
|
|
||||||
for value in c.WILD_VALUES:
|
|
||||||
for _ in range(4):
|
|
||||||
self.cards.append(Card(color, value))
|
|
||||||
for special in c.SPECIALS:
|
|
||||||
for _ in range(6):
|
|
||||||
self.cards.append(Card(None, None, special=special))
|
|
||||||
self.shuffle()
|
|
||||||
|
|
43
game.py
|
@ -19,32 +19,31 @@
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from config import ADMIN_LIST, OPEN_LOBBY, DEFAULT_GAMEMODE, ENABLE_TRANSLATIONS
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from deck import Deck
|
from deck import Deck
|
||||||
import card as c
|
import card as c
|
||||||
|
|
||||||
|
|
||||||
class Game(object):
|
class Game(object):
|
||||||
""" This class represents a game of UNO """
|
""" This class represents a game of UNO """
|
||||||
current_player = None
|
current_player = None
|
||||||
reversed = False
|
reversed = False
|
||||||
|
draw_counter = 0
|
||||||
choosing_color = False
|
choosing_color = False
|
||||||
started = False
|
started = False
|
||||||
draw_counter = 0
|
owner = None
|
||||||
|
open = True
|
||||||
|
translate = False
|
||||||
players_won = 0
|
players_won = 0
|
||||||
starter = None
|
|
||||||
mode = DEFAULT_GAMEMODE
|
|
||||||
job = None
|
|
||||||
owner = ADMIN_LIST
|
|
||||||
open = OPEN_LOBBY
|
|
||||||
translate = ENABLE_TRANSLATIONS
|
|
||||||
|
|
||||||
def __init__(self, chat):
|
def __init__(self, chat):
|
||||||
self.chat = chat
|
self.chat = chat
|
||||||
self.last_card = None
|
self.last_card = None
|
||||||
|
|
||||||
self.deck = Deck()
|
while not self.last_card or self.last_card.special:
|
||||||
|
self.deck = Deck()
|
||||||
|
self.last_card = self.deck.draw()
|
||||||
|
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -63,18 +62,6 @@ class Game(object):
|
||||||
itplayer = itplayer.next
|
itplayer = itplayer.next
|
||||||
return players
|
return players
|
||||||
|
|
||||||
def start(self):
|
|
||||||
if self.mode == None or self.mode != "wild":
|
|
||||||
self.deck._fill_classic_()
|
|
||||||
else:
|
|
||||||
self.deck._fill_wild_()
|
|
||||||
|
|
||||||
self._first_card_()
|
|
||||||
self.started = True
|
|
||||||
|
|
||||||
def set_mode(self, mode):
|
|
||||||
self.mode = mode
|
|
||||||
|
|
||||||
def reverse(self):
|
def reverse(self):
|
||||||
"""Reverses the direction of game"""
|
"""Reverses the direction of game"""
|
||||||
self.reversed = not self.reversed
|
self.reversed = not self.reversed
|
||||||
|
@ -87,20 +74,6 @@ class Game(object):
|
||||||
self.current_player.turn_started = datetime.now()
|
self.current_player.turn_started = datetime.now()
|
||||||
self.choosing_color = False
|
self.choosing_color = False
|
||||||
|
|
||||||
def _first_card_(self):
|
|
||||||
# In case that the player did not select a game mode
|
|
||||||
if not self.deck.cards:
|
|
||||||
self.set_mode(DEFAULT_GAMEMODE)
|
|
||||||
|
|
||||||
# The first card should not be a special card
|
|
||||||
while not self.last_card or self.last_card.special:
|
|
||||||
self.last_card = self.deck.draw()
|
|
||||||
# If the card drawn was special, return it to the deck and loop again
|
|
||||||
if self.last_card.special:
|
|
||||||
self.deck.dismiss(self.last_card)
|
|
||||||
|
|
||||||
self.play_card(self.last_card)
|
|
||||||
|
|
||||||
def play_card(self, card):
|
def play_card(self, card):
|
||||||
"""
|
"""
|
||||||
Plays a card and triggers its effects.
|
Plays a card and triggers its effects.
|
||||||
|
|
|
@ -33,8 +33,6 @@ class GameManager(object):
|
||||||
self.chatid_games = dict()
|
self.chatid_games = dict()
|
||||||
self.userid_players = dict()
|
self.userid_players = dict()
|
||||||
self.userid_current = dict()
|
self.userid_current = dict()
|
||||||
self.remind_dict = dict()
|
|
||||||
|
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def new_game(self, chat):
|
def new_game(self, chat):
|
||||||
|
@ -49,11 +47,6 @@ class GameManager(object):
|
||||||
if chat_id not in self.chatid_games:
|
if chat_id not in self.chatid_games:
|
||||||
self.chatid_games[chat_id] = list()
|
self.chatid_games[chat_id] = list()
|
||||||
|
|
||||||
# remove old games
|
|
||||||
for g in list(self.chatid_games[chat_id]):
|
|
||||||
if not g.players:
|
|
||||||
self.chatid_games[chat_id].remove(g)
|
|
||||||
|
|
||||||
self.chatid_games[chat_id].append(game)
|
self.chatid_games[chat_id].append(game)
|
||||||
return game
|
return game
|
||||||
|
|
||||||
|
@ -79,22 +72,15 @@ class GameManager(object):
|
||||||
for player in players:
|
for player in players:
|
||||||
if player in game.players:
|
if player in game.players:
|
||||||
raise AlreadyJoinedError()
|
raise AlreadyJoinedError()
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
self.leave_game(user, chat)
|
self.leave_game(user, chat)
|
||||||
except NoGameInChatError:
|
except NoGameInChatError:
|
||||||
pass
|
pass
|
||||||
except NotEnoughPlayersError:
|
except NotEnoughPlayersError:
|
||||||
self.end_game(chat, user)
|
self.end_game(chat, user)
|
||||||
|
|
||||||
if user.id not in self.userid_players:
|
|
||||||
self.userid_players[user.id] = list()
|
|
||||||
|
|
||||||
players = self.userid_players[user.id]
|
|
||||||
|
|
||||||
player = Player(game, user)
|
player = Player(game, user)
|
||||||
if game.started:
|
|
||||||
player.draw_first_hand()
|
|
||||||
|
|
||||||
players.append(player)
|
players.append(player)
|
||||||
self.userid_current[user.id] = player
|
self.userid_current[user.id] = player
|
||||||
|
@ -106,16 +92,6 @@ class GameManager(object):
|
||||||
players = self.userid_players.get(user.id, list())
|
players = self.userid_players.get(user.id, list())
|
||||||
|
|
||||||
if not player:
|
if not player:
|
||||||
games = self.chatid_games[chat.id]
|
|
||||||
for g in games:
|
|
||||||
for p in g.players:
|
|
||||||
if p.user.id == user.id:
|
|
||||||
if p is g.current_player:
|
|
||||||
g.turn()
|
|
||||||
|
|
||||||
p.leave()
|
|
||||||
return
|
|
||||||
|
|
||||||
raise NoGameInChatError
|
raise NoGameInChatError
|
||||||
|
|
||||||
game = player.game
|
game = player.game
|
||||||
|
@ -154,29 +130,14 @@ class GameManager(object):
|
||||||
|
|
||||||
# Clear game
|
# Clear game
|
||||||
for player_in_game in game.players:
|
for player_in_game in game.players:
|
||||||
this_users_players = \
|
this_users_players = self.userid_players[player_in_game.user.id]
|
||||||
self.userid_players.get(player_in_game.user.id, list())
|
this_users_players.remove(player_in_game)
|
||||||
|
|
||||||
try:
|
|
||||||
this_users_players.remove(player_in_game)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if this_users_players:
|
if this_users_players:
|
||||||
try:
|
self.userid_current[player.user.id] = this_users_players[0]
|
||||||
self.userid_current[player_in_game.user.id] = this_users_players[0]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
try:
|
del self.userid_players[player_in_game.user.id]
|
||||||
del self.userid_players[player_in_game.user.id]
|
del self.userid_current[player_in_game.user.id]
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
del self.userid_current[player_in_game.user.id]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.chatid_games[chat.id].remove(game)
|
self.chatid_games[chat.id].remove(game)
|
||||||
if not self.chatid_games[chat.id]:
|
if not self.chatid_games[chat.id]:
|
||||||
|
@ -187,4 +148,5 @@ class GameManager(object):
|
||||||
for player in players:
|
for player in players:
|
||||||
if player.game.chat.id == chat.id:
|
if player.game.chat.id == chat.id:
|
||||||
return player
|
return player
|
||||||
return None
|
else:
|
||||||
|
return None
|
||||||
|
|
12
genpot.sh
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
|
|
||||||
currentVer='1.0'
|
|
||||||
|
|
||||||
xgettext *.py -o ./locales/unobot.pot --foreign-user \
|
|
||||||
--package-name="uno_bot" \
|
|
||||||
--package-version="$currentVer" \
|
|
||||||
--msgid-bugs-address='uno@jhoeke.de' \
|
|
||||||
--keyword=__ \
|
|
||||||
--keyword=_ \
|
|
||||||
--keyword=_:1,2 \
|
|
||||||
--keyword=__:1,2
|
|
Before Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 7 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 4 KiB |
Before Width: | Height: | Size: 3 KiB |
Before Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 7 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 7 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 9 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 6 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 9 KiB |
Before Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 9 KiB |
Before Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 9 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 6.7 KiB |