This repository has been archived by the owner on Dec 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.py
114 lines (102 loc) · 5.05 KB
/
lookup.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
"""
This cog deals all the lookup commands
"""
import asyncio
from discord.ext import commands, tasks
import discord
from lookupAPI import nookipediaAPI, localLookup
import os
from dotenv import load_dotenv
load_dotenv(".env")
class Lookup(commands.Cog):
nookAPI = nookipediaAPI.NookipediaAPI(os.environ.get("nookipedia_API_key"))
localAPI = localLookup.LocalLookup()
def __init__(self, bot):
self.bot = bot
@tasks.loop(hours=6)
async def updateLists(self):
await self.localAPI.updateData()
await self.nookAPI.clearOutdatedCache()
@commands.command(name='villager',
help="Get an overview of a villager and their trites.\n"
"<villager>: The villager you want to search for",
aliases=['Villager', 'Villagers', 'villagers'])
async def villagerOverview(self, ctx, villager):
with ctx.typing():
villager = villager.title()
response = await self.nookAPI.getVillager(villager)
if response is None:
await ctx.send("Couldn't find villager\n"
"If the villager's name is in 2 part, use \" to enclose the name.\n"
"E.G. \"Agent S\"")
return
embeded = discord.Embed.from_dict(response.response)
await ctx.send(embed=embeded)
@commands.command(name='critter',
help="Get an overview of a critter and their trites.\n"
"<critter>: The critter you want to search for",
aliases=['bug', 'fish', 'Critter', 'Bug', 'Fish', 'critters', 'Critters'])
async def critterOverview(self, ctx, critter):
with ctx.typing():
critter = critter.title()
response = await self.nookAPI.getCritter(critter)
if response is None:
await ctx.send("Couldn't find critter\n"
"If the critter's name is in 2 part, use \" to enclose the name.\n"
"E.G. \"Banded Dragonfly\"")
return
embeded = discord.Embed.from_dict(response.response)
await ctx.send(embed=embeded)
@commands.command(name='fossil',
help="Get an overview of a fossil and their trites.\n"
"<fossil>: The fossil you want to search for",
aliases=['fossils', 'Fossil', 'Fossils'])
async def fossilOverview(self, ctx, fossil):
with ctx.typing():
fossil = fossil.title()
response = await self.nookAPI.getFossil(fossil)
if response is None:
await ctx.send("Couldn't find fossil\n"
"If the fossil's name is in 2 part, use \" to enclose the name.\n"
"E.G. \"Tyrannosaurus Rex\"")
return
embeded = discord.Embed.from_dict(response.response)
await ctx.send(embed=embeded)
@commands.command(name='eventsToday',
help="Get an overview of all the events on today in AC\n",
aliases=['eventstoday'])
async def todayOverview(self, ctx):
with ctx.typing():
events = await self.nookAPI.getToday()
if events is None:
await ctx.send("Unable to get events today >.<")
return
if len(events['events']) < 1: # We Check that there are events today first
await ctx.send("No events are on today in Animal Crossing\n")
return
embedded = discord.Embed(title='Events Today', description=events['message'], color=0xCF70D3)
embedded.set_author(name="Turnip Bot",
url="https://github.com/vlee489/Turnip-Bot/",
icon_url="https://cdn.vlee.me.uk/TurnipBot/icon.png")
for x in range(len(events['events'])): # For each event we add a field and the event info
embedded.add_field(name="Events {}:".format(x + 1), value=events['events'][x],
inline=False)
embedded.set_footer(text="Info from nookipedia.com",
icon_url="https://cdn.vlee.me.uk/TurnipBot/Nookipedia.png")
await ctx.send(embed=embedded)
@commands.command(name='DIY',
help="Get an overview of a DIY recipe\n"
"<diy>: The item you want to lookup",
aliases=['diy'])
async def DIYOverview(self, ctx, diy):
with ctx.typing():
response = await self.localAPI.getDiy(diy)
if response is None:
await ctx.send("Couldn't find DIY Recipe\n"
"If the recipe's name is in 2 part, use \" to enclose the name.\n"
"E.G. \"gold helmet\"")
return
embedded = discord.Embed.from_dict(response.response)
await ctx.send(embed=embedded)
def setup(bot):
bot.add_cog(Lookup(bot))