Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added writeups command #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config_vars.py
__pycache__/
cogs/__pycache__/
cogs/__pycache__/
todo.txt
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <search query>` 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
Expand Down
38 changes: 38 additions & 0 deletions cogs/writeups.py
Original file line number Diff line number Diff line change
@@ -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='<query>')
async def writeups(self, ctx, *, query=None):
if query is None:
await ctx.send("Query not provided: `>writeups <query>` 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))
9 changes: 8 additions & 1 deletion help_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,19 @@
`>help config`
bot configuration info

`>help writeups`
info for ctf writeup search command

`>help utility`
everything else! (basically misc)

`>report/request "an issue or feature"`
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"
`>writeups <query string>`
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"
7 changes: 5 additions & 2 deletions nullctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down