|
|
@ -112,14 +112,8 @@ class Extension: |
|
|
|
@discord.app_commands.checks.has_role("Администратор Фактов13") |
|
|
|
async def sync_list_not_have_role(interaction: discord.Interaction): |
|
|
|
await interaction.response.defer(thinking=True) |
|
|
|
current_members:List[discord.Member] = self.core.get_guild(int(self.core.main_server_id)).members |
|
|
|
current_members = [str(i.id) for i in current_members if i.get_role(self.default_role) == None] |
|
|
|
|
|
|
|
not_synced = None |
|
|
|
async with aiohttp.ClientSession(cookies={"secretkey":os.getenv("BACKEND_SECRETKEY")}) as session: |
|
|
|
async with session.post(f"{os.getenv('BACKEND_URL')}/api/discord/sync", ssl=False, json=current_members) as response: |
|
|
|
not_synced = await response.json() |
|
|
|
|
|
|
|
|
|
|
|
not_synced = await self.get_authusers_without_sync() |
|
|
|
message = "Текущий список:\n" |
|
|
|
for uid in not_synced: |
|
|
|
message += f"<@{uid}>\n" |
|
|
@ -128,6 +122,26 @@ class Extension: |
|
|
|
|
|
|
|
return await interaction.followup.send(content=message, ephemeral=True) |
|
|
|
|
|
|
|
async def prepair(self): |
|
|
|
not_synced = await self.get_authusers_without_sync() |
|
|
|
for uid in not_synced: |
|
|
|
try: |
|
|
|
member = self.core.get_guild(self.core.main_server_id).get_member(uid) |
|
|
|
await self.final_stage(member, member.guild, "Автоматически, синхронизация с сайтом, во время иницилизации") |
|
|
|
except Exception as e: |
|
|
|
print(f"[register.prepair] Cannot add role, uid:{uid}, error:{e}") |
|
|
|
traceback.print_exc() |
|
|
|
|
|
|
|
async def get_authusers_without_sync(self): |
|
|
|
current_members:List[discord.Member] = self.core.get_guild(int(self.core.main_server_id)).members |
|
|
|
current_members = [str(i.id) for i in current_members if i.get_role(self.default_role) == None] |
|
|
|
|
|
|
|
not_synced = None |
|
|
|
async with aiohttp.ClientSession(cookies={"secretkey":os.getenv("BACKEND_SECRETKEY")}) as session: |
|
|
|
async with session.post(f"{os.getenv('BACKEND_URL')}/api/discord/sync", ssl=False, json=current_members) as response: |
|
|
|
not_synced = await response.json() |
|
|
|
return not_synced |
|
|
|
|
|
|
|
async def final_stage(self, user: discord.Member, guild: discord.Guild, reason = ""): |
|
|
|
try: |
|
|
|
await user.add_roles(guild.get_role(self.default_role), reason = "Автоматически, зарегистрировался через сайтик" if not reason else reason) |
|
|
@ -148,6 +162,14 @@ class Extension: |
|
|
|
await self.updater() |
|
|
|
await asyncio.sleep(timeout) |
|
|
|
|
|
|
|
async def task_secondary(self, timeout = 60 * 60): |
|
|
|
await self.core.wait_until_ready() |
|
|
|
await asyncio.sleep(5) |
|
|
|
print("[register] update register cache who dont have role") |
|
|
|
while True: |
|
|
|
await self.prepair() |
|
|
|
await asyncio.sleep(timeout) |
|
|
|
|
|
|
|
async def updater(self): |
|
|
|
try: |
|
|
|
hmap = None |
|
|
@ -158,6 +180,8 @@ class Extension: |
|
|
|
if not hmap: |
|
|
|
return |
|
|
|
|
|
|
|
print(f"[register] need sync, payload: {hmap}") |
|
|
|
|
|
|
|
for reg in hmap.get("reg", []): |
|
|
|
try: |
|
|
|
member = self.core.get_guild(self.core.main_server_id).get_member(reg) |
|
|
|