diff --git a/COMMANDS.md b/COMMANDS.md index 6493b36..2c9b776 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -78,4 +78,6 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in [ !tell {nick} {message} Tell somebody a message Anyone modsearch.py !mod {modname} Searches for a mod Anyone + booksearch.py + !book {term} Searches for a chapter/page in the modding book Anyone diff --git a/booksearch.py b/booksearch.py new file mode 100644 index 0000000..17eed33 --- /dev/null +++ b/booksearch.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +""" +booksearch.py - Phenny Minetest Modding Book Search Module +Copyright 2018, rubenwardy +Licensed under GNU General Public License v2.0 +""" + +import web + +def book(phenny, input): + uri = "https://rubenwardy.com/minetest_modding_book/sitemap.json" + text, status = web.get(uri) + text = str(text, 'utf-8') + data = web.json(text) + + query = (input.group(2) or "").lower() + if not query: return + for ele in data: + title = ele["title"] + desc = ele.get("description", "") + if query in title.lower() or query in desc.lower(): + return phenny.reply(title + " - " + ele["loc"]) + + phenny.reply("Nothing found.") + +book.commands = ['book'] +book.example = '.book folder structure' + +if __name__ == '__main__': + print(__doc__)