connexions: test
This commit is contained in:
parent
6530558d4a
commit
5b56fa597d
@ -356,6 +356,45 @@ class WynncraftCog(commands.Cog):
|
||||
else:
|
||||
await ctx.send(":x: Si tu lis ce message c'est que quelque chose s'est mal passé car il est normalement impossible que je ne puisse pas te donner de conseils ! Contacte <@158370947097821185> pour l'informer de ce bug.")
|
||||
|
||||
@commands.command()
|
||||
async def connexions(self, ctx, channel: TextChannel):
|
||||
def td_format(seconds):
|
||||
periods = [
|
||||
('year', 60 * 60 * 24 * 365),
|
||||
('month', 60 * 60 * 24 * 30),
|
||||
('day', 60 * 60 * 24),
|
||||
('hour', 60 * 60),
|
||||
('minute', 60),
|
||||
('second', 1)
|
||||
]
|
||||
|
||||
strings = []
|
||||
for period_name, period_seconds in periods:
|
||||
if seconds > period_seconds:
|
||||
period_value, seconds = divmod(seconds, period_seconds)
|
||||
has_s = 's' if period_value > 1 else ''
|
||||
strings.append("%s %s%s" % (period_value, period_name, has_s))
|
||||
break
|
||||
|
||||
return ", ".join(strings)
|
||||
|
||||
connexions = {}
|
||||
r = requests.get("https://api.wynncraft.com/public_api.php?action=guildStats&command=WynncraftFrance").json()
|
||||
t = None
|
||||
for member in r["members"]:
|
||||
player_name = member["name"]
|
||||
p_req = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % player_name).json()
|
||||
try:
|
||||
last_join_dt_utc = datetime.strptime(p_req["data"][0]["meta"]["lastJoin"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
last_join_dt_local = utc_to_local(last_join_dt_utc)
|
||||
now = datetime.now(last_join_dt_local.tzinfo)
|
||||
connexions[player_name] = (now - last_join_dt_local).total_seconds()
|
||||
except:
|
||||
continue
|
||||
|
||||
connexions = {k: v for k, v in sorted(connexions.items(), key=lambda item: item[1], reverse=True)}
|
||||
await ctx.send("\n".join("%s: %s" % (key, td_format(val)) for (key, val) in connexions.items()))
|
||||
|
||||
@commands.command()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
async def ping_channel(self, ctx, channel: TextChannel):
|
||||
|
Loading…
Reference in New Issue
Block a user