meilleur affichage du temps

This commit is contained in:
Mylloon 2021-06-03 20:14:45 +02:00
parent 08bedb2c5d
commit 38057e610a
2 changed files with 20 additions and 4 deletions

View file

@ -9,7 +9,7 @@ from pytz import timezone
from discord_slash import cog_ext from discord_slash import cog_ext
import shlex import shlex
from utils.core import map_list_among_us, get_age, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs from utils.core import map_list_among_us, get_age, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs
from utils.core import cleanUser, userOrNick, ageLayout, stringTempsVersSecondes, nowTimestampCustom, intToTimestamp, nowTimestampUTC from utils.core import cleanUser, userOrNick, ageLayout, stringTempsVersSecondes, timedeltaToString, intToTimestamp, nowTimestampUTC
from utils.reminder import Reminder from utils.reminder import Reminder
def setup(client): def setup(client):
@ -503,7 +503,7 @@ class Utils(commands.Cog):
if fromSlash != True: if fromSlash != True:
messageID = ctx.message.id messageID = ctx.message.id
Reminder().ajoutReminder(messageID, ctx.channel.id, mention, reminder, now, now + seconds, ctx.author.id) Reminder().ajoutReminder(messageID, ctx.channel.id, mention, reminder, now, now + seconds, ctx.author.id)
return await ctx.send(f"Ok, je t'en parles dans {time} !") return await ctx.send(f"Ok, je t'en parles dans {timedeltaToString(seconds)} !")
await ctx.send(embed = embed) await ctx.send(embed = embed)
@cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.") @cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.")
async def __reminder(self, ctx, time, reminder = None): async def __reminder(self, ctx, time, reminder = None):
@ -529,7 +529,7 @@ class Utils(commands.Cog):
except: except:
pass pass
finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToTimestamp(expired[3]), color = discord.Colour.random()) finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToTimestamp(expired[3]), color = discord.Colour.random())
finalEmbed.set_footer(text=f"Message d'il y a {str(timedelta(seconds = int(nowTimestampUTC()) - expired[3])).replace('days', 'jours')} secondes") finalEmbed.set_footer(text=f"Message d'il y a {timedeltaToString(int(nowTimestampUTC()) - expired[3])}")
links = "" links = ""
findedURLs = getURLsInString(reminder) findedURLs = getURLsInString(reminder)

View file

@ -4,7 +4,7 @@ import requests
import time import time
import os import os
from pytz import timezone from pytz import timezone
from datetime import datetime from datetime import datetime, timedelta
myTimezone = os.environ['TIMEZONE'] myTimezone = os.environ['TIMEZONE']
@ -188,3 +188,19 @@ def nowTimestampUTC():
def intToTimestamp(int): def intToTimestamp(int):
return datetime.fromtimestamp(int) return datetime.fromtimestamp(int)
def timedeltaToString(time):
age = str(timedelta(seconds = time)).replace('days, ', 'jours, :').split(':')
if len(age) == 4:
a = [1, 1, 1, 1] # a pour affichage
if len(age) == 3:
a = [0, 1, 1, 1]
age.insert(0, None)
for i in range(1, 4):
if int(age[i]) == 0:
a[i] = 0
age[0] = age[0] if a[0] == 1 else ''
age[1] = f"{age[1]}h " if a[1] == 1 else ''
age[2] = f"{age[2]}m " if a[2] == 1 else ''
age[3] = f"{age[3]}s" if a[3] == 1 else ''
return ''.join(age)