def makeGuild(request): mandatory_keys, optional_keys = getKeys() fields = Fields(request.text, mandatory_keys, optional_keys) editFields(fields) makeHyperlinks(fields) editHeadsAndVices(fields) if not guildAlreadyExists(fields): checkGuildInfo(fields) Guild.create(**fields)
def guildAlreadyExists(guild): name = guild['name'] head = guild['head'] old_guild = Guild(name=name) if old_guild.exists: if old_guild.head == head: return True
def getGuild(text, result): result_index = text.index(result) name = text[:result_index].strip() guild = Guild(name=name) if guild.exists: return guild else: raise GB_guild_not_found
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 getGuilds(): guild_ids = database.getAll("guilds", "id") return [Guild(id=id) for id in guild_ids]
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 checkGuildName(guild_name): pattern = r"^[\[\]A-Za-z_\d ]+$" if search(pattern, guild_name) is None: raise GMError("Название гильдии содержит недопустимые символы.") elif Guild(name=guild_name).exists: raise GMError("Гильдия с таким названием уже существует.")