Skip to content

Commit

Permalink
[PATCH] fixtures command made easier to use
Browse files Browse the repository at this point in the history
  • Loading branch information
MaheshBharadwaj committed Oct 2, 2020
1 parent 9c5b4d6 commit c43edbd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 62 deletions.
35 changes: 7 additions & 28 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,69 +85,48 @@ async def standings(ctx, arg=''):
await ctx.send(embed=leagueCodeEmbed)


@bot.group(name='fixtures')
async def fixtures(ctx):
if ctx.invoked_subcommand is None:
helpEmbed = bot_commands.getHelpEmbed()
await ctx.send('Invalid Usage!\nLook at usage here:', embed=helpEmbed)


@fixtures.command(name='league', aliases=['l'])
async def league(ctx, code='', limit=5):
fixturesEmbed = bot_commands.getFixtures(
code.upper(), limit, mode='league')
@bot.command(name='fixtures', alias=['matches', 'm', 'f'])
async def fixtures(ctx, code = '', limit=5):
fixturesEmbed = bot_commands.getFixtures(code.upper(), limit)
fixturesEmbed.set_footer(text='Requested By: ' + str(ctx.author))

path = fetchImage(code)
path = fetchImage(code.upper())
if path is not None:
fixturesEmbed.set_thumbnail(url='attachment://image.jpg')
await ctx.send(embed=fixturesEmbed, file=discord.File(path, 'image.jpg'))
else:
await ctx.send(embed=fixturesEmbed)


@fixtures.command(name='team', aliases=['t'])
async def team(ctx, code='', limit=5):
fixturesEmbed = bot_commands.getFixtures(code.upper(), limit, mode='team')
fixturesEmbed.set_footer(text='Requested By: ' + str(ctx.author))

await ctx.send(embed=fixturesEmbed)


@bot.command(name='matches', aliases=['live', 'm'])
@bot.command(name='live', aliases=['l'])
async def matches(ctx, code='', limit=5):
liveMatchesEmbed = bot_commands.getMatches(code.upper(), limit)
liveMatchesEmbed.set_footer(text='Requested By: ' + str(ctx.author))
path = fetchImage(code)

path = fetchImage(code.upper())
if path is not None:
liveMatchesEmbed.set_thumbnail(url='attachment://image.jpg')
await ctx.send(embed=liveMatchesEmbed, file=discord.File(path, 'image.jpg'))
else:
await ctx.send(embed=liveMatchesEmbed)



@bot.command(name='league-codes')
async def leagueCodes(ctx):
leagueCodesEmbed = bot_commands.getLeagueCodes()
leagueCodesEmbed.set_footer(text='Requested By: ' + str(ctx.author))
await ctx.send(embed=leagueCodesEmbed)


@bot.command(name='team-codes')
async def teamCodes(ctx):
teamCodesEmbed = bot_commands.getTeamCodes()
teamCodesEmbed.set_footer(text='Requested By: ' + str(ctx.author))
await ctx.send(embed=teamCodesEmbed)


@bot.command(name='invite')
async def invite(ctx):
inviteEmbed = bot_commands.getInviteEmbed(ctx)
await ctx.author.send(embed=inviteEmbed)
await ctx.send(f'The invite link has been sent to your DM {ctx.author.mention} :D')


@bot.command(name='help')
async def help(ctx):
helpEmbed = bot_commands.getHelpEmbed(ctx)
Expand Down
54 changes: 25 additions & 29 deletions source/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def getStandings(code, mode='long'):
return None


def getFixtures(code, limit: int, mode):
def getFixtures(code, limit: int):
"""
Displays the fixtures in the requested league / team as an embed
Fetches fixtures from JSON file and renders embed for it,
Expand All @@ -57,9 +57,7 @@ def getFixtures(code, limit: int, mode):
The ID of the league or team for which fixtures are required
limit: int, optional
Number of fixtures to display (default value of 5)
mode: str ['league' or 'team']
Whether the fixtures of a league or a team are to be rendered
Returns:
--------
discord.Embed
Expand All @@ -71,11 +69,15 @@ def getFixtures(code, limit: int, mode):
if limit < 0:
raise InvalidLimitException

if (mode == 'league' and code not in LEAGUE_CODE):
raise InvalidLeagueCodeException

if (mode == 'team' and code not in TEAM_ID):
raise InvalidTeamCodeException
mode = 'league'
if code not in LEAGUE_CODE:
if code in TEAM_ID:
mode = 'team'
else:
return discord.Embed(title='Please enter a valid code!',
description='Please Refer to **.team-codes** for team codes\
\nAnd **.league-codes** for league-codes',
color=0xf58300)

obj = fetchJSON(code, 'fixtures')
return putFixtures(obj, code, limit, mode)
Expand All @@ -85,12 +87,6 @@ def getFixtures(code, limit: int, mode):
description="Enter a valid limit :smile:",
color=0xf58300)

except InvalidLeagueCodeException:
return getLeagueCodes("Invalid League Code!")

except InvalidTeamCodeException:
return getTeamCodes("Invalid Team Code!")


def getMatches(code, limit: int):
try:
Expand All @@ -103,8 +99,8 @@ def getMatches(code, limit: int):
mode = 'team'
else:
return discord.Embed(title='Please enter a valid code!',
description='Please Refer to `.team-codes` for team codes\
\nAnd `.league-codes` for league-codes',
description='Please Refer to **.team-codes** for team codes\
\nAnd **.league-codes** for league-codes',
color=0xf58300)

obj = fetchJSON(code, 'live')
Expand Down Expand Up @@ -236,20 +232,20 @@ def getHelpEmbed(ctx=None):
color=0xf58300)
embed.set_thumbnail(
url="https://img.icons8.com/fluent/144/000000/get-help.png")
embed.add_field(name=":one: .standings-all [league code]",
value="Detailed Standings, with team codes", inline=False)
embed.add_field(
name=":two: .standings [league code]", value="Display Standings", inline=False)
embed.add_field(
name=":three: .fixtures ['league' or 'team'] [code] [limit (default: :five: )]", value="Displays Fixtures", inline=False)
embed.add_field(name=":one: .standings-all [league code]", inline=False,\
value="Detailed Standings, with team codes")
embed.add_field(name=":two: .standings [league code]", inline=False,\
value="Display Standings")
embed.add_field(name=":three: .fixtures [league code or team code] [limit (default: :five: )]", inline=False,\
value="Displays fixtures of matches of the league or team",)
embed.add_field(name=":four: .live [league code or team code] [limit (default: :five: )]", inline=False,\
value='Display Live Matches of the league or team')
embed.add_field(name=":five: .league-codes",
value="Displays Leagues and their Respective Codes", inline=False)
embed.add_field(name=":six: .team-codes",
value="Displayes Teams and their Respective Codes", inline=False)
embed.add_field(name=":seven: .invite",
value="Invite bot to your servers!", inline=False)
embed.add_field(name=":five: .league-codes", inline=False,\
value="Displays Leagues and their Respective Codes")
embed.add_field(name=":six: .team-codes", inline=False,\
value="Displayes Teams and their Respective Codes")
embed.add_field(name=":seven: .invite", inline=False,\
value="Invite bot to your servers!")
embed.add_field(
name="\u200b", value=":computer: Link to GitHub Repository: [Click Here](https://github.com/MaheshBharadwaj/paneka)", inline=False)
if ctx is not None:
Expand Down
5 changes: 0 additions & 5 deletions source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ def putMatches(obj, code, limit, mode):
for i, match in enumerate(obj['matches']):
if i > limit - 1:
break
# matchTime = dt.datetime.strptime(
# match['utcDate'][:-1], '%Y-%m-%dt%H:%M:%S')

# # Converting to IST from UTC
# matchTime += dt.timedelta(hours=5, minutes=30)
homeTeam = match['homeTeam']['name']
awayTeam = match['awayTeam']['name']

Expand All @@ -203,7 +199,6 @@ def putMatches(obj, code, limit, mode):
awayTeamScore = match['score']['fullTime']['awayTeam']
awayTeamScore = 0 if awayTeamScore is None else awayTeamScore


status = ''
if homeTeamScore == awayTeamScore:
status = f"**Draw {homeTeamScore} - {awayTeamScore}**"
Expand Down

0 comments on commit c43edbd

Please sign in to comment.