1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +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 -*-
import telegram
import configparser
class Player:
@ -17,6 +18,9 @@ class Player:
telegram.sendmessage(text, self.telegramid)
partiteincorso = list()
class Game:
groupid = int()
adminid = int()
@ -148,8 +152,24 @@ class Game:
"I Mifiosi rimasti sono più dei Royal.")
self.tokill = list()
partiteincorso = list()
def save(self):
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:
@ -160,6 +180,21 @@ def findgame(chatid) -> Game:
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:
t = telegram.getupdates()
if 'text' in t:
@ -171,6 +206,9 @@ while True:
g.adminid = t['from']['id']
partiteincorso.append(g)
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"):
telegram.sendmessage("Nessuna partita in corso.", t['chat']['id'], t['message_id'])
else:
@ -251,10 +289,14 @@ while True:
g.addplayer(p)
g.message(p.username + " si è unito alla partita!")
elif t['text'].startswith("/status"):
g.message(g.status())
elif t['text'].startswith("/fullstatus"):
if t['from']['id'] == g.adminid:
g.adminmessage(g.fullstatus())
else:
g.message(g.status())
elif t['text'].startswith("/save"):
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"):
if t['from']['id'] == g.adminid:
g.endday()