auto: add roles classes et métiers automatiquement, et rank de guilde
This commit is contained in:
parent
dd5fa38a3d
commit
b5372d6ae0
@ -20,6 +20,14 @@ class WynncraftCog(commands.Cog):
|
||||
self.bot = bot
|
||||
self.config = Config.get_conf(self, identifier=48775419874)
|
||||
default_guild = {
|
||||
"role_guild_member": 758458266195198003,
|
||||
"role_guild": {
|
||||
"RECRUIT": 743544640052920332,
|
||||
"RECRUITER": 743544826569687160,
|
||||
"CAPTAIN": 750089012097843260,
|
||||
"CHIEF": 743544996774281369,
|
||||
"OWNER": 743544956114698400
|
||||
},
|
||||
"guild_name": None, # OK
|
||||
"ping_levels": False, # OK
|
||||
"ping_channel": None, # OK
|
||||
@ -424,7 +432,9 @@ class WynncraftCog(commands.Cog):
|
||||
for guild in self.bot.guilds:
|
||||
roles_combat_level = await self.config.guild(guild).role_levels()
|
||||
roles_classes = await self.config.guild(guild).role_class()
|
||||
roles_guild = await self.config.guild(guild).role_guild()
|
||||
roles_professions = await self.config.guild(guild).role_professions()
|
||||
role_guild_member = await self.config.guild(guild).role_guild_member()
|
||||
guild_id = guild.id
|
||||
online_players = []
|
||||
almost_online_players = []
|
||||
@ -484,7 +494,7 @@ class WynncraftCog(commands.Cog):
|
||||
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(last_join_dt_local.tzinfo):
|
||||
if last_join_dt_local + timedelta(minutes=30) > datetime.now(last_join_dt_local.tzinfo):
|
||||
await self._log("%s is ALMOST online" % member_name)
|
||||
almost_online_players.append(r)
|
||||
else:
|
||||
@ -496,7 +506,38 @@ class WynncraftCog(commands.Cog):
|
||||
if max_combat_lvl_class and discord_member:
|
||||
await self._log("max_combat_lvl_class and discord_member True")
|
||||
|
||||
# update guild rank
|
||||
if r["data"][0]["guild"]["name"] == "WynncraftFrance":
|
||||
# user is guild member
|
||||
# add guild member role
|
||||
guild_member_role = guild.get_role(role_guild_member)
|
||||
if guild_member_role not in discord_member.roles:
|
||||
await self._log("Add role: %s" % guild_member_role)
|
||||
await discord_member.add_roles(guild_member_role)
|
||||
|
||||
# add guild rank role
|
||||
guild_rank = r["data"][0]["guild"]["rank"]
|
||||
if guild_rank in roles_guild:
|
||||
guild_role_id = roles_guild[guild_rank]
|
||||
rank_role = guild.get_role(guild_role_id)
|
||||
if rank_role not in discord_member.roles:
|
||||
await self._log("Add role: %s" % rank_role)
|
||||
await discord_member.add_roles(rank_role)
|
||||
|
||||
roles_to_remove = list(filter(lambda role: role.id in list(roles_guild.values()) and role.id != guild_role_id, discord_member.roles))
|
||||
if roles_to_remove:
|
||||
await self._log("remove roles: %s" % roles_to_remove)
|
||||
await discord_member.remove_roles(*roles_to_remove)
|
||||
|
||||
else:
|
||||
# remove ranks
|
||||
roles_to_remove = list(filter(lambda role: role.id in list(roles_guild.values()) or role.id == role_guild_member, discord_member.roles))
|
||||
if roles_to_remove:
|
||||
await self._log("remove roles: %s" % roles_to_remove)
|
||||
await discord_member.remove_roles(*roles_to_remove)
|
||||
|
||||
# update level
|
||||
await discord_member.add_roles(guild.get_role(743544189861626017)) # classe
|
||||
max_combat_lvl = max_combat_lvl_class["professions"]["combat"]["level"]
|
||||
combat_role_index = max_combat_lvl // 10
|
||||
if combat_role_index > 10: combat_role_index = 10
|
||||
@ -537,6 +578,7 @@ class WynncraftCog(commands.Cog):
|
||||
await discord_member.remove_roles(*roles_to_remove)
|
||||
|
||||
# update professions
|
||||
await discord_member.add_roles(guild.get_role(750108451287466095)) # métiers
|
||||
role_ids_to_add = []
|
||||
for prof_name in best_professions:
|
||||
prof_level = best_professions[prof_name]
|
||||
|
Loading…
Reference in New Issue
Block a user