change gitlab changelogs + new loading of env variables part. 2

This commit is contained in:
Mylloon 2021-07-28 03:26:21 +02:00
parent 155ff9244e
commit 92fe7a0e92

View file

@ -1,12 +1,10 @@
import discord import discord
from os import environ, path
from re import findall
from discord.ext import commands, tasks 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 from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick
from utils.core import mySendHidden, mentionToUser, getChangelogs, isSlash from utils.core import mySendHidden, mentionToUser, getChangelogs, getActualVersion, isSlash, load
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):
@ -16,7 +14,7 @@ class Utils(commands.Cog):
"""Commandes essentielles.""" """Commandes essentielles."""
def __init__(self, client): def __init__(self, client):
self.client = client self.client = client
self.customTimezone = environ['TIMEZONE'] self.customTimezone = load(["TIMEZONE"])["TIMEZONE"]
self._reminderLoop.start() self._reminderLoop.start()
@commands.command(name='ping') @commands.command(name='ping')
@ -235,8 +233,7 @@ class Utils(commands.Cog):
voice = len(voice_channels) voice = len(voice_channels)
nombreServeur = len(self.client.guilds) nombreServeur = len(self.client.guilds)
with open(path.join(path.dirname(path.dirname(path.dirname(__file__))), "README.md"), "r") as file: version = getActualVersion()
version = findall(r'https://img.shields.io/badge/version-(\d+\.\d+)', file.readlines()[2])[0]
embed.add_field(name = "Dev", value = f"[{appinfo.owner}](https://gitlab.com/Mylloon)") embed.add_field(name = "Dev", value = f"[{appinfo.owner}](https://gitlab.com/Mylloon)")
embed.add_field(name = f"Serveur{'s' if nombreServeur > 1 else ''}", value = f"`{nombreServeur}`") embed.add_field(name = f"Serveur{'s' if nombreServeur > 1 else ''}", value = f"`{nombreServeur}`")
@ -247,8 +244,8 @@ class Utils(commands.Cog):
embed.add_field(name = "Timezone", value = f"`{self.customTimezone}`") embed.add_field(name = "Timezone", value = f"`{self.customTimezone}`")
embed.add_field(name = "Version", value = f"`{version}`") embed.add_field(name = "Version", value = f"`{version}`")
changes = getChangelogs(version) changes = getChangelogs(version)
if changes != None and changes != 0: if changes[0] == 200:
embed.add_field(name = "Changements", value = f"[Lien Gitlab]({changes[0]})") embed.add_field(name = "Changements", value = f"[Lien Gitlab]({changes[1]})")
embed.set_footer(text = f"Basé sur discord.py {discord.__version__}") embed.set_footer(text = f"Basé sur discord.py {discord.__version__}")
try: try:
if fromSlash != True: if fromSlash != True:
@ -630,22 +627,25 @@ class Utils(commands.Cog):
"""Affiche les changements de la dernière version ou d'une version précise.\n ➡ Syntaxe: {PREFIX}changelogs/changelog/changement/changements [version]""" """Affiche les changements de la dernière version ou d'une version précise.\n ➡ Syntaxe: {PREFIX}changelogs/changelog/changement/changements [version]"""
version, fromSlash, _ = isSlash(version) version, fromSlash, _ = isSlash(version)
if not version: if not version:
version = 'latest' version = 'actual'
changes = getChangelogs(version.replace(',', '.')) changes = getChangelogs(version.replace(',', '.'))
if changes == None or changes == 0: if changes[0] != 200:
if fromSlash != True: if fromSlash != True:
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')
if changes == None: if changes[0] == 404:
message = "Veuillez renseigner un numéro de version valide et existant." message = "Veuillez renseigner un numéro de version valide et existant. Peut-être que vous utilisez une version de développement."
elif changes[0] == 429:
message = "Trop de requêtes sur l'API de Gitlab, réessayez plus tard."
else: else:
message = "Trop de requêtes sur l'API de Github, réessayez plus tard." message = f"Erreur API inconnue ({changes[0]})."
return await mySendHidden(ctx, fromSlash, message) return await mySendHidden(ctx, fromSlash, message)
if fromSlash != True: if fromSlash != True:
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')
if len(changes[2]) > 2048: changements = changes[3].replace("## ", "").replace("# ", "")
changes[2] = f"{changes[2][:1900]}..." if len(changements) > 2048:
embed = discord.Embed(description = f"[lien vers la page Github]({changes[0]})\n\n{changes[2]}", color = discord.Colour.random()) changements = f"{changements[:1900]}..."
embed.set_author(name = f"Changements de la v{changes[1]}") embed = discord.Embed(description = f"[lien vers la page Gitlab]({changes[1]})\n\n{changements}", color = discord.Colour.random())
embed.set_author(name = f"Changements de la v{changes[2]}")
await ctx.send(embed = embed) await ctx.send(embed = embed)
@cog_ext.cog_slash(name="changelogs", description = "Affiche les changements de la dernière version ou d'une version précise.") @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 = None): async def __changelogs(self, ctx, version = None):