[V3 Core] add update check (#1388)

* [V3 Core] add update check

* [V3 Core] have it DM the owner if out of date
This commit is contained in:
palmtree5
2018-03-05 14:21:01 -09:00
committed by Tobotimus
parent 40c37b5c06
commit f378ea0d2e
2 changed files with 32 additions and 0 deletions

View File

@@ -2,6 +2,9 @@ import sys
import codecs
import datetime
import logging
from distutils.version import StrictVersion
import aiohttp
import pkg_resources
import traceback
from pkg_resources import DistributionNotFound
@@ -106,6 +109,24 @@ def init_events(bot, cli_flags):
INFO.append('{} cogs with {} commands'.format(len(bot.cogs), len(bot.commands)))
async with aiohttp.ClientSession() as session:
async with session.get("http://pypi.python.org/pypi/red-discordbot/json") as r:
data = await r.json()
if StrictVersion(data["info"]["version"]) > StrictVersion(red_version):
INFO.append(
"Outdated version! {} is available "
"but you're using {}".format(data["info"]["version"], red_version)
)
owner = discord.utils.get(bot.get_all_members(), id=bot.owner_id)
try:
await owner.send(
"Your Red instance is out of date! {} is the current "
"version, however you are using {}!".format(
data["info"]["version"], red_version
)
)
except:
pass
INFO2 = []
sentry = await bot.db.enable_sentry()