Skip to content

Commit

Permalink
[Version]Send a little message to the owner and admins when Willie is…
Browse files Browse the repository at this point in the history
…n't updated.
  • Loading branch information
tyrope committed Aug 1, 2014
1 parent e6c7e27 commit 6a37da5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
version.py - Willie Version Module
Copyright 2009, Silas Baronda
Copyright 2014, Dimitri Molenaars <tyrope@tyrope.nl>
Licensed under the Eiffel Forum License 2.
http://willie.dftba.net
Expand All @@ -12,6 +13,7 @@
import willie
import re
from os import path
import json

log_line = re.compile('\S+ (\S+) (.*? <.*?>) (\d+) (\S+)\tcommit[^:]*: (.+)')

Expand Down Expand Up @@ -76,3 +78,50 @@ def ctcp_time(bot, trigger):
current_time = dt.strftime("%A, %d. %B %Y %I:%M%p")
bot.write(('NOTICE', trigger.nick),
'\x01TIME {0}\x01'.format(current_time))

@willie.module.interval(86400)
def version_check(bot):
"""
This functions checks every 24 hours if there's a new version available.
"""

message_release = "My version doesn't match the latest release (%s(latest)s). I'm on %(local)s. Please update me."
message_git = "My version doesn't match the master branch (%(latest)s). I'm on %(local)s). Please update me."

API_url = 'https://api.github.com/repos/embolalia/willie/'

git_HEAD = git_info()
if not git_HEAD:
# Running a release version.
API_result = willie.web.get(API_url + 'releases')

# Get the first(0) release name('name'), which should be the latest.
latest_release = json.loads(API_result)[0]['name'].encode('utf-8')

if willie.__version__ != latest_release:
# We're not updated!
# Message the owner.
bot.msg(bot.config.core.owner, message_release %
{'latest': latest_release, 'local': willie.__version__ })
for admin in bot.config.core.admins:
# Message the admins as well.
bot.msg(admin, message_release %
{'latest': latest_release, 'local': willie.__version__ })
else:
# Running a -git version.
API_result = willie.web.get(API_url + 'commits/master')

# Get latest commit's hash('sha').
remote_HEAD = json.loads(API_result)['sha'].encode('utf-8')

if git_HEAD.strip() != remote_HEAD:
# We're not updated! Note that this might mean you're AHEAD of master,
# or on a different repo. At which case, you should know what you're doing.
# Message the owner.
bot.msg(bot.config.core.owner, message_git %
{'latest': remote_HEAD, 'local': git_HEAD })
for admin in bot.config.core.admins:
# Message the admins as well.
bot.msg(admin, message_git %
{'latest': remote_HEAD, 'local': git_HEAD })

0 comments on commit 6a37da5

Please sign in to comment.