@@ -30,16 +30,19 @@ async def dex(self, ctx, *args):
30
30
from pokedex import Pokedex as this
31
31
pkmn_id = 0 ; pkmn_name = '' ; pkmn_genus = '' ; pkmn_url = '' ; pkmn_desc = '' ;
32
32
random_args = ['-r' , '-rand' , '-random' ]
33
- papi = PokeAPI ()
33
+ shiny = False
34
+
34
35
if not self .lock :
35
- #pokemon number given
36
+ papi = PokeAPI ()
36
37
if args and len (args ) >= 1 :
37
38
t = args [0 ]
38
39
if type (t ) == str and t .startswith ('-' ):
39
40
if t in random_args :
40
41
p = pkmn ()
41
42
p .initialize ()
42
43
t = p .pkmn_id
44
+ if '-s' in args [1 :] or '-shiny' in args [1 :]:
45
+ shiny = True
43
46
if type (t ) == int or type (t ) == str :
44
47
self .lock = True
45
48
if type (t ) == str :
@@ -67,16 +70,17 @@ async def dex(self, ctx, *args):
67
70
pkmn_type = {i ['type' ]['name' ] for i in pt }
68
71
print ("Displaying Pokemon {0} #{1}" .format (pkmn_name , pkmn_id ))
69
72
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 )
80
84
type_emojis = ' ' .join ({g .TYPE_DICT [t ] for t in pkmn_type if t in g .TYPE_DICT })
81
85
title = "{0} #{1} {2}" .format (pkmn_name .capitalize (), pkmn_id , type_emojis )
82
86
sub_title = "the {0} Pokémon" .format (pkmn_genus )
@@ -97,6 +101,23 @@ async def dex(self, ctx, *args):
97
101
print ("The dex is currently in use" )
98
102
return
99
103
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
+
100
121
@staticmethod
101
122
def std_embed (title = '' , url = '' , thumbnail_url = '' , sub_title = '' , value = '' , color = g .COLOR ):
102
123
pass
0 commit comments