-
Notifications
You must be signed in to change notification settings - Fork 1
/
pottermore.py
183 lines (168 loc) · 7.97 KB
/
pottermore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import contextlib
from cogs.utils.test import menu, DEFAULT_CONTROLS
from typing import Literal
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import aiohttp
import random
slytherin = "https://cdn.shopify.com/s/files/1/1325/3287/products/HP8040B_930f8033-607f-41ee-a8e4-fa90871ce7a7.png?v=1546231154"
gryffindor = "https://cdn10.bigcommerce.com/s-9p3fydit/products/370/images/1328/gryff1c__34591.1449620321.1280.1280.PNG?c=2"
ravenclaw = "https://cdn10.bigcommerce.com/s-9p3fydit/products/372/images/1332/raven1c__54237.1449620971.1200.1200.PNG?c=2"
hufflepuff = "https://cdn.shopify.com/s/files/1/0221/1146/products/Hufflepuff_Embroidered_Patch_Scaled_large.png?v=1553528874"
harry = "https://www.freepngimg.com/thumb/harry_potter/5-2-harry-potter-png-file.png"
hermione = "https://66.media.tumblr.com/3ce8453be755f31f93381918985b4918/tumblr_nn2lopIypj1rxkqbso1_1280.png"
voldemort = "https://vignette.wikia.nocookie.net/harrypotter/images/6/6e/VoldemortHeadshot_DHP1.png"
snape = "https://vignette.wikia.nocookie.net/harrypotter/images/a/a3/Severus_Snape.jpg"
draco = (
"https://vignette.wikia.nocookie.net/harrypotter/images/7/7e/Draco_Malfoy_TDH.png"
)
dumbledore = "https://images.ctfassets.net/bxd3o8b291gf/5ocauY6zAsqGiIgeECw06e/8accc1c586d2be7d9de6a3d9aec37b90/AlbusDumbledore_WB_F1_DumbledoreSmiling_Still_080615_Port.jpg"
ron = "https://upload.wikimedia.org/wikipedia/en/thumb/5/5e/Ron_Weasley_poster.jpg/220px-Ron_Weasley_poster.jpg"
hagrid = "https://vignette.wikia.nocookie.net/harrypotter/images/e/ee/Rubeushagrid.PNG/revision/latest?cb=20161123044204"
ginny = "http://hp-intothefire.wdfiles.com/local--files/ginny/ginny.jpg"
sirius = "https://vignette.wikia.nocookie.net/harrypotter/images/7/75/Sirius_Black_profile.jpg/revision/latest?cb=20150918055024"
mcgonagall = "https://vignette.wikia.nocookie.net/harrypotter/images/6/65/ProfessorMcGonagall-HBP.jpg/revision/latest?cb=20100612114856"
class Pottermore(commands.Cog):
"""Lookup information about the Harry Potter Universe"""
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(loop=self.bot.loop)
@commands.bot_has_permissions(embed_links=True)
@commands.command()
async def housesort(self, ctx):
"""Find your Harry Potter House"""
async with self.session.get("https://www.potterapi.com/v1/sortinghat") as r:
data = await r.json()
house = data
color = "PINK"
if house == "Slytherin":
image = slytherin
embed = discord.Embed(
title="Find your Harry Potter House", description=house, color=color
)
embed.set_thumbnail(url=image)
if house == "Gryffindor":
image = gryffindor
embed = discord.Embed(
title="Find your Harry Potter House", description=house, color=color
)
embed.set_thumbnail(url=image)
if house == "Ravenclaw":
image = ravenclaw
embed = discord.Embed(
title="Find your Harry Potter House", description=house, color=color
)
embed.set_thumbnail(url=image)
if house == "Hufflepuff":
image = hufflepuff
embed = discord.Embed(
title="Find your Harry Potter House", description=house, color=color
)
embed.set_thumbnail(url=image)
await ctx.send(embed=embed)
@staticmethod
async def do_lookup(query: str) -> list:
"""Run pottermore lookup pic lookup"""
base_url = "https://www.potterapi.com/v1/characters/?key=$2a$10$ZiItg0fhdYll4R2A4hNareLdTmuYByHnzL9mSqw3r7Mkh/nMh2WUa&name=%s"
async with aiohttp.ClientSession() as session:
async with session.get(base_url % query) as r:
data = await r.json()
if not data or isinstance(data, dict):
return None
return data[0]
def escape_query(self, query) -> str:
"""Escape mentions from queries"""
return query.replace("`", "'")
@commands.bot_has_permissions(embed_links=True)
@commands.command()
async def charactersearch(self, ctx, *, query):
"""
Search for Harry Potter characters
Note: Searchs are case senseative and require full name
"""
async with ctx.typing():
query = self.escape_query("".join(query))
pottermore_data = await self.do_lookup(query)
if not pottermore_data:
await ctx.send("🔮 Muggle error! Could not find `%s`" % query)
return
if "alias" in pottermore_data:
alias = pottermore_data["alias"]
else:
alias = ""
embed = discord.Embed(
title=pottermore_data["name"],
description=alias,
color=await ctx.embed_color(),
)
name = pottermore_data["name"]
if name == "Harry Potter":
embed.set_thumbnail(url=harry)
if name == "Hermione Granger":
embed.set_thumbnail(url=hermione)
if name == "Lord Voldemort":
embed.set_thumbnail(url=voldemort)
if name == "Severus Snape":
embed.set_thumbnail(url=snape)
if name == "Albus Dumbledore":
embed.set_thumbnail(url=dumbledore)
if name == "Draco Malfoy":
embed.set_thumbnail(url=draco)
if name == "Ron Weasley":
embed.set_thumbnail(url=ron)
if name == "Rubeus Hagrid":
embed.set_thumbnail(url=hagrid)
if name == "Ginny Weasley":
embed.set_thumbnail(url=ginny)
if name == "Sirius Black":
embed.set_thumbnail(url=sirius)
if name == "Minerva McGonagall":
embed.set_thumbnail(url=mcgonagall)
if "house" in pottermore_data:
embed.add_field(name="House", value=pottermore_data["house"], inline=True)
if "school" in pottermore_data:
embed.add_field(
name="School Name", value=pottermore_data["school"], inline=True
)
if "role" in pottermore_data:
embed.add_field(name="Role", value=pottermore_data["role"], inline=True)
if "wand" in pottermore_data:
embed.add_field(name="Wand", value=pottermore_data["wand"], inline=True)
if "boggart" in pottermore_data:
embed.add_field(
name="Boggart", value=pottermore_data["boggart"], inline=True
)
if "patronus" in pottermore_data:
embed.add_field(
name="Patronus", value=pottermore_data["patronus"], inline=True
)
if pottermore_data["ministryOfMagic"] == False:
embed.add_field(name="Ministry of Magic", value="Not a member", inline=True)
else:
embed.add_field(name="Ministry of Magic", value="Member", inline=True)
if pottermore_data["orderOfThePhoenix"] == False:
embed.add_field(
name="Order Of The Phoenix", value="Not a member", inline=True
)
else:
embed.add_field(name="Order Of The Phoenix", value="Member", inline=True)
if pottermore_data["dumbledoresArmy"] == False:
embed.add_field(name="Dumbledores Army", value="Not a member", inline=True)
else:
embed.add_field(name="Dumbledores Army", value="Member", inline=True)
if pottermore_data["deathEater"] == False:
embed.add_field(name="DeathEater", value="No", inline=True)
else:
embed.add_field(name="DeathEater", value="Yes", inline=True)
embed.add_field(
name="Blood Status", value=pottermore_data["bloodStatus"], inline=True
)
embed.add_field(name="Species", value=pottermore_data["species"], inline=True)
if "animagus" in pottermore_data:
embed.add_field(
name="Animagus", value=pottermore_data["animagus"], inline=True
)
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Pottermore(bot))