diff --git a/.gitignore b/.gitignore index 7de4246..586bcb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config_vars.py __pycache__/ -cogs/__pycache__/ \ No newline at end of file +cogs/__pycache__/ +todo.txt diff --git a/README.md b/README.md index c4e8b0d..f4ea300 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ The following commands are the ones you will most likely want to pay attention t * `>request/report "a feature"/"a bug"` Dm's the creator (nullpxl#3928) with your feature/bug request/report. +--- +## Writeups Command +* `>writeups ` Searches for CTF writeups based on the provided string. Search includes, CTF Event, challenge name, writeups content, etc. Double quotes can be used around all or part of a query to find an exact match and a minus sign can be used to exclude results. + ## Have a feature request? Make a GitHub issue or use the >request command. # Setup - General Overview diff --git a/cogs/writeups.py b/cogs/writeups.py new file mode 100644 index 0000000..59e62ed --- /dev/null +++ b/cogs/writeups.py @@ -0,0 +1,38 @@ + +import requests +import urllib +import discord +import json +from discord.ext import commands + +class Writeups(commands.Cog): + + def __init__(self, bot): + self.bot = bot + + @commands.command(name='writeups', usage='') + async def writeups(self, ctx, *, query=None): + if query is None: + await ctx.send("Query not provided: `>writeups ` For an exact match, enclose your search query between double quotes. To exclude a search term, prepend a '-' character.") + else: + writeupapi = "http://ctf-api.hfz-1337.ninja/?q=" + url = writeupapi + urllib.parse.quote_plus(query, safe="") + r = requests.get(url) + data = json.loads(r.content) + i = 0 + + while i <= 4: + try: + embed = discord.Embed(title=data[i]['name'], color=0xFF5733) + embed.add_field(name="Event", value=data[i]['ctf'], inline=False) + embed.add_field(name="Author", value=data[i]['author'], inline=True) + embed.add_field(name="Team", value=data[i]['team'], inline=True) + embed.add_field(name="CTF Time URL", value=data[i]['ctftime'], inline=False) + await ctx.send(embed=embed) + i += 1 + except Exception as err: + await ctx.send("Error fetching additional results.") + break + +def setup(bot): + bot.add_cog(Writeups(bot)) diff --git a/help_info.py b/help_info.py index a2d81c0..2dda12a 100644 --- a/help_info.py +++ b/help_info.py @@ -99,6 +99,9 @@ `>help config` bot configuration info +`>help writeups` +info for ctf writeup search command + `>help utility` everything else! (basically misc) @@ -106,5 +109,9 @@ report an issue, or request a feature for NullCTF, if it is helpful your name will be added to the 'cool names' list! ''' +writeups_help = ''' -src = "https://github.com/NullPxl/NullCTF" \ No newline at end of file +`>writeups ` +search for CTF writeups based on the provided query string. Double quotes can be used to require an exact match fo rall or part of a query. Likewise, a minus sign can be added to remove specified results. +''' +src = "https://github.com/NullPxl/NullCTF" diff --git a/nullctf.py b/nullctf.py index 8a257e4..1cbf6ee 100644 --- a/nullctf.py +++ b/nullctf.py @@ -13,7 +13,7 @@ bot.remove_command('help') # Each extension corresponds to a file within the cogs directory. Remove from the list to take away the functionality. -extensions = ['ctf', 'ctftime', 'configuration', 'encoding', 'cipher', 'utility'] +extensions = ['ctf', 'ctftime', 'configuration', 'encoding', 'cipher', 'utility', 'writeups'] # List of names reserved for those who gave cool ideas or reported something interesting. # please don't spam me asking to be added. if you send something interesting to me i will add you to the list. # If your name is in the list and you use the command '>amicool' you'll get a nice message. @@ -43,7 +43,10 @@ async def help(ctx, page=None): elif page == 'utility': emb = discord.Embed(description=help_info.utility_help, colour=4387968) emb.set_author(name='Utilities Help') - + elif page == 'writeups': + emb = discord.Embed(description=help_info.writeups_help, colour=4387968) + emb.set_author(name='Writeups Help') + else: emb = discord.Embed(description=help_info.help_page, colour=4387968) emb.set_author(name='NullCTF Help')