[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

@ -9,6 +9,7 @@ from collections import namedtuple
from pathlib import Path from pathlib import Path
from random import SystemRandom from random import SystemRandom
from string import ascii_letters, digits from string import ascii_letters, digits
from distutils.version import StrictVersion
import aiohttp import aiohttp
import discord import discord
@ -68,6 +69,10 @@ class Core:
app_info = await self.bot.application_info() app_info = await self.bot.application_info()
owner = app_info.owner owner = app_info.owner
async with aiohttp.ClientSession() as session:
async with session.get("http://pypi.python.org/pypi/red-discordbot/json") as r:
data = await r.json()
outdated = StrictVersion(data["info"]["version"]) > StrictVersion(__version__)
about = ( about = (
"This is an instance of [Red, an open source Discord bot]({}) " "This is an instance of [Red, an open source Discord bot]({}) "
"created by [Twentysix]({}) and [improved by many]({}).\n\n" "created by [Twentysix]({}) and [improved by many]({}).\n\n"
@ -81,7 +86,13 @@ class Core:
embed.add_field(name="Python", value=python_version) embed.add_field(name="Python", value=python_version)
embed.add_field(name="discord.py", value=dpy_version) embed.add_field(name="discord.py", value=dpy_version)
embed.add_field(name="Red version", value=red_version) embed.add_field(name="Red version", value=red_version)
if outdated:
embed.add_field(name="Outdated", value="Yes, {} is available".format(
data["info"]["version"]
)
)
embed.add_field(name="About Red", value=about, inline=False) embed.add_field(name="About Red", value=about, inline=False)
embed.set_footer(text="Bringing joy since 02 Jan 2016 (over " embed.set_footer(text="Bringing joy since 02 Jan 2016 (over "
"{} days ago!)".format(days_since)) "{} days ago!)".format(days_since))
try: try:

View File

@ -2,6 +2,9 @@ import sys
import codecs import codecs
import datetime import datetime
import logging import logging
from distutils.version import StrictVersion
import aiohttp
import pkg_resources import pkg_resources
import traceback import traceback
from pkg_resources import DistributionNotFound 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))) 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 = [] INFO2 = []
sentry = await bot.db.enable_sentry() sentry = await bot.db.enable_sentry()