Skip to content

Commit

Permalink
added invite and message on_guild_join
Browse files Browse the repository at this point in the history
  • Loading branch information
MaheshBharadwaj committed Jul 23, 2020
1 parent 49ca889 commit 803db30
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Introduction
Football bot for discord written in `python` using [discord.py](https://pypi.org/project/discord.py/) and currenty hosted on [heroku](https://heroku.com).

The API used for fetching football data is [football-data.org](https://football-data.org)'s free tier and hence we have a rate limit of **10 Requests / Min** and **12** Competitions.

# Commands
### 1. Help
Displays the commands available for usage
Expand Down Expand Up @@ -58,6 +60,16 @@ Limit restricts the number of fixtures displayed and is by default 5
<img alt="Team Fixtures image" src="https://maheshk23.imfast.io/Paneka/team-fixtures.png">
</p>

### 5. Invite
Sends the URL to invite bot into servers as a _Direct Message_

**usage:** `!invite`

<p align="center">
<img alt="Invite Command image" src="https://maheshk23.imfast.io/Paneka/invite-command.png">
</p>



# How to run locally:
- fork and clone repository
Expand All @@ -72,11 +84,11 @@ Limit restricts the number of fixtures displayed and is by default 5
- Copy the token under `Build-A-Bot`
- Store the key in `.env` as follows:<br>
`DISCORD_KEY=The Bot code`<br>
**NOTE: NO spaces around the '='**
- Get a **free** API key from [here](https://www.football-data.org/)
**NOTE:** NO _spaces_ around the `'='`
- Get a **free** football-data API key from [football-data.org](https://www.football-data.org/)
- Store this key in `.env` on a new line as:<br>
`API_KEY=The API code`<br>
**NOTE: NO spaces around the '='**
**NOTE:** NO _spaces_ around the `'='`
- `python3 bot.py` to run the bot
- Add the bot to your guild(server) by inviting it using the OAuth2 link present in the developer application window
- The bot is now ready :D
Expand All @@ -93,6 +105,7 @@ Limit restricts the number of fixtures displayed and is by default 5
| **Ligue One**<br>France | `FL1` |
| **Premier League**<br>England | `PL` |
| **Primeira Liga**<br>Porugal | `PPL` |
| **Serie A**<br>Italy | `SA` |
| **La Liga**<br>Spain| `SPA` |


Expand Down
37 changes: 30 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,33 @@
@bot.event
async def on_ready():
print("Bot Running!")
await bot.change_presence(
activity = discord.Activity(
type = discord.ActivityType.listening,
name = "commands on " + str(len(bot.guilds)) + " server(s)")
)


@bot.event
async def on_guild_join(guild):
for channel in guild.text_channels:
if channel.permissions_for(guild.me).send_messages:
helpEmbed = bot_commands.getHelpEmbed()
await channel.send('Hey There! Just got added to this channel!\
\nBasic commands are listed below :)', embed=helpEmbed)
break


@bot.command(name='99', help='Responds with a random quote from Brooklyn 99')
async def nine_nine(ctx):
brooklyn_99_quotes = [
'I\'m the human form of the 💯 emoji.',
'Bingpot!',
(
'Cool. Cool cool cool cool cool cool cool, '
'no doubt no doubt no doubt no doubt.'
),
'Cool. Cool cool cool cool cool cool cool,\
\nno doubt no doubt no doubt no doubt.',
'If I die, turn my tweets into a book',
'Captain Wuntch. Good to see you. But if you’re here, who’s guarding Hades?',
'Anyone over the age of six celebrating a birthday should go to hell.'
]

response = random.choice(brooklyn_99_quotes)
Expand Down Expand Up @@ -56,10 +72,10 @@ async def standings(ctx, arg=''):
@bot.group(name='fixtures')
async def fixtures(ctx):
if ctx.invoked_subcommand is None:
helpEmbed = bot_commands.getHelpEmbed(ctx)
helpEmbed = bot_commands.getHelpEmbed()
await ctx.send('Invalid Usage!\nLook at usage here:', embed=helpEmbed)

@fixtures.command(name='league')
@fixtures.command(name='league', aliases=['l'])
async def league(ctx, code='', limit=5):
fixturesEmbed = bot_commands.getFixtures(code, limit,mode='league')
path = fetchImage(code)
Expand All @@ -70,7 +86,7 @@ async def league(ctx, code='', limit=5):
else:
await ctx.send(embed=fixturesEmbed)

@fixtures.command(name='team')
@fixtures.command(name='team', aliases=['t'])
async def team(ctx, code='', limit=5):
fixturesEmbed = bot_commands.getFixtures(code, limit, mode='team')
await ctx.send(embed=fixturesEmbed)
Expand All @@ -87,9 +103,16 @@ async def teamCodes(ctx):
teamCodesEmbed = bot_commands.getTeamCodes()
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 you DM {ctx.author.mention}')

@bot.command(name='help')
async def help(ctx):
helpEmbed = bot_commands.getHelpEmbed(ctx)
await ctx.send(embed=helpEmbed)


bot.run(TOKEN)
37 changes: 34 additions & 3 deletions source/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,34 @@ def getTeamCodes(title="Team Codes"):
embed.add_field(name='Manche$ter City', value = 'MCFC', inline=True)
return embed

def getHelpEmbed(ctx):
def getInviteEmbed(ctx):
"""
Generates Invite embed to invite bot
Parameters:
-----------
ctx: discord.Context
Context data passed by discord when a command is invoked
Returns:
--------
discord.Embed
Showing invite URL for the bot
"""
inviteEmbed = discord.Embed(
title = 'Invite link!',
description = 'URL for inviting bot to your servers'
)

inviteEmbed.add_field(
name = ":warning: You need to be an admin to add bots :slight_smile:",
value = "https://discord.com/api/oauth2/authorize?client_id=731544990446256198&permissions=60416&scope=bot"
)

return inviteEmbed

def getHelpEmbed(ctx=None):
"""
Generates the 'Help' embed when requested
Expand All @@ -169,15 +196,19 @@ def getHelpEmbed(ctx):
"""
embed = discord.Embed(
title="Paneka-Help!",
description="Shows available commands and their functions",
description="Shows available commands and their functions\
\nNOTE: The command prefix is :exclamation:",
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 = ":four: league-codes", value = "Displays Leagues and their Respective Codes", inline=False)
embed.add_field(name = ":five: team-codes", value = "Displayes Teams and their Respective Codes", inline=False)
embed.set_footer(text='Requested By: ' + str(ctx.author))
embed.add_field(name = ":six: invite", value = "Invite bot to your servers!" ,inline=False)
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:
embed.set_footer(text='Requested By: ' + str(ctx.author))

return embed

Expand Down

0 comments on commit 803db30

Please sign in to comment.