Skip to content

Commit 3a581de

Browse files
committed
added support for shiny gifs
1 parent e7fbf13 commit 3a581de

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

Diff for: globals.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ class Globals():
33
COLOR = 0xe74c3c #color for embed (red)
44

55
IMG_URL = 'https://veekun.com/dex/media/pokemon/main-sprites/x-y/'
6+
S_IMG_URL = 'https://veekun.com/dex/media/pokemon/main-sprites/x-y/shiny/'
67
# GIF_URL = 'http://www.pkparaiso.com/imagenes/xy/sprites/animados/'
78
GIF_URL = 'http://www.pokestadium.com/sprites/xy/'
9+
S_GIF_URL = 'http://www.pokestadium.com/sprites/xy/shiny/'
810
DEX_URL = 'http://cdn.bulbagarden.net/upload/thumb/3/36/479Rotom-Pok%C3%A9dex.png/160px-479Rotom-Pok%C3%A9dex.png'
911

1012

Diff for: pokedex.py

+33-12
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ async def dex(self, ctx, *args):
3030
from pokedex import Pokedex as this
3131
pkmn_id = 0; pkmn_name = ''; pkmn_genus = ''; pkmn_url = ''; pkmn_desc = '';
3232
random_args = ['-r', '-rand', '-random']
33-
papi = PokeAPI()
33+
shiny = False
34+
3435
if not self.lock:
35-
#pokemon number given
36+
papi = PokeAPI()
3637
if args and len(args) >= 1:
3738
t = args[0]
3839
if type(t) == str and t.startswith('-'):
3940
if t in random_args:
4041
p = pkmn()
4142
p.initialize()
4243
t = p.pkmn_id
44+
if '-s' in args[1:] or '-shiny' in args[1:]:
45+
shiny = True
4346
if type(t) == int or type(t) == str:
4447
self.lock = True
4548
if type(t) == str:
@@ -67,16 +70,17 @@ async def dex(self, ctx, *args):
6770
pkmn_type = {i['type']['name'] for i in pt}
6871
print("Displaying Pokemon {0} #{1}".format(pkmn_name, pkmn_id))
6972

70-
if '-s' not in args[1:] and '-shiny' not in args[1:]:
71-
try:
72-
s = str(pkmn_name)
73-
trans = str.maketrans('', '', punctuation)
74-
filename = ''.join((g.GIF_URL, s.translate(trans), '.gif'))
75-
a = urlopen(filename)
76-
except HTTPError:
77-
filename = ''.join((g.IMG_URL, str(pkmn_id), '.png'))
78-
else: filename = ''.join((g.IMG_URL, 'shiny/' ,str(pkmn_id), '.png'))
79-
73+
# if '-s' not in args[1:] and '-shiny' not in args[1:]:
74+
# try:
75+
# s = str(pkmn_name)
76+
# trans = str.maketrans('', '', punctuation)
77+
# filename = ''.join((g.GIF_URL, s.translate(trans), '.gif'))
78+
# a = urlopen(filename)
79+
# except HTTPError:
80+
# filename = ''.join((g.IMG_URL, str(pkmn_id), '.png'))
81+
# else: filename = ''.join((g.IMG_URL, 'shiny/' ,str(pkmn_id), '.png'))
82+
83+
filename = self.get_thumbnail(pkmn_id, pkmn_name, shiny=shiny)
8084
type_emojis = ' '.join({g.TYPE_DICT[t] for t in pkmn_type if t in g.TYPE_DICT})
8185
title = "{0} #{1} {2}".format(pkmn_name.capitalize(), pkmn_id, type_emojis)
8286
sub_title = "the {0} Pokémon".format(pkmn_genus)
@@ -97,6 +101,23 @@ async def dex(self, ctx, *args):
97101
print("The dex is currently in use")
98102
return
99103

104+
@staticmethod
105+
def get_thumbnail(id, name, shiny=False):
106+
filename = ''
107+
try:
108+
s = str(name)
109+
trans = str.maketrans('', '', punctuation)
110+
if not shiny:
111+
filename = ''.join((g.GIF_URL, s.translate(trans), '.gif'))
112+
else: filename = ''.join((g.S_GIF_URL, s.translate(trans), '.gif'))
113+
a = urlopen(filename)
114+
except HTTPError:
115+
if not shiny:
116+
filename = ''.join((g.IMG_URL, str(id), '.png'))
117+
else: filename = ''.join((g.S_IMG_URL, str(id), '.png'))
118+
finally:
119+
return filename
120+
100121
@staticmethod
101122
def std_embed(title='', url='', thumbnail_url='', sub_title='', value='', color=g.COLOR):
102123
pass

0 commit comments

Comments
 (0)