ajout commande changelogs

This commit is contained in:
Mylloon 2021-06-22 14:02:42 +02:00
parent 1520fa7495
commit 904149fcb0
2 changed files with 44 additions and 4 deletions

View file

@ -5,7 +5,7 @@ from discord.ext import commands, tasks
from random import randint, shuffle from random import randint, shuffle
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.reminder import Reminder from utils.reminder import Reminder
from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick, mentionToUser from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick, mentionToUser, getChangelogs
from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString, timestampScreen, getAge, ageLayout, nowCustom from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString, timestampScreen, getAge, ageLayout, nowCustom
def setup(client): def setup(client):
@ -669,3 +669,30 @@ class Utils(commands.Cog):
@cog_ext.cog_slash(name="reminderdelete", description = "Suppprime un rappel.") @cog_ext.cog_slash(name="reminderdelete", description = "Suppprime un rappel.")
async def __reminderdelete(self, ctx, id): async def __reminderdelete(self, ctx, id):
return await self._reminderdelete(ctx, id, True) return await self._reminderdelete(ctx, id, True)
@commands.command(name='changelogs', aliases=["changelog", "changement", "changements"])
async def _changelogs(self, ctx, *version):
"""Affiche les changements de la dernière version ou d'une version précise.\n ➡ Syntaxe: {PREFIX}changelogs/changelog/changement/changements [version] """
fromSlash = False
if len(version) > 0:
if version[-1] == True:
fromSlash = version[-1]
version = version[:-1]
if len(version) > 0:
version = version[0]
else:
version = 'latest'
changes = getChangelogs(version)
if changes == None:
if fromSlash != True:
await ctx.message.add_reaction(emoji = '')
return await ctx.send("Veuillez renseigner un numéro de version valide et existant.")
if fromSlash != True:
await ctx.message.add_reaction(emoji = '')
await ctx.send(f"url: {changes[0]}\nnum de version: {changes[1]}\ntaille du message de changements: {len(changes[2])}")
@cog_ext.cog_slash(name="changelogs", description = "Affiche les changements de la dernière version ou d'une version précise.")
async def __changelogs(self, ctx, version: int = None):
if version == None:
return await self._reminderlist(ctx, True)
else:
return await self._reminderlist(ctx, version, True)

View file

@ -109,4 +109,17 @@ def ligneFormatage(ligne):
return ligne return ligne
def mentionToUser(mention: str): def mentionToUser(mention: str):
"""Récupère une mention et renvois son ID"""
return int(mention[2:-1].replace("!","")) return int(mention[2:-1].replace("!",""))
def getChangelogs(version = 'latest'):
"""Récupère les changements d'une version (par défaut, la dernière en date) et renvois dans l'ordre : url, n° version, changements"""
if version != 'latest':
version = f'tags/v{version}'
changements = requests.get(f"https://api.github.com/repos/Confrerie-du-Kassoulait/KassouBot/releases/{version}").json()
try:
changements["message"] # renvois None si aucune version correspondante n'a été trouvée
return None
except:
pass
return (changements["html_url"], changements["tag_name"][1:], changements["body"])