1
Fork 0
mirror of https://github.com/RYGhub/royal-mifia.git synced 2024-11-29 17:14:17 +00:00
This commit is contained in:
Steffo 2016-05-29 17:12:23 +02:00
parent 0c57162072
commit 24aef4af8b
3 changed files with 35 additions and 1 deletions

1
.gitignore vendored
View file

@ -112,3 +112,4 @@ $RECYCLE.BIN/
# La roba di Pycharm # La roba di Pycharm
.pyc .pyc
.idea/* .idea/*
*.p

30
main.py
View file

@ -1,5 +1,7 @@
#!/usr/bin/env python3.5 #!/usr/bin/env python3.5
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pickle
from telegram.ext import Updater, CommandHandler from telegram.ext import Updater, CommandHandler
from telegram import ParseMode from telegram import ParseMode
import filemanager import filemanager
@ -438,6 +440,15 @@ class Game:
def endgame(self): def endgame(self):
inprogress.remove(self) inprogress.remove(self)
def save(self):
# Crea il file.
file = open(str(self.groupid) + ".p", 'x')
file.close()
# Scrivi sul file.
file = open(str(self.groupid) + ".p", 'wb')
pickle.dump(self, file)
file.close()
# Partite in corso # Partite in corso
inprogress = list() inprogress = list()
@ -713,6 +724,23 @@ def fakerole(bot, update):
else: else:
bot.sendMessage(update.message.chat['id'], s.error_private_required, parse_mode=ParseMode.MARKDOWN) bot.sendMessage(update.message.chat['id'], s.error_private_required, parse_mode=ParseMode.MARKDOWN)
def load(bot, update):
"""Carica una partita salvata."""
file = open(str(update.message.chat['id']) + ".p", "rb")
game = pickle.load(file)
inprogress.append(game)
game.message(bot, s.game_loaded)
def save(bot, update):
"""Salva una partita su file."""
game = findgamebyid(update.message.chat['id'])
if game is not None:
game.save()
else:
bot.sendMessage(update.message.chat['id'], s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
updater.dispatcher.addHandler(CommandHandler('ping', ping)) updater.dispatcher.addHandler(CommandHandler('ping', ping))
updater.dispatcher.addHandler(CommandHandler('newgame', newgame)) updater.dispatcher.addHandler(CommandHandler('newgame', newgame))
updater.dispatcher.addHandler(CommandHandler('join', join)) updater.dispatcher.addHandler(CommandHandler('join', join))
@ -727,6 +755,8 @@ updater.dispatcher.addHandler(CommandHandler('debuggameslist', debuggameslist))
updater.dispatcher.addHandler(CommandHandler('kill', kill)) updater.dispatcher.addHandler(CommandHandler('kill', kill))
updater.dispatcher.addHandler(CommandHandler('config', config)) updater.dispatcher.addHandler(CommandHandler('config', config))
updater.dispatcher.addHandler(CommandHandler('fakerole', fakerole)) updater.dispatcher.addHandler(CommandHandler('fakerole', fakerole))
updater.dispatcher.addHandler(CommandHandler('save', save))
updater.dispatcher.addHandler(CommandHandler('load', load))
updater.start_polling() updater.start_polling()
print("Bot avviato!") print("Bot avviato!")
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -99,6 +99,9 @@ display_role = "Il tuo ruolo è *{icon} {role}*."
check_private = "Messaggio inviato in chat privata.\n" \ check_private = "Messaggio inviato in chat privata.\n" \
"Controlla @mifiabot." "Controlla @mifiabot."
# Generale: partita caricata
game_loaded = "Partita caricata da file."
# Vittoria: team Mifia # Vittoria: team Mifia
victory_mifia = "I Mifiosi rimasti sono più dei Royal.\n" \ victory_mifia = "I Mifiosi rimasti sono più dei Royal.\n" \
"*La Mifia vince!*" "*La Mifia vince!*"