commit 40033dc0f0a86933e0082767e4cbb1110fa53e42
parent 6177324461bc7678d9948ac49bbb372ab3d01fe8
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Fri, 22 Jan 2021 12:32:23 -0800
Implement stats method.
Diffstat:
| M | bot.py | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 45 insertions(+), 0 deletions(-)
diff --git a/bot.py b/bot.py
@@ -43,6 +43,7 @@ class Message:
def __init__(self, obj):
self.channel = obj.channel.id
self.id = obj.id
+ self.timestamp = obj.created_at
self.author = f"{obj.author.name}#{obj.author.discriminator}"
self.number = int(re.findall("^[0-9,]+", obj.content)[0].replace(",",""))
@@ -123,6 +124,50 @@ class Countdown:
except:
pass
+ def stats(self):
+ """
+ Get countdown statistics.
+
+ Returns
+ -------
+ dict
+ A dictionary containing countdown statistics.
+ """
+
+ # Get start/current number
+ if (len(self.messages) > 0):
+ start = self.messages[0].number
+ current = self.messages[-1].number
+ else:
+ start = None
+ current = None
+
+ # Get list of progress
+ progress = []
+ for message in self.messages:
+ progress += [{
+ "time":message.timestamp,
+ "progress":message.number
+ }]
+
+ # Get author contributions
+ contributions = []
+ authors = list(set([x.author for x in self.messages]))
+ for author in authors:
+ contributions += [{
+ "author":author,
+ "contributions":len([x for x in self.messages if x.author == author]),
+ }]
+ contributions = sorted(contributions, key=lambda x: x["contributions"], reverse=True)
+
+ # Return stats
+ return {
+ "start": start,
+ "current": current,
+ "progress": progress,
+ "contributions": contributions,
+ }
+
# Load list of channels