Compare commits

...

5 Commits

Author SHA1 Message Date
rubenwardy c91a769a6a Add book command to search modding book 2018-06-28 12:11:40 +02:00
sfan5 28fc9f1f15 [rssnotify] Fix my incompetence 2017-12-04 21:19:34 +01:00
sfan5 2e6a04a73d [rssnotify] Update configuration 2017-11-26 17:24:41 +01:00
sfan5 8a432e905c [title] Try to fix with certain sites 2017-08-23 19:56:34 +02:00
sfan5 382e7cb15b Add kitty 2017-05-29 19:12:59 +02:00
5 changed files with 62 additions and 16 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__)

View File

@ -32,6 +32,20 @@ def to_unix_time(tstr):
ts += int(g[3]) * 60
return ts
def resolve_channels(phenny, l):
ret = set()
for entry in l:
sign = 1
if entry[0] == "-":
entry = entry[1:]
sign = -1
c = phenny.bot.channels if entry == "*" else [entry]
if sign == 1:
ret |= set(c)
else: # sign == -1
ret -= set(c)
return ret
class RssNotify():
def __init__(self, config):
self.config = config
@ -114,24 +128,25 @@ class RssNotify():
committer_final = f_clong % (committer, committer_realname)
return f_all % (committer_final, repo_name, commit_text, commit_hash, commit_link, commit_time)
def _announce(self, phenny, message, chans):
if chans == "*":
chans = phenny.bot.channels
assert(type(chans) == list)
chans = resolve_channels(phenny, chans)
for ch in chans:
phenny.write(['PRIVMSG', ch], message)
#################
c = ['*', '-#minetest-hub']
rssn = RssNotify({
"check_interval": 120,
"show_link": True,
"shorten_link": True,
"logfile": os.getcwd() + "/rssnotify.log",
"feeds": [
('https://github.com/minetest/minetest/commits/master.atom', "*"),
('https://github.com/minetest/minetest_game/commits/master.atom', "*"),
('https://github.com/minetest/minetestmapper/commits/master.atom', "*"),
('https://github.com/minetest/master-server/commits/master.atom', "*"),
('https://github.com/Uberi/Minetest-WorldEdit/commits/master.atom', "*"),
('https://github.com/minetest-mods/mesecons/commits/master.atom', "*"),
('https://github.com/minetest/minetest/commits/master.atom', c),
('https://github.com/minetest/minetest_game/commits/master.atom', c),
('https://github.com/minetest/minetestmapper/commits/master.atom', c),
('https://github.com/minetest/master-server/commits/master.atom', c),
('https://github.com/Uberi/Minetest-WorldEdit/commits/master.atom', c),
('https://github.com/minetest-mods/mesecons/commits/master.atom', c),
('https://github.com/sfan5/phenny/commits/master.atom', ['##minetestbot']),
('https://github.com/sfan5/minetestbot-modules/commits/master.atom', ['##minetestbot']),
],

View File

@ -134,7 +134,8 @@ def cat(phenny, input):
"https://i.imgur.com/s9tdEOi.jpg",
"http://i.imgur.com/8mFITRO.jpg",
"http://i.imgur.com/ZT2jVRu.jpg",
"http://i.imgur.com/NIwzCXd.jpg"
"http://i.imgur.com/NIwzCXd.jpg",
"https://pbs.twimg.com/media/DBAZtPCXgAAYKtz.jpg:large"
]
phenny.say(random.choice(cats))

View File

@ -23,16 +23,14 @@ def title(phenny, input):
data, sc = web.get(uri, 16384)
if sc != 200:
return phenny.say("HTTP error %d" % sc)
try:
data = str(data, 'utf-8')
except UnicodeDecodeError:
return phenny.say("Doesn't seem to be HTML..")
data = str(data, 'utf-8', 'ignore')
m = re.search(r_title, data)
if not m:
return phenny.say("No title found.")
title = m.group(1)
title = html.unescape(title)
title = title.strip()
title = html.unescape(title).strip()
if len(title) > 150:
title = title[:150] + "[...]"
phenny.reply(title)