@@ -19,12 +19,12 @@ pub(crate) use settings::*;
1919#[ derive( BotCommands , Clone ) ]
2020#[ command( rename_rule = "lowercase" , description = "Simple commands" ) ]
2121pub ( crate ) enum UnauthenticatedCommands {
22- #[ command( description = "show help message." ) ]
23- Help ,
2422 #[ command( description = "start the bot." ) ]
2523 Start ,
2624 #[ command( description = "change settings." ) ]
2725 Settings ,
26+ #[ command( description = "show help message." ) ]
27+ Help ,
2828}
2929
3030pub ( crate ) async fn unauthenticated_commands_handler (
@@ -35,17 +35,25 @@ pub(crate) async fn unauthenticated_commands_handler(
3535 cmd : UnauthenticatedCommands ,
3636 dialogue : DiffusionDialogue ,
3737) -> anyhow:: Result < ( ) > {
38+ let chat = msg. chat . id ;
39+ let user = msg. from ( ) . unwrap ( ) . id ;
3840 let text = match cmd {
3941 UnauthenticatedCommands :: Help => {
40- if cfg. chat_is_allowed ( & msg. chat . id )
41- || cfg. chat_is_allowed ( & msg. from ( ) . unwrap ( ) . id . into ( ) )
42- {
43- format ! (
44- "{}\n \n {}\n \n {}" ,
45- UnauthenticatedCommands :: descriptions( ) ,
46- SettingsCommands :: descriptions( ) ,
47- GenCommands :: descriptions( )
48- )
42+ if cfg. chat_is_allowed ( & chat) || cfg. chat_is_allowed ( & user. into ( ) ) {
43+ let unauth = vec ! [ UnauthenticatedCommands :: descriptions( ) ] ;
44+ let settings =
45+ if !cfg. settings . disable_user_settings || cfg. user_is_admin ( & user. into ( ) ) {
46+ vec ! [ SettingsCommands :: descriptions( ) ]
47+ } else {
48+ vec ! [ ]
49+ } ;
50+ let gen = vec ! [ GenCommands :: descriptions( ) ] ;
51+ [ unauth, settings, gen]
52+ . iter ( )
53+ . flatten ( )
54+ . map ( ToString :: to_string)
55+ . collect :: < Vec < _ > > ( )
56+ . join ( "\n \n " )
4957 } else if msg. chat . is_group ( ) || msg. chat . is_supergroup ( ) {
5058 UnauthenticatedCommands :: descriptions ( )
5159 . username_from_me ( & me)
@@ -92,14 +100,6 @@ pub(crate) fn filter_map_settings() -> UpdateHandler<anyhow::Error> {
92100 } )
93101}
94102
95- pub ( crate ) fn admin_filter ( ) -> UpdateHandler < anyhow:: Error > {
96- dptree:: filter ( |cfg : ConfigParameters , upd : Update | {
97- upd. user ( )
98- . map ( |user| cfg. user_is_admin ( & user. id . into ( ) ) )
99- . unwrap_or_default ( )
100- } )
101- }
102-
103103pub ( crate ) fn auth_filter ( ) -> UpdateHandler < anyhow:: Error > {
104104 dptree:: filter ( |cfg : ConfigParameters , upd : Update | {
105105 upd. chat ( )
0 commit comments