|
|
@ -1,11 +1,9 @@
|
|
|
|
import discord
|
|
|
|
import discord
|
|
|
|
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
from redbot.core import Config
|
|
|
|
|
|
|
|
from redbot.core.utils.chat_formatting import box
|
|
|
|
|
|
|
|
|
|
|
|
from .utils.chat_formatting import pagify
|
|
|
|
from .howdoi_source import howdoi as hdi
|
|
|
|
from .utils.chat_formatting import box
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .howdoi_source import howdoi as hdi, Answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Howdoi:
|
|
|
|
class Howdoi:
|
|
|
@ -24,7 +22,7 @@ class Howdoi:
|
|
|
|
"num_answers": 1,
|
|
|
|
"num_answers": 1,
|
|
|
|
"clear_cache": False,
|
|
|
|
"clear_cache": False,
|
|
|
|
"version": False
|
|
|
|
"version": False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.config.register_global(**default_global)
|
|
|
|
self.config.register_global(**default_global)
|
|
|
|
|
|
|
|
|
|
|
@ -34,52 +32,52 @@ class Howdoi:
|
|
|
|
Settings are reset on reload"""
|
|
|
|
Settings are reset on reload"""
|
|
|
|
if ctx.invoked_subcommand is None:
|
|
|
|
if ctx.invoked_subcommand is None:
|
|
|
|
await ctx.send_help()
|
|
|
|
await ctx.send_help()
|
|
|
|
|
|
|
|
|
|
|
|
@howdoiset.command(pass_context=True, name="answers")
|
|
|
|
@howdoiset.command(pass_context=True, name="answers")
|
|
|
|
async def howdoiset_answers(self, ctx, num_answers: int=1):
|
|
|
|
async def howdoiset_answers(self, ctx, num_answers: int = 1):
|
|
|
|
"""Adjust number of answers provided.
|
|
|
|
"""Adjust number of answers provided.
|
|
|
|
Defaults to 1"""
|
|
|
|
Defaults to 1"""
|
|
|
|
|
|
|
|
|
|
|
|
await self.config.num_answers.set(num_answers)
|
|
|
|
await self.config.num_answers.set(num_answers)
|
|
|
|
await ctx.send("Number of answers provided will now be {}".format(num_answers))
|
|
|
|
await ctx.send("Number of answers provided will now be {}".format(num_answers))
|
|
|
|
|
|
|
|
|
|
|
|
@howdoiset.command(pass_context=True, name="link")
|
|
|
|
@howdoiset.command(pass_context=True, name="link")
|
|
|
|
async def howdoiset_link(self, ctx):
|
|
|
|
async def howdoiset_link(self, ctx):
|
|
|
|
"""Toggles providing in-line answers or a link
|
|
|
|
"""Toggles providing in-line answers or a link
|
|
|
|
Default On"""
|
|
|
|
Default On"""
|
|
|
|
|
|
|
|
|
|
|
|
await self.config.link.set(not (await self.config.link()))
|
|
|
|
await self.config.link.set(not (await self.config.link()))
|
|
|
|
|
|
|
|
|
|
|
|
if await self.config.link():
|
|
|
|
if await self.config.link():
|
|
|
|
await ctx.send("Answers will now be provided as a link")
|
|
|
|
await ctx.send("Answers will now be provided as a link")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("Answers will now be provided as the response")
|
|
|
|
await ctx.send("Answers will now be provided as the response")
|
|
|
|
|
|
|
|
|
|
|
|
@howdoiset.command(pass_context=True, name="full")
|
|
|
|
@howdoiset.command(pass_context=True, name="full")
|
|
|
|
async def howdoiset_full(self, ctx):
|
|
|
|
async def howdoiset_full(self, ctx):
|
|
|
|
"""Toggles providing full answers or just first code found
|
|
|
|
"""Toggles providing full answers or just first code found
|
|
|
|
Default Off
|
|
|
|
Default Off
|
|
|
|
Only works if links are turned off"""
|
|
|
|
Only works if links are turned off"""
|
|
|
|
|
|
|
|
|
|
|
|
await self.config.all.set(not (await self.config.all()))
|
|
|
|
await self.config.all.set(not (await self.config.all()))
|
|
|
|
|
|
|
|
|
|
|
|
if await self.config.all():
|
|
|
|
if await self.config.all():
|
|
|
|
await ctx.send("Answers will now be provided in full context")
|
|
|
|
await ctx.send("Answers will now be provided in full context")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("Answers will now be provided as a code snippet")
|
|
|
|
await ctx.send("Answers will now be provided as a code snippet")
|
|
|
|
|
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
|
|
|
@commands.command(pass_context=True)
|
|
|
|
async def howdoi(self, ctx, *question):
|
|
|
|
async def howdoi(self, ctx, *question):
|
|
|
|
"""Ask a coding question"""
|
|
|
|
"""Ask a coding question"""
|
|
|
|
self.query = " ".join(question)
|
|
|
|
self.query = " ".join(question)
|
|
|
|
|
|
|
|
|
|
|
|
await self.config.query.set(self.query)
|
|
|
|
await self.config.query.set(self.query)
|
|
|
|
|
|
|
|
|
|
|
|
out = hdi.howdoi(await self.config.all()) # .encode('utf-8', 'ignore')
|
|
|
|
out = hdi(await self.config.all()) # .encode('utf-8', 'ignore')
|
|
|
|
|
|
|
|
|
|
|
|
if await self.config.links():
|
|
|
|
if await self.config.links():
|
|
|
|
await ctx.send(out)
|
|
|
|
await ctx.send(out)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send(box(out,"python"))
|
|
|
|
await ctx.send(box(out, "python"))
|
|
|
|
# for page in pagify(out, shorten_by=24):
|
|
|
|
# for page in pagify(out, shorten_by=24):
|
|
|
|
# await ctx.send(box(page))
|
|
|
|
# await ctx.send(box(page))
|
|
|
|