[mod-perdu] Added auto fill on ready

[mod-perdu] Added typing on stats commands
This commit is contained in:
Suwako Moriya 2020-04-11 11:52:29 +02:00
parent 9d3488d92c
commit bd622fe698
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5

View File

@ -27,6 +27,9 @@ class MainClass(BaseClassPython):
self.config.init({"channel": 0, "lost_role": 0, "min_delta": datetime.timedelta(minutes=26).total_seconds()})
self.history = {}
async def on_ready(self):
await self.fill_history()
async def on_message(self, message: discord.Message):
# Fill history
if message.author.bot:
@ -111,83 +114,84 @@ class MainClass(BaseClassPython):
async def com_stats(self, message: discord.Message, args, kwargs):
# TODO: Finir sum
if not ((not False or (not False or not ("sum" in args))) or not True):
if message.mentions:
top = self.get_top(only_users=[mention.id for mention in message.mentions] + [message.author.id])
else:
# TOP 5 + auteur
top = self.get_top(top=5, with_user=[message.author.id])
dates = []
new_top = {}
for t in top:
for date, _ in t[1]:
dates.append(date)
dates.sort()
dates.append(datetime.datetime.today() + datetime.timedelta(days=1))
for t in top:
user = t[0]
new_top.update({user: ([dates[0]], [0])})
i = 0
for date, _ in t[1]:
while date < dates[i]:
new_top[user][0].append(dates[i])
new_top[user][1].append(new_top[user][1][-1])
i += 1
new_top[user][0].append(date)
new_top[user][1].append(new_top[user][1][-1] + 1)
to_plot = [t[1][1:] for t in new_top.values()]
np.xlabel("Temps", fontsize=30)
np.ylabel("Score", fontsize=30)
np.title("Évolution du nombre de perdu au cours du temps.", fontsize=40)
np.legend()
file_name = f"/tmp/{time.time()}.png"
np.savefig(file_name, bbox_inches='tight')
await message.channel.send(file=discord.File(file_name))
if "history" in args:
since = datetime.datetime(year=1, month=1, day=1)
debut_message = "la création du salon"
top = 5
if "s" in [k[0] for k in kwargs]:
try:
d = [k[1] for k in kwargs if k[0] == "s"][0]
since = datetime.datetime.now() - datetime.timedelta(days=float(d))
debut_message = humanize.naturalday(since.date(), format='le %d %b')
except ValueError:
pass
if "t" in [k[0] for k in kwargs]:
try:
top = int([k[1] for k in kwargs if k[0] == "t"][0])
except ValueError:
pass
# Si mention, alors uniquement les mentions
if message.mentions:
top = self.get_top(since=since,
only_users=[mention.id for mention in message.mentions])
else:
# TOP 5 + auteur
top = self.get_top(since=since, top=top, with_user=[message.author.id])
new_top = {}
for t in top:
c = 0
counts = []
async with message.channel.typing():
if not ((not False or (not False or not ("sum" in args))) or not True):
if message.mentions:
top = self.get_top(only_users=[mention.id for mention in message.mentions] + [message.author.id])
else:
# TOP 5 + auteur
top = self.get_top(top=5, with_user=[message.author.id])
dates = []
for date, _ in t[1]:
c += 1
counts.append(c)
dates.append(date)
new_top.update({t[0]: (dates, counts)})
np.figure(num=None, figsize=(25, 15), dpi=120, facecolor='w', edgecolor='k')
for user, (dates, counts) in new_top.items():
np.plot_date(dates, counts, linestyle='-', label=str(self.client.get_user(user).name))
np.xlabel("Temps", fontsize=30)
np.ylabel("Score", fontsize=30)
np.legend(fontsize=20)
np.title(f"Évolution du nombre de perdu au cours du temps depuis {debut_message}.", fontsize=35)
file_name = f"/tmp/{time.time()}.png"
np.savefig(file_name, bbox_inches='tight')
await message.channel.send(file=discord.File(file_name))
new_top = {}
for t in top:
for date, _ in t[1]:
dates.append(date)
dates.sort()
dates.append(datetime.datetime.today() + datetime.timedelta(days=1))
for t in top:
user = t[0]
new_top.update({user: ([dates[0]], [0])})
i = 0
for date, _ in t[1]:
while date < dates[i]:
new_top[user][0].append(dates[i])
new_top[user][1].append(new_top[user][1][-1])
i += 1
new_top[user][0].append(date)
new_top[user][1].append(new_top[user][1][-1] + 1)
to_plot = [t[1][1:] for t in new_top.values()]
np.xlabel("Temps", fontsize=30)
np.ylabel("Score", fontsize=30)
np.title("Évolution du nombre de perdu au cours du temps.", fontsize=40)
np.legend()
file_name = f"/tmp/{time.time()}.png"
np.savefig(file_name, bbox_inches='tight')
await message.channel.send(file=discord.File(file_name))
if "history" in args:
since = datetime.datetime(year=1, month=1, day=1)
debut_message = "la création du salon"
top = 5
if "s" in [k[0] for k in kwargs]:
try:
d = [k[1] for k in kwargs if k[0] == "s"][0]
since = datetime.datetime.now() - datetime.timedelta(days=float(d))
debut_message = humanize.naturalday(since.date(), format='le %d %b')
except ValueError:
pass
if "t" in [k[0] for k in kwargs]:
try:
top = int([k[1] for k in kwargs if k[0] == "t"][0])
except ValueError:
pass
# Si mention, alors uniquement les mentions
if message.mentions:
top = self.get_top(since=since,
only_users=[mention.id for mention in message.mentions])
else:
# TOP 5 + auteur
top = self.get_top(since=since, top=top, with_user=[message.author.id])
new_top = {}
for t in top:
c = 0
counts = []
dates = []
for date, _ in t[1]:
c += 1
counts.append(c)
dates.append(date)
new_top.update({t[0]: (dates, counts)})
np.figure(num=None, figsize=(25, 15), dpi=120, facecolor='w', edgecolor='k')
for user, (dates, counts) in new_top.items():
np.plot_date(dates, counts, linestyle='-', label=str(self.client.get_user(user).name))
np.xlabel("Temps", fontsize=30)
np.ylabel("Score", fontsize=30)
np.legend(fontsize=20)
np.title(f"Évolution du nombre de perdu au cours du temps depuis {debut_message}.", fontsize=35)
file_name = f"/tmp/{time.time()}.png"
np.savefig(file_name, bbox_inches='tight')
await message.channel.send(file=discord.File(file_name))
async def command(self, message, args, kwargs):
if message.mentions: