mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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:
parent
40c37b5c06
commit
f378ea0d2e
@ -9,6 +9,7 @@ from collections import namedtuple
|
||||
from pathlib import Path
|
||||
from random import SystemRandom
|
||||
from string import ascii_letters, digits
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
@ -68,6 +69,10 @@ class Core:
|
||||
app_info = await self.bot.application_info()
|
||||
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 = (
|
||||
"This is an instance of [Red, an open source Discord bot]({}) "
|
||||
"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="discord.py", value=dpy_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.set_footer(text="Bringing joy since 02 Jan 2016 (over "
|
||||
"{} days ago!)".format(days_since))
|
||||
try:
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user