46 lines
994 B
Python
46 lines
994 B
Python
import nextcord as nc
|
|
from nextcord.ext import commands
|
|
from typing import Optional
|
|
import asyncio
|
|
import os
|
|
import requests as req
|
|
|
|
bot = commands.Bot()
|
|
|
|
async def search(txt):
|
|
resp = req.post("https://www.sci-hub.st/", data={
|
|
'request':txt
|
|
})
|
|
|
|
return resp
|
|
|
|
@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)
|
|
|
|
await interaction.followup.send(f"""Search Response:
|
|
```
|
|
{resp.text[:1000]}
|
|
```
|
|
""")
|
|
|
|
def main():
|
|
# TODO: Import bot token from env
|
|
bot.run(os.environ["DISCORD_TOKEN"])
|
|
|
|
if __name__ == "__main__":
|
|
print("Handy Helper has Begun!")
|
|
main()
|
|
|
|
|