add(laucnher|update): add bot.version and --update
This commit is contained in:
parent
712339968c
commit
02d279b6c4
8 changed files with 71 additions and 12 deletions
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
## Launcher requirements :
|
## Launcher requirements :
|
||||||
|
|
||||||
- [ ] Can install the bot
|
- [x] Can install the bot
|
||||||
- [ ] Can launch the bot
|
- [x] Can launch the bot
|
||||||
- [ ] Can propose updates
|
- [ ] Can propose updates
|
||||||
|
|
||||||
## New commands :
|
## New commands :
|
||||||
|
|
5
bot.py
5
bot.py
|
@ -6,11 +6,13 @@ from collections import deque
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
|
import git
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from cogs.utils.config import Config
|
from cogs.utils.config import Config
|
||||||
from cogs.utils.lang import gettext
|
from cogs.utils.lang import gettext
|
||||||
|
from cogs.utils.version import Version
|
||||||
|
|
||||||
description = """
|
description = """
|
||||||
Je suis TuxBot, le bot qui vit de l'OpenSource ! ;)
|
Je suis TuxBot, le bot qui vit de l'OpenSource ! ;)
|
||||||
|
@ -47,6 +49,8 @@ class TuxBot(commands.AutoShardedBot):
|
||||||
self.prefixes = Config('prefixes.json')
|
self.prefixes = Config('prefixes.json')
|
||||||
self.blacklist = Config('blacklist.json')
|
self.blacklist = Config('blacklist.json')
|
||||||
|
|
||||||
|
self.version = Version(10, 0, 0, pre_release='a18', build=git.Repo(search_parent_directories=True).head.object.hexsha)
|
||||||
|
|
||||||
for extension in l_extensions:
|
for extension in l_extensions:
|
||||||
if extension not in unload:
|
if extension not in unload:
|
||||||
try:
|
try:
|
||||||
|
@ -95,6 +99,7 @@ class TuxBot(commands.AutoShardedBot):
|
||||||
self.uptime = datetime.datetime.utcnow()
|
self.uptime = datetime.datetime.utcnow()
|
||||||
|
|
||||||
print(gettext('Ready:') + f' {self.user} (ID: {self.user.id})')
|
print(gettext('Ready:') + f' {self.user} (ID: {self.user.id})')
|
||||||
|
print(self.version)
|
||||||
|
|
||||||
presence: dict = dict(status=discord.Status.dnd)
|
presence: dict = dict(status=discord.Status.dnd)
|
||||||
if self.config.activity is not None:
|
if self.config.activity is not None:
|
||||||
|
|
12
cogs/utils/version.py
Normal file
12
cogs/utils/version.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class Version:
|
||||||
|
def __init__(self, major: int, minor: int, patch: int, **kwargs):
|
||||||
|
self.major: int = major
|
||||||
|
self.minor: int = minor
|
||||||
|
self.patch: int = patch
|
||||||
|
|
||||||
|
self.pre_release = kwargs.get('pre_release', '')
|
||||||
|
self.build = kwargs.get('build', '')
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
build = self.build[:10]
|
||||||
|
return f'v{self.major}.{self.minor}.{self.patch}{self.pre_release}-{build}'
|
51
launcher.py
51
launcher.py
|
@ -3,6 +3,8 @@ import contextlib
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import git
|
||||||
|
import requests
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ def setup_logging():
|
||||||
log.removeHandler(hdlr)
|
log.removeHandler(hdlr)
|
||||||
|
|
||||||
|
|
||||||
def run_bot(unload):
|
def run_bot(unload: list = []):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
|
@ -60,15 +62,46 @@ def run_bot(unload):
|
||||||
bot.run()
|
bot.run()
|
||||||
|
|
||||||
|
|
||||||
@click.group(invoke_without_command=True, options_metavar='[options]')
|
@click.command()
|
||||||
@click.option('-u', '--unload',
|
@click.option('-d', '--unload', multiple=True, type=str, help=gettext('Launch without loading the <TEXT> module'))
|
||||||
multiple=True, type=str,
|
@click.option('-u', '--update', help=gettext('Search for update'), is_flag=True)
|
||||||
help=gettext('Launch without loading the <TEXT> module'))
|
def main(**kwargs):
|
||||||
@click.pass_context
|
if kwargs.get('update'):
|
||||||
def main(ctx, unload):
|
_update()
|
||||||
if ctx.invoked_subcommand is None:
|
|
||||||
|
with setup_logging():
|
||||||
|
run_bot(kwargs.get('unload'))
|
||||||
|
|
||||||
|
|
||||||
|
@click.option('-d', '--update', help=gettext('Search for update'), is_flag=True)
|
||||||
|
def _update():
|
||||||
|
print(gettext('Checking for update...'))
|
||||||
|
|
||||||
|
local = git.Repo(search_parent_directories=True)
|
||||||
|
current = local.head.object.hexsha
|
||||||
|
|
||||||
|
origin = requests.get('https://git.gnous.eu/api/v1/repos/gnouseu/tuxbot-bot/branches/master')
|
||||||
|
last = origin.json().get('commit').get('id')
|
||||||
|
|
||||||
|
if current != last:
|
||||||
|
print(gettext('A new version is available !'))
|
||||||
|
check = input(gettext('Update ? [Y/n]')).lower().strip()
|
||||||
|
|
||||||
|
while check not in ['', 'y', 'n']:
|
||||||
|
check = input(gettext('Update ? [Y/n]'))
|
||||||
|
|
||||||
|
if check == 'y':
|
||||||
|
local.remotes.origin.pull()
|
||||||
|
with setup_logging():
|
||||||
|
run_bot()
|
||||||
|
else:
|
||||||
|
with setup_logging():
|
||||||
|
run_bot()
|
||||||
|
else:
|
||||||
|
print(gettext('Tuxbot is up to date') + '\n')
|
||||||
|
|
||||||
with setup_logging():
|
with setup_logging():
|
||||||
run_bot(unload)
|
run_bot()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -23,6 +23,10 @@ msgstr ""
|
||||||
msgid "Launch without loading the <TEXT> module"
|
msgid "Launch without loading the <TEXT> module"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: launcher.py:73
|
||||||
|
msgid "Search for update"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: bot.py:52
|
#: bot.py:52
|
||||||
msgid "Failed to load extension : "
|
msgid "Failed to load extension : "
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
Binary file not shown.
|
@ -23,6 +23,10 @@ msgstr "Impossible de lancer PostgreSQL..."
|
||||||
msgid "Launch without loading the <TEXT> module"
|
msgid "Launch without loading the <TEXT> module"
|
||||||
msgstr "Lancer sans charger le module <TEXT>"
|
msgstr "Lancer sans charger le module <TEXT>"
|
||||||
|
|
||||||
|
#: launcher.py:73
|
||||||
|
msgid "Search for update"
|
||||||
|
msgstr "Rechercher les mises à jour"
|
||||||
|
|
||||||
#: bot.py:52
|
#: bot.py:52
|
||||||
msgid "Failed to load extension : "
|
msgid "Failed to load extension : "
|
||||||
msgstr "Impossible de charger l'extension : "
|
msgstr "Impossible de charger l'extension : "
|
||||||
|
|
|
@ -3,3 +3,4 @@ jishaku
|
||||||
lxml
|
lxml
|
||||||
click
|
click
|
||||||
asyncpg>=0.12.0
|
asyncpg>=0.12.0
|
||||||
|
gitpython
|
Loading…
Reference in a new issue