Beispiel #1
0
def get_captainname_from_team(team: Team):
    if team.captain is None:
        return "No captain"
    session = session_factory()
    captain = session.query(Player).filter_by(discord_id=team.captain).one()
    session.close()
    return captain.name
Beispiel #2
0
 async def predicate(ctx: commands.Context):
     session = session_factory()
     player = find_player_by_discord_id(ctx.author.id, session)
     if player.team is not None:
         session.close()
         return True
     session.close()
     raise NotCaptainOfTeamError
Beispiel #3
0
 async def predicate(ctx: commands.Context):
     session = session_factory()
     players = session.query(Player).all()
     if ctx.author.id in [p.discord_id for p in players]:
         session.close()
         return False
     session.close()
     return True
Beispiel #4
0
 async def predicate(ctx: commands.Context):
     session = session_factory()
     players = session.query(Player).all()
     for player in players:
         if player.discord_id == ctx.author.id:
             return True
     session.close()
     raise UserNotRegisteredError
 async def invite(self, ctx: commands.Context, player_mention):
     p = ctx.message.mentions[0]
     session = session_factory()
     captain = find_player_by_discord_id(ctx.author.id, session)
     teamname = captain.team.name
     session.close()
     add_player_to_team(teamname, p)
     await ctx.send(f"{p.name} is now part of team {captain.team.name}!")
def add_user(player):
    p = Player(player.name, player.discriminator, player.id)
    session = session_factory()
    try:
        session.add(p)
        session.commit()
    except IntegrityError:
        raise UserAlreadyExistsError
    finally:
        session.close()
def add_team(teamname):
    t = Team(teamname)
    session = session_factory()
    try:
        session.add(t)
        session.commit()
    except IntegrityError:
        raise TeamAlreadyExistsError
    finally:
        session.close()
 async def kick(self, ctx: commands.Context, player_mention):
     p = ctx.message.mentions[0]
     session = session_factory()
     captain = find_player_by_discord_id(ctx.author.id, session)
     player = find_player_by_discord_id(p.id, session)
     if player in captain.team.players:
         captain.team.players.remove(player)
     else:
         raise UserNotInTeamError
     await ctx.message(f"{p.name} has been kicked from the team!")
def add_player_to_team(teamname, player):
    session = session_factory()
    p = find_player_by_discord_id(player.id, session)

    if p.team is not None:
        raise PlayerAlreadyInTeamError

    t = find_team_by_name(teamname, session)

    t.players.append(p)
    session.commit()
    session.close()
def remove_player_from_team(player):
    session = session_factory()
    p = find_player_by_discord_id(player.id, session)
    if p.team is None:
        raise UserNotInTeamError
    t = find_team_by_name(p.team.name, session)
    if p.team.captain == p.discord_id:
        p.team.captain = None
    p.team.players.remove(p)
    replace_captain_or_none(t)
    session.commit()
    session.close()
 async def logo(self, ctx: commands.Context):
     pic = ctx.message.attachments
     if len(pic) > 0 and self.allowed_format(pic):
         session = session_factory()
         t = session.query(Team).filter_by(captain=ctx.author.id)
         t.logo = pic.url
         session.commit()
         session.close()
         await ctx.send("Your logo has been uploaded")
     else:
         await ctx.send(
             "Drag and drop a picture in discord and add !logo as comment")
def promote_player_to_captain(team, player):
    session = session_factory()
    t = find_team_by_name(team, session)
    if t.captain is not None:
        raise TeamAlreadyCaptainizedError

    p = find_player_by_discord_id(player.id, session)

    if p.team is not None:
        raise PlayerAlreadyInTeamError

    t.players.append(p)
    t.captain = p.discord_id
    session.commit()
    session.close()
Beispiel #13
0
async def on_ready():
    # ###################################
    # Load commands
    print("# Loading commands")

    print("=> Miscellaneous commands")
    bot.add_cog(miscellaneous.Miscellaneous())
    print("=> Admin commands")
    bot.add_cog(admincommands.AdminCommands())
    print("=> User commands")
    bot.add_cog(usercommands.UserCommands())
    print("=> Captain commands")
    bot.add_cog(captaincommands.CaptainCommands(bot))
    print("=> Error handler")
    bot.add_cog(errorhandler.ErrorCog())
    print("Done!")
    print("\n")

    print("# Initializing database")
    session = session_factory()
    session.commit()
    session.close()
    print("Done!")
    print("\n")
def delete_user(player):
    session = session_factory()
    p = find_player_by_discord_id(player.id, session)
    session.delete(p)
    session.commit()
    session.close()
def rename_team(from_, to_):
    session = session_factory()
    t = find_team_by_name(from_, session)
    t.name = to_
    session.commit()
    session.close()
def delete_team(teamname):
    session = session_factory()
    t = find_team_by_name(teamname, session)
    session.delete(t)
    session.commit()
    session.close()