def check_name(name): if len(name) > 32: raise ctf_model.TaskFailed("Challenge name is too long!") if not re.match(r"[-._!0-9A-Za-z æøåÆØÅ]+$", name): raise ctf_model.TaskFailed("Challenge contains invalid characters!") # Replace spaces with a dash with a configured delimiter return re.sub(r" +", config["challenge_name_delimiter"], name).lower()
def check_name(name): if len(name) > 32: raise ctf_model.TaskFailed("Challenge name is too long!") if not re.match(r"[-._!0-9A-Za-z æøåÆØÅ]+$", name): raise ctf_model.TaskFailed("Challenge contains invalid characters!") # Replace spaces with a dash, because discord does it :/ return re.sub(r" +", "-", name).lower()
def chk_fetch_team_by_name(ctx, name): channels = ctx.guild.channels if len([channel.id for channel in channels if name == channel.name]) > 1: raise ctf_model.TaskFailed("Multiple channels with same name exists") found_channel_id = "" for channel in channels: if channel.name == name: found_channel_id = channel.id team = ctf_model.CtfTeam.fetch(ctx.channel.guild, found_channel_id) if not team: raise ctf_model.TaskFailed("Failed to join CTF") return team
async def parse_user(guild, user): print('parsinig user:'******'Invalid username: `{user}`, use @username') return ret
async def country(self, ctx, country): table, country_name = country_scores(country.upper()) if not table: raise ctf_model.TaskFailed( "Invalid year or country code. Should be `YYYY` or `XX`.") out = f":flag_{country.lower()}: **Top teams for {country_name}**" out += "```glsl\n" out += format_table(table) cut = 0 suffix = "\n```" while len(out) > 2000 - len(suffix): out = "\n".join(out.split("\n")[:-1]) cut += 1 suffix = f"\n\n+{cut} more teams\n```" out += suffix await ctx.send(out)
def chk_fetch_chal(ctx): chal = ctf_model.Challenge.fetch(ctx.channel.guild, ctx.channel.id) if not chal: raise ctf_model.TaskFailed( "Please type this command in a challenge channel.") return chal
def chk_fetch_team(ctx): team = ctf_model.CtfTeam.fetch(ctx.channel.guild, ctx.channel.id) if not team: raise ctf_model.TaskFailed( "Please type this command in the main channel of a CTF.") return team