From 6d7f6482e943ea726331b43b107d7e9cde54ad10 Mon Sep 17 00:00:00 2001 From: NightWolf56 <104475159+NightWolf56@users.noreply.github.com> Date: Mon, 27 Jun 2022 23:28:37 +0000 Subject: [PATCH 1/4] Added writeups command --- .gitignore | 3 ++- cogs/writeups.py | 38 ++++++++++++++++++++++++++++++++++++++ nullctf.py | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 cogs/writeups.py 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/cogs/writeups.py b/cogs/writeups.py new file mode 100644 index 0000000..fc8eeec --- /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/nullctf.py b/nullctf.py index 8a257e4..a0939e8 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. From de1bd1cb350cfa0fe10134ae25e914a506ca6104 Mon Sep 17 00:00:00 2001 From: NightWolf56 <104475159+NightWolf56@users.noreply.github.com> Date: Mon, 27 Jun 2022 23:44:15 +0000 Subject: [PATCH 2/4] Updated README.md to include writeups command --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From f2236547a18415a7589e6c40b2168a274e436090 Mon Sep 17 00:00:00 2001 From: NightWolf56 <104475159+NightWolf56@users.noreply.github.com> Date: Tue, 28 Jun 2022 00:34:26 +0000 Subject: [PATCH 3/4] Fixed bug in writeups command --- cogs/writeups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/writeups.py b/cogs/writeups.py index fc8eeec..59e62ed 100644 --- a/cogs/writeups.py +++ b/cogs/writeups.py @@ -13,7 +13,7 @@ def __init__(self, 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.") + 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="") From decf6425ca987bb7624bf192b413af71e3431519 Mon Sep 17 00:00:00 2001 From: NightWolf56 <104475159+NightWolf56@users.noreply.github.com> Date: Tue, 28 Jun 2022 02:29:04 +0000 Subject: [PATCH 4/4] Added writeups command to help command --- help_info.py | 9 ++++++++- nullctf.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 a0939e8..1cbf6ee 100644 --- a/nullctf.py +++ b/nullctf.py @@ -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')