Add book command to search modding book

master
rubenwardy 2018-06-27 23:16:45 +01:00 committed by sfan5
parent 28fc9f1f15
commit c91a769a6a
2 changed files with 32 additions and 0 deletions

View File

@ -78,4 +78,6 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in [
<tr> <td>!tell {nick} {message}</td> <td>Tell somebody a message</td> <td>Anyone</td> </tr>
<tr> <td><b>modsearch.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!mod {modname}</td> <td>Searches for a mod</td> <td>Anyone</td> </tr>
<tr> <td><b>booksearch.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!book {term}</td> <td>Searches for a chapter/page in the modding book</td> <td>Anyone</td> </tr>
</table>

30
booksearch.py Normal file
View File

@ -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__)