changed pokemon into a cog
This commit is contained in:
parent
275c5b7ee2
commit
2b0ec090c4
2 changed files with 253 additions and 249 deletions
|
|
@ -1,5 +1,4 @@
|
|||
#plugin file for sparkytron 3000
|
||||
|
||||
from discord.ext import commands
|
||||
import discord
|
||||
import random
|
||||
|
|
@ -9,9 +8,15 @@ import math
|
|||
import time
|
||||
import aiohttp
|
||||
|
||||
class Pokemon(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.working_dir = "tmp/pokemon/"
|
||||
self.data_dir = "data/pokemon/"
|
||||
self.folder_setup()
|
||||
|
||||
async def get_json(url):
|
||||
async def get_json(self, url):
|
||||
http_session = aiohttp.ClientSession()
|
||||
async with http_session.get(url) as resp:
|
||||
json_data = await resp.json()
|
||||
|
|
@ -24,10 +29,10 @@ async def get_json(url):
|
|||
aliases=['pkmn'],
|
||||
hidden=True
|
||||
)
|
||||
async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
||||
async def pokemon(self, ctx, *args):
|
||||
async def starter_picker(id): #id = pokedex number
|
||||
url = "https://pokeapi.co/api/v2/pokemon-species/" + str(id)
|
||||
json_data = await get_json(url)
|
||||
json_data = await self.get_json(url)
|
||||
if (json_data["evolves_from_species"] == None) and (not json_data['is_mythical']) and (not json_data['is_legendary']):
|
||||
return True
|
||||
else:
|
||||
|
|
@ -59,7 +64,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
|
||||
async def generate_starter(discord_id):
|
||||
random.seed(discord_id)
|
||||
json_data = await get_json('https://pokeapi.co/api/v2/pokemon-species/')
|
||||
json_data = await self.get_json('https://pokeapi.co/api/v2/pokemon-species/')
|
||||
pokemon_count = json_data['count']
|
||||
base_pokemon = False
|
||||
while not base_pokemon:
|
||||
|
|
@ -70,7 +75,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
|
||||
async def get_pkmn_from_id(id):
|
||||
url = 'https://pokeapi.co/api/v2/pokemon/' + str(id)
|
||||
json_data = await get_json(url)
|
||||
json_data = await self.get_json(url)
|
||||
return json_data
|
||||
|
||||
async def give_buddy_food(pkmn_data):
|
||||
|
|
@ -128,7 +133,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
embed.add_field(name="Types", value=type_str, inline=False)
|
||||
return embed
|
||||
|
||||
if arg1=='start':
|
||||
if args[0]=='start':
|
||||
if not os.path.isdir("databases/pokemon/"):
|
||||
os.makedirs("databases/pokemon/")
|
||||
if not os.path.isfile("databases/pokemon/"+str(ctx.author.id)+'.json'):
|
||||
|
|
@ -137,7 +142,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
json_data = await get_pkmn_from_id(starter_id)
|
||||
is_shiny = await shiny_roll()
|
||||
nature = random.randint(0,19)
|
||||
nature_data = await get_json('https://pokeapi.co/api/v2/nature/')
|
||||
nature_data = await self.get_json('https://pokeapi.co/api/v2/nature/')
|
||||
nature = nature_data['results'][nature]['name']
|
||||
json_data['shiny'] = is_shiny
|
||||
json_data['nickname'] = None
|
||||
|
|
@ -155,8 +160,8 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
await ctx.channel.send("You already have a pokemon!")
|
||||
return
|
||||
|
||||
elif arg1 == 'nick' or arg1 == 'nickname':
|
||||
nickname = arg2
|
||||
elif args[0] == 'nick' or args[0] == 'nickname':
|
||||
nickname = args[1]
|
||||
json_data = await load_pokemon(ctx.author.id)
|
||||
json_data['nickname'] = nickname
|
||||
await save_pokemon(ctx.author.id, json_data)
|
||||
|
|
@ -164,15 +169,15 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
await ctx.channel.send(message)
|
||||
return
|
||||
|
||||
elif arg1 == 'feed':
|
||||
elif args[0] == 'feed':
|
||||
json_data = await load_pokemon(ctx.author.id)
|
||||
json_data, fed = await give_buddy_food(json_data)
|
||||
if fed:
|
||||
await save_pokemon(ctx.author.id, json_data)
|
||||
if json_data['nickname']:
|
||||
message = "You " + arg1 + ' ' + json_data['nickname']
|
||||
message = "You " + args[0] + ' ' + json_data['nickname']
|
||||
else:
|
||||
message = "You " + arg1 + ' ' + json_data['name']
|
||||
message = "You " + args[0] + ' ' + json_data['name']
|
||||
await ctx.channel.send(message)
|
||||
return
|
||||
else:
|
||||
|
|
@ -183,15 +188,15 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
await ctx.channel.send(message)
|
||||
return
|
||||
|
||||
elif arg1 == 'hug':
|
||||
elif args[0] == 'hug':
|
||||
json_data = await load_pokemon(ctx.author.id)
|
||||
json_data, hugged = await give_buddy_affection(json_data)
|
||||
if hugged:
|
||||
await save_pokemon(ctx.author.id, json_data)
|
||||
if json_data['nickname']:
|
||||
message = "You " + arg1 + ' ' + json_data['nickname']
|
||||
message = "You " + args[0] + ' ' + json_data['nickname']
|
||||
else:
|
||||
message = "You " + arg1 + ' ' + json_data['name']
|
||||
message = "You " + args[0] + ' ' + json_data['name']
|
||||
await ctx.channel.send(message)
|
||||
return
|
||||
else:
|
||||
|
|
@ -219,7 +224,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
|
|||
aliases=['pdex'],
|
||||
hidden=False
|
||||
)
|
||||
async def pokedex(ctx):
|
||||
async def pokedex(self, ctx):
|
||||
pokemon = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
try:
|
||||
shiny = False
|
||||
|
|
@ -229,7 +234,7 @@ async def pokedex(ctx):
|
|||
url = "https://pokeapi.co/api/v2/pokemon/" + pokemon
|
||||
dex_url = "https://pokeapi.co/api/v2/pokemon-species/" + pokemon
|
||||
#try:
|
||||
data = await get_json(url)
|
||||
data = await self.get_json(url)
|
||||
name = data['name']
|
||||
height_str = str(int(data['height'])/10) + 'm'
|
||||
weight_str = str(int(data['weight'])/10) + 'kg'
|
||||
|
|
@ -243,7 +248,7 @@ async def pokedex(ctx):
|
|||
sprite = data["sprites"]["front_default"]
|
||||
if shiny:
|
||||
sprite = data["sprites"]["front_shiny"]
|
||||
dex_data = await get_json(dex_url)
|
||||
dex_data = await self.get_json(dex_url)
|
||||
generation = dex_data['generation']['name'].upper().replace("GENERATION","Generation")
|
||||
for entry in dex_data['flavor_text_entries']:
|
||||
if entry['language']['name'] == 'en':
|
||||
|
|
@ -270,5 +275,4 @@ async def pokedex(ctx):
|
|||
await ctx.channel.send(message)
|
||||
|
||||
async def setup(bot):
|
||||
bot.add_command(pokedex)
|
||||
bot.add_command(pokemon)
|
||||
bot.add_cog(Pokemon)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import time
|
|||
import os
|
||||
import asyncio
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import aiohttp
|
||||
|
||||
#Stable Diffusion
|
||||
|
|
@ -44,6 +43,7 @@ async def handle_error(error):
|
|||
f.write(log_line)
|
||||
return error
|
||||
|
||||
|
||||
def create_channel_config(filepath):
|
||||
config_dict = {
|
||||
"personality":"average",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue