import nextcord as nc from nextcord.ext import commands from typing import Optional import asyncio import os import requests as req from bs4 import BeautifulSoup as soup bot = commands.Bot() async def search(txt): resp = req.post("https://www.sci-hub.st/", data={ 'request':txt }) doc = soup(resp.text, 'html_parser') if 'not found' in doc.title: return None ref = doc.find("div", {'id': 'citation'}).get_text() return { 'ref': ref } @bot.event async def on_ready(): print(f'We have logged in as {bot.user}') @bot.slash_command(name="summarize", description="Summarize all or part of an article", dm_permission=True) async def summarize( interaction: nc.Interaction, article: str, part: Optional[str] = nc.SlashOption(required=False) ): await interaction.response.defer(ephemeral=False, with_message=True) resp = await search(article) if resp is None: await interaction.followup.send(f"Unable to find article: {article}") return await interaction.followup.send(f"Article Found: \n{resp['ref']}") def main(): # TODO: Import bot token from env bot.run(os.environ["DISCORD_TOKEN"]) if __name__ == "__main__": print("Handy Helper has Begun!") main()