diff --git a/wikibot.py b/wikibot.py index 3c47b56..7e64310 100644 --- a/wikibot.py +++ b/wikibot.py @@ -14,7 +14,8 @@ async def on_ready(): print(f"We've logged in as {bot.user}.") -@bot.slash_command(guild_ids=g_ids, name = "summary", description="Returns a Wikipedia summary" ) + +@bot.slash_command(guild_ids=g_ids, name = "summary", description="Returns a Wikipedia summary") async def summary(ctx, search: Option(str, description="What do you want to get summary for?", required = True)): await ctx.channel.trigger_typing() # shows that bot is typing try: # sezene sumar a odesle @@ -32,5 +33,34 @@ async def summary(ctx, search: Option(str, description="What do you want to get +@bot.slash_command(guild_ids=g_ids, name = "search", description="Search Wikipedia") +async def search(ctx, search: Option(str, description = "What do you want to search for?", required = True)): + await ctx.channel.trigger_typing() # shows that bot is typing + searchsearch = str(wikipedia.search(search, suggestion = True)).replace('(', '').replace(")", "").replace("'", "").replace('[', '').replace(']', '') + try: + await ctx.respond(searchsearch) + except: + await ctx.send(searchsearch) + + + +@bot.slash_command(guild_ids=g_ids, name = "url", description="Get a URL to a page on Wikipedia") +async def search(ctx, search: Option(str, description = "What do you want to get URL for?", required = True)): + await ctx.channel.trigger_typing() # shows that bot is typing + try: # pokud sezenu sumary tak sezenu link + urlsummary = wikipedia.summary(search, auto_suggest = False) + search = search.lower().replace(" ","_").replace(" ","_") + try: + await ctx.respond(f"https://en.wikipedia.org/wiki/{search}") + except: + await ctx.send(f"https://en.wikipedia.org/wiki/{search}") + except: + urlsearch = str(wikipedia.search(search, suggestion = True)).replace('(', '').replace(")", "").replace("'", "").replace('[', '').replace(']', '') + try: + await ctx.respond(f"https://en.wikipedia.org/wiki/{urlsearch}") + except: + await ctx.send(f"https://en.wikipedia.org/wiki/{urlsearch}") + + bot.run("MTMyNTk1Mzg4OTcyNzQxNDM0Mw.G2Tgo0.2OhbgaVYhys0BhxJMVgGDnG0W5qvxH-soJML3M")