feat: use discord new time format
This commit is contained in:
@@ -3,8 +3,6 @@ from datetime import timedelta
|
||||
import calendar
|
||||
|
||||
from utils import (
|
||||
str_date,
|
||||
str_datetime,
|
||||
from_now,
|
||||
plural,
|
||||
percent,
|
||||
@@ -60,24 +58,24 @@ class Frequency:
|
||||
if self.dates[0].hour <= busiest_hour and self.dates[-1].hour >= busiest_hour:
|
||||
n_hours += 1
|
||||
ret = [
|
||||
f"- **earliest message**: {str_datetime(self.dates[0])} ({from_now(self.dates[0])})",
|
||||
f"- **latest message**: {str_datetime(self.dates[-1])} ({from_now(self.dates[-1])})",
|
||||
f"- **earliest message**: {from_now(self.dates[0])}",
|
||||
f"- **latest message**: {from_now(self.dates[-1])}",
|
||||
f"- **messages/day**: {precise(total_msg/delta.days, precision=3)}",
|
||||
f"- **busiest day of week**: {calendar.day_name[busiest_weekday]} (~{precise(week[busiest_weekday]/n_weekdays, precision=3)} msg, {percent(week[busiest_weekday]/total_msg)})",
|
||||
f"- **quietest day of week**: {calendar.day_name[quietest_weekday]} (~{precise(week[quietest_weekday]/n_weekdays, precision=3)} msg, {percent(week[quietest_weekday]/total_msg)})"
|
||||
if week[quietest_weekday] > 0 else "",
|
||||
f"- **busiest day ever**: {str_date(self.busiest_day)} ({from_now(self.busiest_day)}, {self.busiest_day_count} msg)"
|
||||
f"- **busiest day ever**: {from_now(self.busiest_day)} ({self.busiest_day_count} msg)"
|
||||
if self.busiest_day is not None
|
||||
else "",
|
||||
f"- **messages/hour**: {precise(total_msg*3600/delta.total_seconds(), precision=3)}",
|
||||
f"- **busiest hour of day**: {busiest_hour:0>2}:00 (~{precise(day[busiest_hour]/n_hours, precision=3)} msg, {percent(day[busiest_hour]/total_msg)})",
|
||||
f"- **quietest hour of day**: {quietest_hour:0>2}:00 (~{precise(day[quietest_hour]/n_hours, precision=3)} msg, {percent(day[quietest_hour]/total_msg)})"
|
||||
if day[quietest_hour] > 0 else "",
|
||||
f"- **busiest hour ever**: {str_datetime(self.busiest_hour)} ({from_now(self.busiest_hour)}, {self.busiest_hour_count} msg)",
|
||||
f"- **longest break**: {plural(round(self.longest_break.total_seconds()/3600), 'hour')} ({plural(self.longest_break.days,'day')}) from {str_datetime(self.longest_break_start)} ({from_now(self.longest_break_start)})",
|
||||
f"- **busiest hour ever**: {from_now(self.busiest_hour)} ({self.busiest_hour_count} msg)",
|
||||
f"- **longest break**: {plural(round(self.longest_break.total_seconds()/3600), 'hour')} ({plural(self.longest_break.days,'day')}), started {from_now(self.longest_break_start)}",
|
||||
f"- **avg. streak**: {precise(sum(self.streaks)/len(self.streaks), precision=3)} msg",
|
||||
f"- **longest streak**: {self.longest_streak:,} msg from {str_datetime(self.longest_streak_start)} ({from_now(self.longest_streak_start)})"
|
||||
f"- **longest streak**: {self.longest_streak:,} msg, started {from_now(self.longest_streak_start)}"
|
||||
if member_specific
|
||||
else f"- **longest streak**: {mention(self.longest_streak_author)} ({self.longest_streak:,} msg from {str_datetime(self.longest_streak_start)}, {from_now(self.longest_streak_start)})",
|
||||
else f"- **longest streak**: {mention(self.longest_streak_author)} ({self.longest_streak:,} msg, started {from_now(self.longest_streak_start)})",
|
||||
]
|
||||
return ret
|
||||
|
||||
@@ -6,7 +6,6 @@ import random
|
||||
from utils import (
|
||||
mention,
|
||||
from_now,
|
||||
str_datetime,
|
||||
message_link,
|
||||
SPLIT_TOKEN,
|
||||
FilterLevel,
|
||||
@@ -78,7 +77,7 @@ class History:
|
||||
|
||||
return [
|
||||
intro,
|
||||
f"{str_datetime(message.created_at)} ({from_now(message.created_at)}) {mention(message.author)} sent:",
|
||||
f"{from_now(message.created_at)}, {mention(message.author)} sent:",
|
||||
f"<{message_link(message)}>",
|
||||
SPLIT_TOKEN,
|
||||
image,
|
||||
@@ -107,7 +106,7 @@ class History:
|
||||
|
||||
return [
|
||||
intro,
|
||||
f"{str_datetime(message.created_at)} ({from_now(message.created_at)}) {mention(message.author)} said:",
|
||||
f"{from_now(message.created_at)}, {mention(message.author)} said:",
|
||||
*text,
|
||||
f"<{message_link(message)}>",
|
||||
]
|
||||
|
||||
+4
-8
@@ -6,6 +6,7 @@ import discord
|
||||
import math
|
||||
from datetime import datetime, timedelta
|
||||
import re
|
||||
import time
|
||||
import dateutil.parser
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
@@ -290,11 +291,11 @@ def parse_time(src: str) -> datetime:
|
||||
|
||||
|
||||
def str_date(date: datetime) -> str:
|
||||
return date.strftime("%d %b. %Y") # 12 Jun. 2018
|
||||
return f"<t:{int(time.mktime(date.timetuple()))}:D>"
|
||||
|
||||
|
||||
def str_datetime(date: datetime) -> str:
|
||||
return date.strftime("%H:%M, %d %b. %Y") # 12:05, 12 Jun. 2018
|
||||
return f"<t:{int(time.mktime(date.timetuple()))}:f>"
|
||||
|
||||
|
||||
def str_delta(delay: timedelta) -> str:
|
||||
@@ -322,12 +323,7 @@ def str_delta(delay: timedelta) -> str:
|
||||
def from_now(src: Optional[datetime]) -> str:
|
||||
if src is None:
|
||||
return "never"
|
||||
output = str_delta(datetime.utcnow() - src)
|
||||
if output == "no time":
|
||||
return "now"
|
||||
elif output == "one day":
|
||||
return "yesterday"
|
||||
return output + " ago"
|
||||
return f"<t:{int(time.mktime(src.timetuple()))}:R>"
|
||||
|
||||
|
||||
# APP SPECIFIC
|
||||
|
||||
Reference in New Issue
Block a user