def changeNick(request): "Прошу сменить мой никнейм на ..." name = getNickname(request.text) checkIfPlayerExists(name=name) if request.asker.exists: request.asker.set("name", name) else: Player.create(id=request.asker.id, name=name)
def changeId(request): "Прошу сменить мою ссылку на ..." hyperlink = Hyperlink(request.text) checkIfPlayerExists(id=hyperlink.id) if request.asker.exists: request.asker.set("id", hyperlink.id) else: checkIfPlayerIsTheAsker(hyperlink.name, request.asker) Player.create(id=hyperlink.id, name=hyperlink.name)
def getPlayersFromComment(comment): comment = comment.split(" ") player1 = Player(name=comment[0]) if len(comment) > 2: player2 = Player(name=comment[1]) player1.score = eval(comment[2]) return player1, player2 else: player1.score = eval(comment[1]) return [player1]
def checkIfPlayerExists(id=None, name=None): player = Player(id, name) if player.exists: if id is not None: raise player_already_exists elif name is not None: raise nickname_already_exists
def __init__(self, post_text, post_owner, comment_id, topic): self.id = comment_id self.topic = topic self.text = post_text logger.debug("Getting asker ({}) information...".format(post_owner)) self.asker = Player(id=post_owner) self.action = self.topic.getAction(self.text.lower()) self.guilds_to_update = [] logger.debug("Recieved request '{}'".format(post_text))
def handleGuildCommand(request): command = request.guild_command if command == "exclude": player = Player(request.id) guild = player.guild excludeFromGuild(player) elif command == "setrank": guild = player.guild guild.setPosition(request.id, request.rank) elif command == "endguild": guild = Guild(request.id) endGuild(guild) refreshGuilds() database.save() updateGuild(guild.id)
def addToGuild(request): "Прошу зачислить игрока ..." checkRights(request.asker, "vice") guild_id = request.asker.guild_id hyperlink = Hyperlink(request.text) id_, name = hyperlink.id, hyperlink.name player = Player(id=id_) if id_ in ban_list: raise user_banned elif player.inguild: raise already_in_guild if player.exists: player.set("guild_id", guild_id) else: checkIfPlayerExists(name=name) Player.create(id=id_, name=name, guild_id=guild_id)
def check_excludeFromGuild(request): "Прошу исключить игрока ..." if not request.asker.inguild: raise not_in_guild asker = request.asker guild = asker.guild request.guilds_to_update.append(guild) if "меня" in request.text: if asker.rank == Rank.head and len(guild.heads) == 1: raise head_must_present excludeFromGuild(request.asker) return player = Player(Hyperlink(request.text).id) if player.guild_id != asker.guild_id: raise not_in_guild elif asker.rank <= player.rank: if player.rank == Rank.vice: raise need_head_rights elif player.rank == Rank.player: raise need_vice_rights elif player.rank == Rank.head: raise head_cant_leave excludeFromGuild(player)
def changeStatus(request): "Прошу сменить статус ... на главу, заместителя, игрока" asker = request.asker guild = asker.guild heads, vices = guild.heads, guild.vices status = getRequestedStatus(request.text) hyperlink = Hyperlink(request.text) player = Player(hyperlink.id) if not player.exists or player.guild_id != asker.guild_id: raise not_in_guild elif not asker.inguild or not player.inguild: raise not_in_guild if "глав" in status: checkRights(asker, "head") if len(heads) == 2: raise too_many_heads else: guild.setPosition(player.id, "head") elif "зам" in status: checkRights(asker, "head") if len(vices) == 4: raise too_many_vices elif asker.id == player.id and len(heads) == 1: raise head_must_present elif asker.id != player.id and player.rank == Rank.head: raise head_cant_leave else: guild.setPosition(player.id, "vice") elif "игрок" in status: if asker.id == player.id and asker.rank == Rank.head and len(heads) == 1: raise head_must_present elif asker.id != player.id and asker.rank != Rank.head: raise need_head_rights elif asker.id != player.id and player.rank == Rank.head: raise head_cant_leave else: guild.setPosition(player.id, "player")
def editFields(fields): players = fields['участники'].split(" ") fields['участники'] = [Player(id=p) for p in players] fields['волны'] = int(fields['волны']) fields['гильдия'] = Guild(name=fields['гильдия']) fields['испытание'] = Achi(name=fields['испытание'])
def checkIfPlayerIsTheAsker(playerName, asker): player = Player(name=playerName) if (player.exists and player.id != asker.id): raise player_already_exists
def removePlayersFromGuild(guild_id): players = [Player(id=id) for id in database.getAll("players", "id")] for player in players: if player.guild_id == guild_id: player.set("guild_id", 0)
def checkPlayerUniqueness(player): old_player = Player(name=player.name) if old_player.exists and old_player.id != player.id: raise GMError("Игрок с ником {} уже [id{}|существует]".format( player.name, old_player.id))
def getResponse(request): player = Player(id=request.asker.id) guild_name, page_id = player.guild.name, player.guild.page link = "https://vk.com/page-{}_{}".format(group_id, page_id) return "Гильдия: {} ({})".format(guild_name, link)
def checkIfPlayerHasGuild(hyperlink): player = Player(id=hyperlink.id) if player.rank > 0: raise GMError("{} уже состоит в гильдии {}".format( hyperlink, player.guild.name))