33
44from bot .main import ActBot
55from bot .ui import EmbedX
6+ from db .actor import Actor
67
78
89# ----------------------------------------------------------------------------------------------------
@@ -24,7 +25,48 @@ async def sync(self, interaction: Interaction, global_sync: bool = True):
2425 await interaction .followup .send (
2526 embed = EmbedX .success (
2627 title = "Commands Synchronization" ,
27- description = f"{ count [0 ]} /{ count [1 ]} commands synchronized." ,
28+ description = f"{ count [0 ]} /{ count [1 ]} command(s) synchronized." ,
29+ ),
30+ ephemeral = True ,
31+ )
32+
33+ # ----------------------------------------------------------------------------------------------------
34+ # * Sync Actors
35+ # ----------------------------------------------------------------------------------------------------
36+ @app_commands .guild_only ()
37+ @app_commands .default_permissions (administrator = True )
38+ @app_commands .checks .has_permissions (administrator = True )
39+ @app_commands .command (
40+ description = "Update actors with fresh data from associated guild members" ,
41+ )
42+ async def sync_actors (self , interaction : Interaction ):
43+ await interaction .response .defer (ephemeral = True )
44+ guild = interaction .guild
45+ if not guild :
46+ return
47+ db = self .bot .get_db (guild )
48+ actors = list (db .find (Actor ))
49+ removed_members_count = 0
50+ for actor in actors :
51+ member = None
52+ try :
53+ member = guild .get_member (actor .id ) or await guild .fetch_member (
54+ actor .id
55+ )
56+ except :
57+ pass
58+ if member :
59+ actor .is_member = True
60+ actor .name = member .name
61+ actor .display_name = member .display_name
62+ else :
63+ actor .is_member = False
64+ removed_members_count += 1
65+ db .save_all (actors )
66+ await interaction .followup .send (
67+ embed = EmbedX .success (
68+ title = "Actors Synchronization" ,
69+ description = f"{ len (actors )} actor(s) synchronized.\n { removed_members_count } actor(s) no longer members." ,
2870 ),
2971 ephemeral = True ,
3072 )
0 commit comments