Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GameSearch] Add Rawg.io apikey #63

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions anisearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .anisearch import AniSearch


def setup(bot):
async def setup(bot):
n = AniSearch()
bot.add_cog(n)
await bot.add_cog(n)
4 changes: 2 additions & 2 deletions conversationgames/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .conversationgames import ConversationGames


def setup(bot):
async def setup(bot):
n = ConversationGames()
bot.add_cog(n)
await bot.add_cog(n)
4 changes: 2 additions & 2 deletions gamesearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .gamesearch import Gamesearch


def setup(bot):
async def setup(bot):
n = Gamesearch()
bot.add_cog(n)
await bot.add_cog(n)
29 changes: 27 additions & 2 deletions gamesearch/gamesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@

class Gamesearch(BaseCog):
"""Search Rawg.io for games"""


def __init__(self):
self.config = Config.get_conf(self, identifier=7535876897)
default_global = {"apikey": ""}
self.config.register_global(**default_global)

@commands.command()
@cached(ttl=86400, cache=SimpleMemoryCache)
@commands.bot_has_permissions(embed_links=True, add_reactions=True)
async def game(self, ctx, *, game):
"""Search Rawg.io for games"""

# Get API key
apikey = await self.config.apikey()

if apikey == "":
await ctx.send("No rawgkey set, please set one using [p]rawgkey")
return

url = "https://api.rawg.io/api/games?"+urlencode({
"search": game,
"key": apikey,
})

# Queries api for a game
Expand All @@ -35,7 +48,7 @@ async def game(self, ctx, *, game):
for game in results:
# Build Embed
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.rawg.io/api/games/{game['id']}") as response:
async with session.get(f"https://api.rawg.io/api/games/{game['id']}?key={apikey}") as response:
game_details = await response.json()
embed = discord.Embed()
embed.title=f"{game['name']}"
Expand All @@ -51,3 +64,15 @@ async def game(self, ctx, *, game):
embeds.append(embed)

await menu(ctx, pages=embeds, controls=DEFAULT_CONTROLS, message=None, page=0, timeout=20)

@commands.command()
@checks.is_owner()
async def rawgkey(self, ctx, *, key):
"""Set a key to use the rawg api"""

# Load config
config_boards = await self.config.apikey()

# Set new config
await self.config.apikey.set(key)
await ctx.send("The apikey has been added.")
4 changes: 2 additions & 2 deletions imdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .imdb import Imdb


def setup(bot):
async def setup(bot):
n = Imdb()
bot.add_cog(n)
await bot.add_cog(n)