update class role
This commit is contained in:
parent
8c5f5dc0f2
commit
8efe6ed009
@ -5,6 +5,7 @@ from discord import TextChannel
|
|||||||
import discord
|
import discord
|
||||||
import traceback
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class WynncraftCog(commands.Cog):
|
class WynncraftCog(commands.Cog):
|
||||||
@ -35,7 +36,7 @@ class WynncraftCog(commands.Cog):
|
|||||||
"archer": 750097050867204246,
|
"archer": 750097050867204246,
|
||||||
"warrior": 750097044433272833
|
"warrior": 750097044433272833
|
||||||
},
|
},
|
||||||
"update_msg": 123456
|
"update_msg": 750124413529358467
|
||||||
}
|
}
|
||||||
default_global = {
|
default_global = {
|
||||||
"log": True
|
"log": True
|
||||||
@ -95,7 +96,9 @@ class WynncraftCog(commands.Cog):
|
|||||||
await self._log("Looping guilds")
|
await self._log("Looping guilds")
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
roles_combat_level = await self.config.guild(guild).role_levels()
|
roles_combat_level = await self.config.guild(guild).role_levels()
|
||||||
|
roles_classes = await self.config.guild(guild).role_class()
|
||||||
guild_id = guild.id
|
guild_id = guild.id
|
||||||
|
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()
|
||||||
@ -137,11 +140,16 @@ class WynncraftCog(commands.Cog):
|
|||||||
# await self._log("cl: %s, max_combat_lvl_class: %s" % (cl, max_combat_lvl_class))
|
# 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
|
||||||
|
|
||||||
|
if r["data"][0]["meta"]["location"]["online"] == "true":
|
||||||
|
online_players.append(r)
|
||||||
|
|
||||||
await self._log("Setting max_combat_lvl_class role")
|
await self._log("Setting max_combat_lvl_class role")
|
||||||
# set max_combat_lvl_class role
|
# set max_combat_lvl_class role
|
||||||
discord_member = discord.utils.find(lambda m: m.display_name == member_name, guild.members)
|
discord_member = discord.utils.find(lambda m: m.display_name == member_name, guild.members)
|
||||||
if max_combat_lvl_class and discord_member:
|
if max_combat_lvl_class and discord_member:
|
||||||
await self._log("max_combat_lvl_class and discord_member True")
|
await self._log("max_combat_lvl_class and discord_member True")
|
||||||
|
|
||||||
|
# update level
|
||||||
max_combat_lvl = max_combat_lvl_class["professions"]["combat"]["level"]
|
max_combat_lvl = max_combat_lvl_class["professions"]["combat"]["level"]
|
||||||
combat_role_index = max_combat_lvl // 10
|
combat_role_index = max_combat_lvl // 10
|
||||||
if combat_role_index > 10: combat_role_index = 10
|
if combat_role_index > 10: combat_role_index = 10
|
||||||
@ -155,8 +163,47 @@ class WynncraftCog(commands.Cog):
|
|||||||
if roles_to_remove:
|
if roles_to_remove:
|
||||||
await self._log("remove roles: %s" % roles_to_remove)
|
await self._log("remove roles: %s" % roles_to_remove)
|
||||||
await discord_member.remove_roles(*roles_to_remove)
|
await discord_member.remove_roles(*roles_to_remove)
|
||||||
|
|
||||||
|
# update class
|
||||||
|
class_name = max_combat_lvl_class["name"]
|
||||||
|
|
||||||
|
class_role_id = None
|
||||||
|
if class_name.startswith("archer") or class_name.startswith("hunter"):
|
||||||
|
class_role_id = roles_classes["archer"]
|
||||||
|
if class_name.startswith("mage") or class_name.startswith("darkwizard"):
|
||||||
|
class_role_id = roles_classes["mage"]
|
||||||
|
if class_name.startswith("assassin") or class_name.startswith("ninja"):
|
||||||
|
class_role_id = roles_classes["assassin"]
|
||||||
|
if class_name.startswith("warrior") or class_name.startswith("knight"):
|
||||||
|
class_role_id = roles_classes["warrior"]
|
||||||
|
if class_name.startswith("shaman") or class_name.startswith("skyseer"):
|
||||||
|
class_role_id = roles_classes["shaman"]
|
||||||
|
|
||||||
|
class_role = guild.get_role(class_role_id)
|
||||||
|
if class_role not in discord_member.roles:
|
||||||
|
await self._log("Add role: %s" % class_role)
|
||||||
|
await discord_member.add_roles(class_role)
|
||||||
|
|
||||||
|
roles_to_remove = list(filter(lambda role: role.id in roles_classes and role.id != class_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:
|
else:
|
||||||
await self._log("max_combat_lvl_class: %s, discord_member: %s (name: %s)" % (max_combat_lvl_class, discord_member, member_name))
|
await self._log("max_combat_lvl_class: %s, discord_member: %s (name: %s)" % (max_combat_lvl_class, discord_member, member_name))
|
||||||
|
|
||||||
|
# update online players
|
||||||
|
full_text = ""
|
||||||
|
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"])
|
||||||
|
full_text += s + "\n"
|
||||||
|
if not online_players:
|
||||||
|
full_text = "Personne n'est connecté :disappointed_relieved:"
|
||||||
|
full_text += "\n*Dernière mise à jour: %s*" % datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")
|
||||||
|
online_channel = self.bot.get_channel(750100968766701708)
|
||||||
|
update_msg = await online_channel.fetch_message(await self.config.guild(guild).update_msg())
|
||||||
|
await update_msg.edit(content=full_text)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
if await self.config.log():
|
if await self.config.log():
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
Loading…
Reference in New Issue
Block a user