Compare commits

...

5 Commits

Author SHA1 Message Date
sfan5 27d965c411 [rssnotify] Remove link shortening
git.io stopped working in January
2022-04-26 22:41:33 +02:00
sfan5 551ff1e89b
Update README 2021-08-29 21:42:59 +02:00
sfan5 6eee4e7567 [rssnotify] Update and fix a few things 2021-08-29 21:38:25 +02:00
sfan5 5fd4be8693 [rssnotify] Update a feed URL 2021-01-24 12:24:52 +01:00
sfan5 0334f86ca4 [modsearch] Show git repo link too 2020-04-06 22:01:17 +02:00
4 changed files with 38 additions and 37 deletions

View File

@ -1,4 +1,8 @@
minetestbot-modules
===================
Customised Phenny (sbp/phenny) Modules for the #minetest Channel Bot
customised phenny (https://github.com/sfan5/phenny) modules for the [#minetest](https://wiki.minetest.net/IRC) channel bot
Check [COMMANDS.md](./COMMANDS.md) for a list of supported commands.
Individual modules have their licenses listed in the docstring.

View File

@ -19,6 +19,8 @@ def mod(phenny, input):
answer = (data["title"] +
" by " + data["author"] +
" - " + data["link"])
if "source" in data:
answer += " - " + data["source"]
phenny.reply(answer)

View File

@ -47,6 +47,7 @@ def resolve_channels(phenny, l):
return ret
class RssNotify():
MAX_MESSAGES = 6
def __init__(self, config):
self.config = config
self.last_updated = {}
@ -61,41 +62,36 @@ class RssNotify():
print("[RssNotify]: Checking RSS feeds...")
for fid, feedspec in enumerate(self.config["feeds"]):
feed = feedparser.parse(feedspec[0], agent="Mozilla/5.0 (compatible; MinetestBot)")
updated = 0
if self.firstrun:
self.last_updated[fid] = max((to_unix_time(e.updated) for e in feed.entries), default=0)
continue
new = []
for entry in feed.entries:
if self.firstrun:
break
if self.last_updated[fid] >= to_unix_time(entry.updated):
continue
new.append(entry)
if len(new) == 0:
continue
print("[RssNotify]: Found %d update(s) for '%s'" % (len(new), feedspec[0]))
self.last_updated[fid] = max(to_unix_time(e.updated) for e in feed.entries)
new.reverse()
if self.config["logfile"] is not None:
with open(self.config["logfile"], "a", encoding="utf-8") as f:
for entry in new:
message = self._format_msg(entry, log_format=True)
f.write(message + "\n")
for entry in new[:RssNotify.MAX_MESSAGES]:
message = self._format_msg(entry)
self._announce(phenny, message, feedspec[1])
if self.config["logfile"] is not None:
with open(self.config["logfile"], "a", encoding="utf-8") as f:
message = self._format_msg(entry, log_format=True)
f.write(message)
f.write("\n")
updated += 1
new_time = max((to_unix_time(e.updated) for e in feed.entries), default=0)
if new_time > self.last_updated[fid]:
self.last_updated[fid] = new_time
if updated > 0:
print("[RssNotify]: Found %d update(s) for '%s'" % (updated, feedspec[0]))
if self.firstrun:
self.firstrun = False
if len(new) > RssNotify.MAX_MESSAGES:
message = self._get_cutoff_message(len(new) - RssNotify.MAX_MESSAGES)
self._announce(phenny, message, feedspec[1])
self.firstrun = False
print("[RssNotify]: Checked %d RSS feeds in %0.3f seconds" % (len(self.config["feeds"]), time.time()-start))
def _shorten(self, link):
# We can utilitze git.io to shorten *.github.com links
l, code = web.post("https://git.io/create", {'url': link})
if code != 200:
return None
l = str(l, 'utf-8')
if ' ' in l: # spaces means there was an error :(
return None
return "https://git.io/" + l
def _format_msg(self, feed_entry, log_format=False):
if log_format:
f_cshort = "[color=#cc0000]%s[/color]"
f_clong = "[color=#cc0000]%s[/color] ([color=#cc0000]%s[/color])"
f_cshort = "[color=#c00]%s[/color]"
f_clong = "[color=#c00]%s[/color] ([color=#c00]%s[/color])"
f_all = "[color=#3465a4][git][/color] %s -> [color=#73d216]%s[/color]: [b]%s[/b] [color=#a04265]%s[/color] %s ([color=#888a85]%s[/color])"
else:
f_cshort = "\x0304%s\x0f"
@ -103,10 +99,10 @@ class RssNotify():
f_all = "\x0302[git]\x0f %s -> \x0303%s\x0f: \x02%s\x0f \x0313%s\x0f %s (\x0315%s\x0f)"
committer_realname = feed_entry.authors[0].name
if committer_realname == "":
try:
committer_realname = feed_entry.authors[0].email
except AttributeError:
committer_realname = ""
try:
committer_realname = feed_entry.authors[0].email
except AttributeError:
committer_realname = ""
try:
committer = feed_entry.authors[0].href.replace('https://github.com/',"")
except AttributeError:
@ -118,8 +114,6 @@ class RssNotify():
commit_text = feed_entry.title
if self.config["show_link"]:
commit_link = feed_entry.link
if self.config["shorten_link"]:
commit_link = self._shorten(commit_link) or commit_link
else:
commit_link = ""
if committer_realname == "" or committer_realname.lower() == committer.lower():
@ -127,6 +121,8 @@ class RssNotify():
else:
committer_final = f_clong % (committer, committer_realname)
return f_all % (committer_final, repo_name, commit_text, commit_hash, commit_link, commit_time)
def _get_cutoff_message(self, left):
return "\x0302[git]\x0f (%d newer commits not shown)" % left
def _announce(self, phenny, message, chans):
chans = resolve_channels(phenny, chans)
for ch in chans:
@ -138,13 +134,12 @@ 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', 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/minetest/serverlist/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

@ -38,7 +38,7 @@ def check(host, port):
sock.close()
def serverup(phenny, input):
arg = input.group(2)
arg = input.group(2).strip()
if not arg:
return phenny.reply("give me an address and (optionally) a port")