async def makeManager(ctx, user: User): guild = client.get_guild(guildid) Team_ID = db.getTeamNumber(ctx.author.id) League_ID = db.getLeagueNumber(ctx.author.id) leagueChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Chat")) managerrole = discord.utils.get(guild.roles, name="Manager") player = user.mention.replace("<@", "").replace(">", "") print(player) #find old manage Old_Manager = discord.utils.get(guild.members, id=ctx.author.id) New_Manager = discord.utils.get(guild.members, id=int(player)) print(New_Manager) New_Manager_Team_ID = db.getTeamNumber(player) New_Manager_League_ID = db.getLeagueNumber(player) if (New_Manager_League_ID != 0): if (New_Manager_Team_ID != 0): if (New_Manager_Team_ID == Team_ID and New_Manager_League_ID == League_ID): teamname = db.getTeamName(ctx.author.id) db.updateManager(League_ID, Team_ID, New_Manager.id) await Old_Manager.remove_roles(managerrole) await New_Manager.add_roles(managerrole) await leagueChat.send(teamname + "'s manager <@" + str(Old_Manager.id) + "> has resigned and <@" + str(New_Manager.id) + "> has replaced them in the role!") else: await ctx.channel.send("This player is not in your team") else: await ctx.channel.send("This player is not in a Team") else: await ctx.channel.send("This player is not in a League")
async def invite(ctx, user: User): guild = client.get_guild(guildid) player = user.mention.replace("<@", "").replace(">", "") invitee = discord.utils.get(guild.members, id=int(player)) teamID = db.getTeamNumber(ctx.author.id) leagueID = db.getLeagueNumber(ctx.author.id) xbox_free_agent = discord.utils.get(guild.channels, name="free-agents-xbox") ps4_free_agent = discord.utils.get(guild.channels, name="free-agents-ps4") if (ctx.channel.id == xbox_free_agent.id or ctx.channel.id == ps4_free_agent.id): if (db.getInviteID(leagueID, teamID, invitee.id) == 0 and db.getLeagueNumber(invitee.id) == 0): print(invitee) print(invitee.id) #create Invite and get team name and ID teamname = db.getTeamName(ctx.author.id) db.invitePlayer(leagueID, teamID, invitee.id) inviteID = db.getInviteID(leagueID, teamID, invitee.id) try: channel1 = await ctx.author.create_dm() await channel1.send("You have invited " + invitee.name + " to join your team " + teamname) except: await ctx.channel.send( "Check your DM settings, something went wrong so we will post this here. \n" + "<@" + str(ctx.author.id) + ">" + "You have invited " + invitee.name + " to join your team " + teamname) try: channel2 = await invitee.create_dm() await channel2.send( "You have been invited to join team " + teamname + " by " + ctx.author.name + "\n Type the following to accept: \n !accept " + str(inviteID) + "\n or type the following to decline: \n !decline " + str(inviteID)) except: await ctx.channel.send( "Check your DM settings, something went wrong so we will post this here. \n" + "<@" + str(ctx.author.id) + ">" "You have been invited to join team " + teamname + " by " + ctx.author.name + "\n Type the following to accept: \n !accept " + str(inviteID) + "\n or type the following to decline: \n !decline " + str(inviteID)) else: await ctx.channel.send( "This player has already been invited or are already in a League!" ) else: await ctx.channel.send( "This command can only be used in the free agents channels")
async def declineScore(ctx, ID: int): guild = client.get_guild(guildid) teamID = db.getTeamNumber(ctx.author.id) League_ID = db.getLeagueNumber(ctx.author.id) LeagueInfo = db.getTeamNames(League_ID)[0] scoreChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Scores")) score = db.getScore(ID) Team_1 = score[3] Team_2 = score[4] score_1 = score[5] score_2 = score[6] Fixture_Pos = score[2] if (teamID == Team_1 or teamID == Team_2): await ctx.channel.send("Thank you, we will let the League know") db.deleteScore(League_ID, Fixture_Pos) scoreMessage = str(Fixture_Pos) + ": **" + str( score_1) + "**" + " " + str( LeagueInfo[Team_1 + 1]) + " vs " + str( LeagueInfo[Team_2 + 1]) + " " + "**" + str(score_2) + "**" await scoreChat.send("The following score has been **declined** by " + ctx.author.name + ":\n" + scoreMessage) else: await ctx.channel.send("Invalid Submission ID")
async def acceptScore(ctx, ID: int): guild = client.get_guild(guildid) teamID = db.getTeamNumber(ctx.author.id) League_ID = db.getLeagueNumber(ctx.author.id) manager = db.getManager(League_ID, teamID) scoreChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Scores")) score = db.getScore(ID) if (ctx.author.id == manager): if (teamID == Team_1 or teamID == Team_2): Team_1 = score[3] Team_2 = score[4] LeagueInfo = db.getTeamNames(League_ID)[0] score_1 = score[5] score_2 = score[6] Fixture_Pos = score[2] db.addFixtureScore(League_ID, Fixture_Pos, score_1, score_2) db.deleteScore(League_ID, Fixture_Pos) await ctx.channel.send("We will add this to the fixtures now!") scoreMessage = str(Fixture_Pos) + ": **" + str( score_1) + "**" + " " + str( LeagueInfo[Team_1 + 1]) + " vs " + str( LeagueInfo[Team_2 + 1]) + " " + "**" + str(score_2) + "**" await scoreChat.send( "The following score has been **accepted** by both managers:\n" + scoreMessage) else: await ctx.channel.send("Invalid Submission ID") else: await ctx.channel.send("You are not a manager!")
async def fixture(ctx, fixturenumber: int): League_ID = db.getLeagueNumber(ctx.author.id) FixtureChat_ID = db.getLeagueObjectID(League_ID, "Fixtures") if (ctx.channel.id == FixtureChat_ID): fixture = db.getFixture(League_ID, fixturenumber) teamnames = db.getTeamNames(League_ID)[0] message = "Here is Fixture " + str(fixturenumber) + ":\n" for match in fixture: if match[5] is None: message = message + str(match[2]) + ": " + str( teamnames[match[3] + 1]) + " vs " + str( teamnames[match[4] + 1]) + " - Due - " + str( match[7])[0:19] + "\n" else: message = message + str(match[2]) + ": **" + str( match[5]) + "**" + " " + str( teamnames[match[3] + 1]) + " vs " + str( teamnames[match[4] + 1]) + " " + "**" + str( match[6]) + "**" + " - Due - " + str( match[7])[0:19] + "\n" await ctx.channel.send(message) else: await ctx.channel.send( "This command must be run in the Fixtures chat of your League")
async def submitScore(ctx, Fixture_Pos: int, homescore: int, awayscore: int): print("Submit Score") guild = client.get_guild(guildid) teamID = db.getTeamNumber(ctx.author.id) League_ID = db.getLeagueNumber(ctx.author.id) LeagueInfo = db.getTeamNames(League_ID)[0] match = db.getMatch(League_ID, Fixture_Pos)[0] #check if home if (teamID == match[3]): print("Im home") db.submitScore(League_ID, Fixture_Pos, homescore, awayscore) awayTeam = match[4] awayManager = LeagueInfo[6 + awayTeam] awayDiscord = discord.utils.get(guild.members, id=int(awayManager)) channel1 = await ctx.author.create_dm() channel2 = await awayDiscord.create_dm() scoreMessage = str(Fixture_Pos) + ": **" + str( homescore) + "**" + " " + str( LeagueInfo[teamID + 1]) + " vs " + str( LeagueInfo[awayTeam + 1]) + " " + "**" + str(awayscore) + "**" subID = db.getScoreSubmitID(League_ID, Fixture_Pos) await channel1.send("You have submitted a score of:\n" + scoreMessage) channel2message = ctx.author.name + " of the team " + str( LeagueInfo[teamID + 1] ) + " has submitted the score:\n" + scoreMessage + "\nIf you would like to accept type !acceptScore " + str( subID ) + "\nIf you would like to decline type !declineScore " + str(subID) await channel2.send(channel2message) #check if away elif (teamID == match[4]): print("Im away") db.submitScore(League_ID, Fixture_Pos, awayscore, homescore) awayTeam = match[3] awayManager = LeagueInfo[6 + awayTeam] awayDiscord = discord.utils.get(guild.members, id=int(awayManager)) channel1 = await ctx.author.create_dm() channel2 = await awayDiscord.create_dm() scoreMessage = str(Fixture_Pos) + ": **" + str( awayscore) + "**" + " " + str( LeagueInfo[awayTeam + 1]) + " vs " + str( LeagueInfo[teamID + 1]) + " " + "**" + str(homescore) + "**" subID = db.getScoreSubmitID(League_ID, Fixture_Pos) await channel1.send("You have submitted a score of:\n" + scoreMessage) channel2message = ctx.author.name + " of the team " + str( LeagueInfo[teamID + 1] ) + " has submitted the score:\n" + scoreMessage + "\nIf you would like to accept type !acceptScore " + str( subID ) + "\nIf you would like to decline type !declineScore " + str(subID) await channel2.send(channel2message) #neither else: await ctx.channel.send("This wasn't your match!")
async def on_member_remove(member): guild = client.get_guild(guildid) League_ID = db.getLeagueNumber(member.id) if (League_ID != 0): leagueChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID( League_ID, "Chat")) await leagueChat.send( str(member.name) + " has left the League, if they where a manager please contact staff and open a ticket under tech support." ) db.deletePlayer(member.id)
async def kick(ctx, user: User): guild = client.get_guild(guildid) Team_ID = db.getTeamNumber(ctx.author.id) League_ID = db.getLeagueNumber(ctx.author.id) leagueChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Chat")) player = user.mention.replace("<@", "").replace(">", "") print(player) Old_Manager = discord.utils.get(guild.members, id=ctx.author.id) New_Manager = discord.utils.get(guild.members, id=int(player)) print(New_Manager) New_Manager_Team_ID = db.getTeamNumber(player) New_Manager_League_ID = db.getLeagueNumber(player) if (New_Manager_League_ID != 0): if (New_Manager_Team_ID != 0): if (New_Manager_Team_ID == Team_ID and New_Manager_League_ID == League_ID): teamname = db.getTeamName(ctx.author.id) leagueRole = discord.utils.get(guild.roles, id=db.getLeagueObjectID( League_ID, "Role")) await New_Manager.remove_roles(leagueRole) db.deletePlayer(New_Manager.id) await leagueChat.send( "<@" + str(New_Manager.id) + ">'s contract has been terminated from " + teamname + "!") DMNotice = await New_Manager.create_dm() await DMNotice.send( "Sorry to inform you but your contract for the team " + teamname + " has been terminated!") else: await ctx.channel.send("This player is not in your team") else: await ctx.channel.send("This player is not in a Team") else: await ctx.channel.send("This player is not in a League")
async def squad(ctx, *, message: str): League_ID = db.getLeagueNumber(ctx.author.id) TeamChat_ID = db.getLeagueObjectID(League_ID, "Team") if (ctx.channel.id == TeamChat_ID): team = db.getTeamMembers(League_ID, message) cmessage = "Here are the squad members of " + message + ":\n" for player in team: newplayer = str(player) newplayer = newplayer.replace("(", "").replace(")", "").replace(",", "") cmessage = cmessage + "<@" + str(newplayer) + ">\n" await ctx.channel.send(cmessage) else: await ctx.channel.send( "This command must be run in the Team chat of your League")
async def leaveLeague(ctx): guild = client.get_guild(guildid) League_ID = db.getLeagueNumber(ctx.author.id) Team_ID = db.getTeamNumber(ctx.author.id) leagueRole = discord.utils.get(guild.roles, id=db.getLeagueObjectID(League_ID, "Role")) if (League_ID != 0): manager = db.getManager(League_ID, Team_ID) if (ctx.author.id == manager): await ctx.channel.send( "You are a manager so you cannot leave the league until you transfer ownership." ) else: Member = discord.utils.get(guild.members, id=int(ctx.author.id)) await Member.remove_roles(leagueRole) db.deletePlayer(ctx.author.id) else: await ctx.channel.send("You are not part of a League!")
async def table(ctx): guild = client.get_guild(guildid) League_ID = db.getLeagueNumber(ctx.author.id) leagueChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Chat")) scores = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Scores")) fixtures = discord.utils.get(guild.channels, id=db.getLeagueObjectID( League_ID, "Fixtures")) team = discord.utils.get(guild.channels, id=db.getLeagueObjectID(League_ID, "Team")) if (ctx.channel.id == leagueChat.id or ctx.channel.id == scores.id or ctx.channel.id == fixtures.id or ctx.channel.id == team.id): fixturetable = "```yaml\n" + db.calculateTable(League_ID) + "\n```" await ctx.channel.send(fixturetable) else: await ctx.channel.send( "This command can only be used within your League!")
async def teams(ctx): League_ID = db.getLeagueNumber(ctx.author.id) TeamChat_ID = db.getLeagueObjectID(League_ID, "Team") if (ctx.channel.id == TeamChat_ID): Teams = db.getTeamNames(League_ID) print(Teams[0][0]) print(Teams) message = "These are the teams of the League:\n" message = message + Teams[0][2] + " - Managed by <@" + str( Teams[0][7]) + ">\n" message = message + Teams[0][3] + " - Managed by <@" + str( Teams[0][8]) + ">\n" message = message + Teams[0][4] + " - Managed by <@" + str( Teams[0][9]) + ">\n" message = message + Teams[0][5] + " - Managed by <@" + str( Teams[0][10]) + ">\n" message = message + Teams[0][6] + " - Managed by <@" + str( Teams[0][11]) + ">\n" await ctx.channel.send(message) else: await ctx.channel.send( "This command must be run in the Team chat of your League")