update almost connected
This commit is contained in:
parent
26195846e3
commit
f46208250d
@ -7,7 +7,11 @@ from discord import TextChannel
|
|||||||
import discord
|
import discord
|
||||||
import traceback
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
import datetime
|
from datetime import datetime, timezone, timedelta
|
||||||
|
|
||||||
|
|
||||||
|
def utc_to_local(utc_dt):
|
||||||
|
return utc_dt.replace(tzinfo=timezone.utc).astimezone(tz=None)
|
||||||
|
|
||||||
|
|
||||||
class WynncraftCog(commands.Cog):
|
class WynncraftCog(commands.Cog):
|
||||||
@ -160,6 +164,7 @@ class WynncraftCog(commands.Cog):
|
|||||||
roles_professions = await self.config.guild(guild).role_professions()
|
roles_professions = await self.config.guild(guild).role_professions()
|
||||||
guild_id = guild.id
|
guild_id = guild.id
|
||||||
online_players = []
|
online_players = []
|
||||||
|
almost_online_players = []
|
||||||
await self._log("Loop id %s" % guild_id)
|
await self._log("Loop id %s" % guild_id)
|
||||||
try:
|
try:
|
||||||
guild_name = await self.config.guild(guild).guild_name()
|
guild_name = await self.config.guild(guild).guild_name()
|
||||||
@ -200,7 +205,6 @@ class WynncraftCog(commands.Cog):
|
|||||||
|
|
||||||
# get max_combat_lvl_class
|
# get max_combat_lvl_class
|
||||||
if not max_combat_lvl_class or cl["professions"]["combat"]["level"] > max_combat_lvl_class["professions"]["combat"]["level"]:
|
if not max_combat_lvl_class or cl["professions"]["combat"]["level"] > max_combat_lvl_class["professions"]["combat"]["level"]:
|
||||||
# await self._log("cl: %s, max_combat_lvl_class: %s" % (cl, max_combat_lvl_class))
|
|
||||||
max_combat_lvl_class = cl
|
max_combat_lvl_class = cl
|
||||||
|
|
||||||
# set max_lvl_professions
|
# set max_lvl_professions
|
||||||
@ -212,7 +216,14 @@ class WynncraftCog(commands.Cog):
|
|||||||
await self._log("%s is online" % member_name)
|
await self._log("%s is online" % member_name)
|
||||||
online_players.append(r)
|
online_players.append(r)
|
||||||
else:
|
else:
|
||||||
await self._log("%s was offline: %s" % (member_name, r["data"][0]["meta"]["location"]))
|
last_join_dt_utc = datetime.strptime(r["data"][0]["meta"]["lastJoin"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
|
last_join_dt_local = utc_to_local(last_join_dt_utc)
|
||||||
|
|
||||||
|
if last_join_dt_local + timedelta(minutes=10) > datetime.now():
|
||||||
|
await self._log("%s is ALMOST online" % member_name)
|
||||||
|
almost_online_players.append(r)
|
||||||
|
else:
|
||||||
|
await self._log("%s was offline: %s" % (member_name, r["data"][0]["meta"]["location"]))
|
||||||
|
|
||||||
await self._log("Setting roles")
|
await self._log("Setting roles")
|
||||||
# set max_combat_lvl_class role
|
# set max_combat_lvl_class role
|
||||||
@ -290,9 +301,15 @@ class WynncraftCog(commands.Cog):
|
|||||||
for online_player in online_players:
|
for online_player in online_players:
|
||||||
s = ":green_circle: **%s** connecté sur %s" % (online_player["data"][0]["username"], online_player["data"][0]["meta"]["location"]["server"])
|
s = ":green_circle: **%s** connecté sur %s" % (online_player["data"][0]["username"], online_player["data"][0]["meta"]["location"]["server"])
|
||||||
full_text += s + "\n"
|
full_text += s + "\n"
|
||||||
if not online_players:
|
for almost_online_player in almost_online_players:
|
||||||
|
last_join_dt_utc = datetime.strptime(almost_online_player["data"][0]["meta"]["lastJoin"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
|
last_join_dt_local = utc_to_local(last_join_dt_utc)
|
||||||
|
mins = (datetime.now() - last_join_dt_local).total_seconds() // 60
|
||||||
|
s = ":grey_question: **%s** était connecté il y a %s minutes" % (almost_online_player["data"][0]["username"], mins)
|
||||||
|
full_text += s + "\n"
|
||||||
|
if not online_players and not almost_online_players:
|
||||||
full_text = "Personne n'est connecté :disappointed_relieved:\n"
|
full_text = "Personne n'est connecté :disappointed_relieved:\n"
|
||||||
full_text += "\n*Dernière mise à jour: %s*\n*Les vraies informations peuvent prendre jusqu'à 5 minutes de plus*" % datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
full_text += "\n*Dernière mise à jour: %s*\n*Les vraies informations peuvent prendre jusqu'à 5 minutes de plus*" % datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||||
online_channel = self.bot.get_channel(750100968766701708)
|
online_channel = self.bot.get_channel(750100968766701708)
|
||||||
update_msg = await online_channel.fetch_message(await self.config.guild(guild).update_msg())
|
update_msg = await online_channel.fetch_message(await self.config.guild(guild).update_msg())
|
||||||
await update_msg.edit(content=full_text)
|
await update_msg.edit(content=full_text)
|
||||||
|
Loading…
Reference in New Issue
Block a user