added prof roles
This commit is contained in:
parent
d4b1586072
commit
bca6e5639c
@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import itertools
|
||||
|
||||
from redbot.core import commands
|
||||
from redbot.core import Config, checks
|
||||
from discord import TextChannel
|
||||
@ -36,7 +38,65 @@ class WynncraftCog(commands.Cog):
|
||||
"archer": 750097050867204246,
|
||||
"warrior": 750097044433272833
|
||||
},
|
||||
"update_msg": 750124413529358467
|
||||
"update_msg": 750124413529358467,
|
||||
"role_professions": {
|
||||
"farming": [
|
||||
743544309059551292, # 0-9
|
||||
750103671077077004, # 10-19
|
||||
750103673178423397, # 20-29
|
||||
750103675195752528, # 30-39
|
||||
750103677011755080, # 40-49
|
||||
750103681046675527, # 50-59
|
||||
750103683349479452, # 60-69
|
||||
750103692182552667, # 70-79
|
||||
750103687589920789, # 80-89
|
||||
750103685295767734, # 90-99
|
||||
750103689536077966, # 100-109
|
||||
750103679314558980, # 110
|
||||
],
|
||||
"mining": [
|
||||
743544348821553305, # 0-9
|
||||
750105003464851508, # 10-19
|
||||
750105011173851176, # 20-29
|
||||
750105019260469288, # 30-39
|
||||
750104996204380211, # 40-49
|
||||
750105001522888874, # 50-59
|
||||
750105005759135805, # 60-69
|
||||
750105016433377380, # 70-79
|
||||
750105008644554783, # 80-89
|
||||
750105013749153792, # 90-99
|
||||
750104998670762075, # 100-109
|
||||
750104994392309801, # 110
|
||||
],
|
||||
"fishing": [
|
||||
743544397152518146, # 0-9
|
||||
750105742127923303, # 10-19
|
||||
750105731482779779, # 20-29
|
||||
750105744774529124, # 30-39
|
||||
750105734615662672, # 40-49
|
||||
750105754739933345, # 50-59
|
||||
750105729284964472, # 60-69
|
||||
750105749899837551, # 70-79
|
||||
750105752374345769, # 80-89
|
||||
750105747219546122, # 90-99
|
||||
750105737254011051, # 100-109
|
||||
750105739716067488, # 110
|
||||
],
|
||||
"woodcutting": [
|
||||
743920688607264818, # 0-9
|
||||
750106425174261771, # 10-19
|
||||
750106428253012048, # 20-29
|
||||
750106431033835570, # 30-39
|
||||
750106433785430126, # 40-49
|
||||
750106436419452949, # 50-59
|
||||
750106438931579032, # 60-69
|
||||
750106441557475430, # 70-79
|
||||
750106444493488129, # 80-89
|
||||
750106446883979326, # 90-99
|
||||
750106449790631937, # 100-109
|
||||
750106452277985301, # 110
|
||||
]
|
||||
}
|
||||
}
|
||||
default_global = {
|
||||
"log": True
|
||||
@ -97,6 +157,7 @@ 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_professions = await self.config.guild(guild).role_professions()
|
||||
guild_id = guild.id
|
||||
online_players = []
|
||||
await self._log("Loop id %s" % guild_id)
|
||||
@ -111,8 +172,10 @@ class WynncraftCog(commands.Cog):
|
||||
r = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % member_name).json()
|
||||
|
||||
max_combat_lvl_class = None
|
||||
best_professions = dict.fromkeys(list(roles_professions.keys()), 0)
|
||||
|
||||
if not r["data"]:
|
||||
await self._log("%s had data %s" % (member_name, r["data"]))
|
||||
await self._log("%s had empty data %s" % (member_name, r["data"]))
|
||||
continue
|
||||
for cl in r["data"][0]["classes"]:
|
||||
if guild_id not in last_status:
|
||||
@ -140,6 +203,11 @@ class WynncraftCog(commands.Cog):
|
||||
# await self._log("cl: %s, max_combat_lvl_class: %s" % (cl, max_combat_lvl_class))
|
||||
max_combat_lvl_class = cl
|
||||
|
||||
# set max_lvl_professions
|
||||
for prof_name in list(roles_professions.keys()):
|
||||
if cl["professions"][prof_name]["level"] > best_professions[prof_name]:
|
||||
best_professions[prof_name] = cl["professions"][prof_name]["level"]
|
||||
|
||||
if r["data"][0]["meta"]["location"]["online"]:
|
||||
await self._log("%s is online" % member_name)
|
||||
online_players.append(r)
|
||||
@ -192,6 +260,27 @@ class WynncraftCog(commands.Cog):
|
||||
await self._log("remove roles: %s" % roles_to_remove)
|
||||
await discord_member.remove_roles(*roles_to_remove)
|
||||
|
||||
# update professions
|
||||
role_ids_to_add = []
|
||||
for prof_name in best_professions:
|
||||
prof_level = best_professions[prof_name]
|
||||
if prof_level < 5: continue # do not add roles for professions < lvl 5
|
||||
prof_role_index = prof_level // 10
|
||||
if prof_role_index > 10: prof_role_index = 10
|
||||
role_ids_to_add.append(roles_professions[prof_name][prof_role_index])
|
||||
|
||||
roles_to_add = []
|
||||
for role_id_to_add in role_ids_to_add:
|
||||
roles_to_add.append(guild.get_role(role_id_to_add))
|
||||
await self._log("Add role: %s" % roles_to_add)
|
||||
await discord_member.add_roles(*roles_to_add)
|
||||
|
||||
all_prof_ids = list(itertools.chain.from_iterable([roles_professions[b] for b in roles_professions]))
|
||||
roles_to_remove = list(filter(lambda role: role.id in all_prof_ids and role.id not in role_id_to_add, 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:
|
||||
await self._log("max_combat_lvl_class: %s, discord_member: %s (name: %s)" % (max_combat_lvl_class, discord_member, member_name))
|
||||
|
||||
@ -203,7 +292,7 @@ class WynncraftCog(commands.Cog):
|
||||
full_text += s + "\n"
|
||||
if not online_players:
|
||||
full_text = "Personne n'est connecté :disappointed_relieved:\n"
|
||||
full_text += "\n*Dernière mise à jour: %s*" % 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.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)
|
||||
|
Loading…
Reference in New Issue
Block a user