-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (54 loc) · 2.44 KB
/
main.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
import discord
import os
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv
from functions import *
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='/', intents=intents)
#Load the .env file containing the token of our bot
load_dotenv()
TOKEN = os.getenv("TOKEN")
class Choice:
def __init__(self, name, wiki):
self.name = name
self.wiki = wiki
@bot.event
async def on_ready():
print("Connected!")
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands")
pass
except Exception as e:
print(e)
wikidict = {
"games": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Games_hub"),
"shows": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:TV_hub"),
"movies": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Movies_hub"),
"music": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Music_hub"),
"books": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Books_hub"),
"lifestyle": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Lifestyle_hub"),
"other": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Without_hub"),
"comics": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:Comics_hub"),
"tv": get_list_of_wikis("https://wikis.fandom.com/wiki/Category:TV_hub"),
}
numberlist = [1,2,3,4,5,6,7,8,9]
Choice = app_commands.Choice
@bot.tree.command(name = "wiki", description = "Searches the given wiki for a given query")
@app_commands.describe(query = "The search subject", wiki = "The wikipedia you want to look up in")
async def lookup(interaction: discord.Interaction, query: str, wiki: str):
await interaction.response.defer()
await get_wiki_result(interaction, query, wiki)
@bot.tree.command(name = "wikilist", description = "Lists the available wikis")
@app_commands.describe(category = "The category of wikis")
@app_commands.choices(category=[
*[app_commands.Choice(name=key.capitalize(), value=value) for key, value in zip(wikidict.keys(), numberlist)],]
)
async def wikilist(interaction: discord.Interaction, category: Choice[int]):
await interaction.response.defer()
for key, value in wikidict.items():
if category.name == key.capitalize():
await interaction.followup.send(f"Here are the available wikis for **{key.capitalize()}**:\n{value}")
bot.run(TOKEN)