@@ -4,8 +4,7 @@ use serenity::all::{GuildId, Http, UserId};
44use sqlx:: { Pool , Row , Sqlite , query} ;
55use std:: sync:: Arc ;
66
7- pub fn get_panel_permissions_cache (
8- ) -> Arc < moka:: future:: Cache < String , Vec < PanelPermission > > > {
7+ pub fn get_panel_permissions_cache ( ) -> Arc < moka:: future:: Cache < String , Vec < PanelPermission > > > {
98 use std:: sync:: OnceLock ;
109 static CACHE : OnceLock < Arc < moka:: future:: Cache < String , Vec < PanelPermission > > > > =
1110 OnceLock :: new ( ) ;
@@ -41,11 +40,7 @@ pub async fn is_super_admin(
4140
4241 if let Ok ( member) = guild_id_obj. member ( bot_http, user_id_obj) . await {
4342 for role_id in & member. roles {
44- if config
45- . bot
46- . panel_super_admin_roles
47- . contains ( & role_id. get ( ) )
48- {
43+ if config. bot . panel_super_admin_roles . contains ( & role_id. get ( ) ) {
4944 return true ;
5045 }
5146 }
@@ -78,9 +73,7 @@ pub async fn get_user_panel_permissions(
7873 PanelPermission :: ManageApiKeys ,
7974 PanelPermission :: ManagePermissions ,
8075 ] ;
81- cache
82- . insert ( user_id. to_string ( ) , permissions. clone ( ) )
83- . await ;
76+ cache. insert ( user_id. to_string ( ) , permissions. clone ( ) ) . await ;
8477 return permissions;
8578 }
8679
@@ -90,6 +83,8 @@ pub async fn get_user_panel_permissions(
9083 PanelPermission :: ManageBot ,
9184 PanelPermission :: ManageConfig ,
9285 PanelPermission :: ManageTickets ,
86+ PanelPermission :: ManageApiKeys ,
87+ PanelPermission :: ManagePermissions ,
9388 ] ;
9489 }
9590
@@ -114,16 +109,33 @@ pub async fn get_user_panel_permissions(
114109 let user_id_num = match user_id. parse :: < u64 > ( ) {
115110 Ok ( id) => id,
116111 Err ( _) => {
117- cache
118- . insert ( user_id. to_string ( ) , permissions. clone ( ) )
119- . await ;
112+ cache. insert ( user_id. to_string ( ) , permissions. clone ( ) ) . await ;
120113 return permissions;
121114 }
122115 } ;
123116
124117 let guild_id_obj = GuildId :: new ( guild_id) ;
125118 let user_id_obj = UserId :: new ( user_id_num) ;
126119
120+ let everyone_role_id = guild_id. to_string ( ) ;
121+ if let Ok ( rows) = query (
122+ "SELECT permission FROM panel_permissions WHERE subject_type = 'role' AND subject_id = ?" ,
123+ )
124+ . bind ( & everyone_role_id)
125+ . fetch_all ( db_pool)
126+ . await
127+ {
128+ for row in rows {
129+ if let Ok ( perm_str) = row. try_get :: < String , _ > ( "permission" ) {
130+ if let Some ( perm) = PanelPermission :: from_str ( & perm_str) {
131+ if !permissions. contains ( & perm) {
132+ permissions. push ( perm) ;
133+ }
134+ }
135+ }
136+ }
137+ }
138+
127139 if let Ok ( member) = guild_id_obj. member ( bot_http, user_id_obj) . await {
128140 for role_id in & member. roles {
129141 let role_id_str = role_id. get ( ) . to_string ( ) ;
@@ -147,9 +159,7 @@ pub async fn get_user_panel_permissions(
147159 }
148160 }
149161
150- cache
151- . insert ( user_id. to_string ( ) , permissions. clone ( ) )
152- . await ;
162+ cache. insert ( user_id. to_string ( ) , permissions. clone ( ) ) . await ;
153163 permissions
154164}
155165
0 commit comments