1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00

Carica e salva partite? Forse?

This commit is contained in:
Steffo 2016-04-10 14:04:04 +02:00
parent 48be4c8831
commit ae38a8bee3

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import telegram import telegram
import configparser
class Player: class Player:
@ -17,6 +18,9 @@ class Player:
telegram.sendmessage(text, self.telegramid) telegram.sendmessage(text, self.telegramid)
partiteincorso = list()
class Game: class Game:
groupid = int() groupid = int()
adminid = int() adminid = int()
@ -148,8 +152,24 @@ class Game:
"I Mifiosi rimasti sono più dei Royal.") "I Mifiosi rimasti sono più dei Royal.")
self.tokill = list() self.tokill = list()
def save(self):
partiteincorso = list() status = configparser.ConfigParser()
status['General'] = {
"groupid": self.groupid,
"adminid": self.adminid,
}
for player in self.players:
status[player.username] = {
"telegramid": player.username,
"role": player.role,
"alive": player.alive,
}
try:
f = open(str(self.groupid) + ".ini", "w")
except OSError:
open(str(self.groupid) + ".ini", "x")
f = open(str(self.groupid) + ".ini", "w")
status.write(f)
def findgame(chatid) -> Game: def findgame(chatid) -> Game:
@ -160,6 +180,21 @@ def findgame(chatid) -> Game:
return None return None
def loadgame(chatid) -> Game:
l = Game()
loaded = configparser.ConfigParser()
loaded.read(str(chatid) + ".ini")
# General non è un giocatore, quindi toglilo
playerlist = loaded.sections().remove("General")
for player in playerlist:
lp = Player()
lp.alive = bool(loaded[player]['alive'])
lp.username = player
lp.role = int(loaded[player]['role'])
lp.telegramid = int(loaded[player]['alive'])
partiteincorso.append(l)
while True: while True:
t = telegram.getupdates() t = telegram.getupdates()
if 'text' in t: if 'text' in t:
@ -171,6 +206,9 @@ while True:
g.adminid = t['from']['id'] g.adminid = t['from']['id']
partiteincorso.append(g) partiteincorso.append(g)
g.message("Partita creata!") g.message("Partita creata!")
elif t['text'].startswith("/loadgame"):
g = loadgame(t['chat']['id'])
g.message("Partita caricata!\n_Forse._")
elif t['text'].startswith("/status"): elif t['text'].startswith("/status"):
telegram.sendmessage("Nessuna partita in corso.", t['chat']['id'], t['message_id']) telegram.sendmessage("Nessuna partita in corso.", t['chat']['id'], t['message_id'])
else: else:
@ -251,10 +289,14 @@ while True:
g.addplayer(p) g.addplayer(p)
g.message(p.username + " si è unito alla partita!") g.message(p.username + " si è unito alla partita!")
elif t['text'].startswith("/status"): elif t['text'].startswith("/status"):
g.message(g.status())
elif t['text'].startswith("/fullstatus"):
if t['from']['id'] == g.adminid: if t['from']['id'] == g.adminid:
g.adminmessage(g.fullstatus()) g.adminmessage(g.fullstatus())
else: elif t['text'].startswith("/save"):
g.message(g.status()) if t['from']['id'] == g.adminid:
g.save()
g.message("Partita salvata!\n_Funzione instabile, speriamo che non succedano casini..._")
elif t['text'].startswith("/endday"): elif t['text'].startswith("/endday"):
if t['from']['id'] == g.adminid: if t['from']['id'] == g.adminid:
g.endday() g.endday()