54 lines
1.1 KiB
Python
54 lines
1.1 KiB
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()
|
|
|
|
user = os.environ["OPENSEARCH_USER"]
|
|
pswd = os.environ["OPENSEARCH_PASS"]
|
|
|
|
async def search(txt):
|
|
ses = req.Session()
|
|
ses.auth = (user, pswd)
|
|
|
|
resp = ses.get("https://scihub.copernicus.eu/dhus/search", params = {
|
|
'q': 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 = search(article)
|
|
|
|
interaction.followup.send("""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()
|
|
|
|
|