meilleur affichage du temps
This commit is contained in:
parent
08bedb2c5d
commit
38057e610a
2 changed files with 20 additions and 4 deletions
|
@ -9,7 +9,7 @@ from pytz import timezone
|
|||
from discord_slash import cog_ext
|
||||
import shlex
|
||||
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
|
||||
|
||||
def setup(client):
|
||||
|
@ -503,7 +503,7 @@ class Utils(commands.Cog):
|
|||
if fromSlash != True:
|
||||
messageID = ctx.message.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)
|
||||
@cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.")
|
||||
async def __reminder(self, ctx, time, reminder = None):
|
||||
|
@ -529,7 +529,7 @@ class Utils(commands.Cog):
|
|||
except:
|
||||
pass
|
||||
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 = ""
|
||||
findedURLs = getURLsInString(reminder)
|
||||
|
|
|
@ -4,7 +4,7 @@ import requests
|
|||
import time
|
||||
import os
|
||||
from pytz import timezone
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
myTimezone = os.environ['TIMEZONE']
|
||||
|
||||
|
@ -188,3 +188,19 @@ def nowTimestampUTC():
|
|||
|
||||
def intToTimestamp(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)
|
||||
|
|
Reference in a new issue