async def accept(ctx, message: str): guild = client.get_guild(guildid) XboxwtRole = discord.utils.get(guild.roles, name="Xbox One Waiting") PS4wtRole = discord.utils.get(guild.roles, name="PS4 Waiting") XboxRole = discord.utils.get(guild.roles, name="Xbox One") PS4Role = discord.utils.get(guild.roles, name="PS4") member = discord.utils.get(guild.members, id=ctx.author.id) rolewaiting = discord.utils.get(guild.roles, name="Not Queued") PS4Waiting = discord.utils.get(guild.channels, name="ps4-manager-waiting-room") XboxWaiting = discord.utils.get(guild.channels, name="xbox-one-manager-waiting-room") if (ctx.author.id == db.getInviteUser(message)): await ctx.channel.send( "We will let the manager know and add you to the League, hang tight!" ) teamID = db.getInviteTeam(message) leagueID = db.getInviteLeague(message) leagueRole = discord.utils.get(guild.roles, id=db.getLeagueObjectID( leagueID, "Role")) leagueChat = discord.utils.get(guild.channels, id=db.getLeagueObjectID( leagueID, "Chat")) db.deleteInvite(message) db.createPlayeronTeam(ctx.author.id, leagueID, teamID) await member.add_roles(leagueRole) try: await member.remove_roles(rolewaiting) pass except: print("Failed to remove queue role") try: await member.remove_roles(XboxwtRole) pass except: print("Failed to remove xbox role") try: await member.remove_roles(PS4wtRole) pass except: print("Failed to remove ps4 role") teamname = teamname = db.getTeamName(ctx.author.id) db.deleteInvitePlayer(ctx.author.id) await leagueChat.send("Welcome <@" + str(member.id) + "> to the League, they are joining " + teamname + "!") else: await ctx.channel.send("This is not a valid invite")
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 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 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 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 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")