Delete pressf and wolfram, update info
This commit is contained in:
parent
319a401fd3
commit
21794dea70
7 changed files with 2 additions and 241 deletions
|
@ -4,8 +4,8 @@
|
|||
],
|
||||
"install_msg": "Thanks for adding Ava Cogs! Join our Discord @ https://discord.gg/5CA8sewarU",
|
||||
"name": "Ava Cogs",
|
||||
"short": "Ava Cogs, for our fork of Red-DiscordBot",
|
||||
"description": "Ava Cogs, for our fork of Red-DiscordBot",
|
||||
"short": "Ava Cogs, for our fork of Red-DiscordBot (Ava-DiscordBot)",
|
||||
"description": "Ava Cogs, for our fork of Red-DiscordBot (Ava-DiscordBot)",
|
||||
"tags": [
|
||||
"avacogs",
|
||||
"pokemon",
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
from .pressf import PressF
|
||||
|
||||
__red_end_user_data_statement__ = "This cog does not persistently store data or metadata about users."
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(PressF(bot))
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"author": ["aikaterna"],
|
||||
"description": "Pay respects to a thing or user by pressing f.",
|
||||
"end_user_data_statement": "This cog does not persistently store data or metadata about users.",
|
||||
"install_msg": "Thanks for installing, have fun.",
|
||||
"min_bot_version": "3.5.0",
|
||||
"short": "Press f to pay respects.",
|
||||
"tags": ["f", "pressf", "respects"],
|
||||
"type": "COG"
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
import asyncio
|
||||
import discord
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.common_filters import filter_mass_mentions
|
||||
|
||||
|
||||
class PressF(commands.Cog):
|
||||
"""Pay some respects."""
|
||||
|
||||
async def red_delete_data_for_user(self, **kwargs):
|
||||
""" Nothing to delete """
|
||||
return
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.channels = {}
|
||||
|
||||
@commands.command()
|
||||
@commands.bot_has_permissions(add_reactions=True)
|
||||
async def pressf(self, ctx, *, user: discord.User = None):
|
||||
"""Pay respects by pressing F"""
|
||||
if str(ctx.channel.id) in self.channels:
|
||||
return await ctx.send(
|
||||
"Oops! I'm still paying respects in this channel, you'll have to wait until I'm done."
|
||||
)
|
||||
|
||||
if user:
|
||||
answer = user.display_name
|
||||
else:
|
||||
await ctx.send("What do you want to pay respects to?")
|
||||
|
||||
def check(m):
|
||||
return m.author == ctx.author and m.channel == ctx.channel
|
||||
|
||||
try:
|
||||
pressf = await ctx.bot.wait_for("message", timeout=120.0, check=check)
|
||||
except asyncio.TimeoutError:
|
||||
return await ctx.send("You took too long to reply.")
|
||||
|
||||
answer = pressf.content[:1900]
|
||||
|
||||
message = await ctx.send(
|
||||
f"Everyone, let's pay respects to **{filter_mass_mentions(answer)}**! Press the f reaction on this message to pay respects."
|
||||
)
|
||||
await message.add_reaction("\U0001f1eb")
|
||||
self.channels[str(ctx.channel.id)] = {"msg_id": message.id, "reacted": []}
|
||||
await asyncio.sleep(120)
|
||||
try:
|
||||
await message.delete()
|
||||
except (discord.errors.NotFound, discord.errors.Forbidden):
|
||||
pass
|
||||
amount = len(self.channels[str(ctx.channel.id)]["reacted"])
|
||||
word = "person has" if amount == 1 else "people have"
|
||||
await ctx.send(f"**{amount}** {word} paid respects to **{filter_mass_mentions(answer)}**.")
|
||||
del self.channels[str(ctx.channel.id)]
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_add(self, reaction, user):
|
||||
if str(reaction.message.channel.id) not in self.channels:
|
||||
return
|
||||
if self.channels[str(reaction.message.channel.id)]["msg_id"] != reaction.message.id:
|
||||
return
|
||||
if user.id == self.bot.user.id:
|
||||
return
|
||||
if user.id not in self.channels[str(reaction.message.channel.id)]["reacted"]:
|
||||
if str(reaction.emoji) == "\U0001f1eb":
|
||||
await reaction.message.channel.send(f"**{user.name}** has paid their respects.")
|
||||
self.channels[str(reaction.message.channel.id)]["reacted"].append(user.id)
|
|
@ -1,7 +0,0 @@
|
|||
from .wolfram import Wolfram
|
||||
|
||||
__red_end_user_data_statement__ = "This cog does not persistently store data or metadata about users."
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Wolfram(bot))
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"author": ["aikaterna"],
|
||||
"description": "Query Wolfram|Alpha for answers. Requires a free API key. Originally by Paddo.",
|
||||
"end_user_data_statement": "This cog does not persistently store data or metadata about users.",
|
||||
"install_msg": "Thanks for installing, have fun.",
|
||||
"min_bot_version": "3.5.0",
|
||||
"short": "Query Wolfram|Alpha for answers.",
|
||||
"tags": ["wolfram"],
|
||||
"requirements": ["pillow"],
|
||||
"type": "COG"
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
import aiohttp
|
||||
import discord
|
||||
from io import BytesIO
|
||||
import xml.etree.ElementTree as ET
|
||||
import urllib.parse
|
||||
|
||||
from redbot.core import Config, commands, checks
|
||||
from redbot.core.utils.chat_formatting import box, pagify
|
||||
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
|
||||
|
||||
|
||||
class Wolfram(commands.Cog):
|
||||
"""Ask Wolfram Alpha any question."""
|
||||
|
||||
async def red_delete_data_for_user(self, **kwargs):
|
||||
"""Nothing to delete."""
|
||||
return
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.session = aiohttp.ClientSession()
|
||||
|
||||
default_global = {"WOLFRAM_API_KEY": None}
|
||||
|
||||
self.config = Config.get_conf(self, 2788801004)
|
||||
self.config.register_guild(**default_global)
|
||||
|
||||
@commands.command(name="wolfram")
|
||||
async def _wolfram(self, ctx, *question: str):
|
||||
"""Ask Wolfram Alpha any question."""
|
||||
api_key = await self.config.WOLFRAM_API_KEY()
|
||||
if not api_key:
|
||||
return await ctx.send("No API key set for Wolfram Alpha. Get one at http://products.wolframalpha.com/api/")
|
||||
|
||||
url = "http://api.wolframalpha.com/v2/query?"
|
||||
query = " ".join(question)
|
||||
payload = {"input": query, "appid": api_key}
|
||||
headers = {"user-agent": "Red-cog/2.0.0"}
|
||||
async with ctx.typing():
|
||||
async with self.session.get(url, params=payload, headers=headers) as r:
|
||||
result = await r.text()
|
||||
root = ET.fromstring(result)
|
||||
a = []
|
||||
for pt in root.findall(".//plaintext"):
|
||||
if pt.text:
|
||||
a.append(pt.text.capitalize())
|
||||
if len(a) < 1:
|
||||
message = "There is as yet insufficient data for a meaningful answer."
|
||||
else:
|
||||
message = "\n".join(a[0:3])
|
||||
if "Current geoip location" in message:
|
||||
message = "There is as yet insufficient data for a meaningful answer."
|
||||
|
||||
if len(message) > 1990:
|
||||
menu_pages = []
|
||||
for page in pagify(message, delims=[" | ", "\n"], page_length=1990):
|
||||
menu_pages.append(box(page))
|
||||
await menu(ctx, menu_pages, DEFAULT_CONTROLS)
|
||||
else:
|
||||
await ctx.send(box(message))
|
||||
|
||||
@commands.command(name="wolframimage")
|
||||
async def _image(self, ctx, *arguments: str):
|
||||
"""Ask Wolfram Alpha any question. Returns an image."""
|
||||
if not arguments:
|
||||
return await ctx.send_help()
|
||||
api_key = await self.config.WOLFRAM_API_KEY()
|
||||
if not api_key:
|
||||
return await ctx.send("No API key set for Wolfram Alpha. Get one at http://products.wolframalpha.com/api/")
|
||||
|
||||
width = 800
|
||||
font_size = 30
|
||||
layout = "labelbar"
|
||||
background = "193555"
|
||||
foreground = "white"
|
||||
units = "metric"
|
||||
query = " ".join(arguments)
|
||||
query = urllib.parse.quote(query)
|
||||
url = f"http://api.wolframalpha.com/v1/simple?appid={api_key}&i={query}%3F&width={width}&fontsize={font_size}&layout={layout}&background={background}&foreground={foreground}&units={units}&ip=127.0.0.1"
|
||||
|
||||
async with ctx.typing():
|
||||
async with self.session.request("GET", url) as r:
|
||||
img = await r.content.read()
|
||||
if len(img) == 43:
|
||||
# img = b'Wolfram|Alpha did not understand your input'
|
||||
return await ctx.send("There is as yet insufficient data for a meaningful answer.")
|
||||
wolfram_img = BytesIO(img)
|
||||
try:
|
||||
await ctx.channel.send(file=discord.File(wolfram_img, f"wolfram{ctx.author.id}.png"))
|
||||
except Exception as e:
|
||||
await ctx.send(f"Oops, there was a problem: {e}")
|
||||
|
||||
@commands.command(name="wolframsolve")
|
||||
async def _solve(self, ctx, *, query: str):
|
||||
"""Ask Wolfram Alpha any math question. Returns step by step answers."""
|
||||
api_key = await self.config.WOLFRAM_API_KEY()
|
||||
if not api_key:
|
||||
return await ctx.send("No API key set for Wolfram Alpha. Get one at http://products.wolframalpha.com/api/")
|
||||
|
||||
url = f"http://api.wolframalpha.com/v2/query"
|
||||
params = {
|
||||
"appid": api_key,
|
||||
"input": query,
|
||||
"podstate": "Step-by-step solution",
|
||||
"format": "plaintext",
|
||||
}
|
||||
msg = ""
|
||||
|
||||
async with ctx.typing():
|
||||
async with self.session.request("GET", url, params=params) as r:
|
||||
text = await r.content.read()
|
||||
root = ET.fromstring(text)
|
||||
for pod in root.findall(".//pod"):
|
||||
if pod.attrib["title"] == "Number line":
|
||||
continue
|
||||
msg += f"{pod.attrib['title']}\n"
|
||||
for pt in pod.findall(".//plaintext"):
|
||||
if pt.text:
|
||||
strip = pt.text.replace(" | ", " ").replace("| ", " ")
|
||||
msg += f"- {strip}\n\n"
|
||||
if len(msg) < 1:
|
||||
msg = "There is as yet insufficient data for a meaningful answer."
|
||||
for text in pagify(msg):
|
||||
await ctx.send(box(text))
|
||||
|
||||
@checks.is_owner()
|
||||
@commands.command(name="setwolframapi", aliases=["setwolfram"])
|
||||
async def _setwolframapi(self, ctx, key: str):
|
||||
"""Set the api-key. The key is the AppID of your application on the Wolfram|Alpha Developer Portal."""
|
||||
|
||||
if key:
|
||||
await self.config.WOLFRAM_API_KEY.set(key)
|
||||
await ctx.send("Key set.")
|
||||
|
||||
def cog_unload(self):
|
||||
self.bot.loop.create_task(self.session.close())
|
Loading…
Add table
Reference in a new issue