mirror of
				https://github.com/cdryzun/tg_bot_collections.git
				synced 2025-11-04 16:56:43 +08:00 
			
		
		
		
	feat(argparse): show available commands as choices for disable_command option
This commit is contained in:
		@ -80,3 +80,13 @@ def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None:
 | 
				
			|||||||
    if all_commands:
 | 
					    if all_commands:
 | 
				
			||||||
        bot.set_my_commands(all_commands)
 | 
					        bot.set_my_commands(all_commands)
 | 
				
			||||||
        print("Setting commands done.")
 | 
					        print("Setting commands done.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def available_commands() -> list[str]:
 | 
				
			||||||
 | 
					    commands = []
 | 
				
			||||||
 | 
					    this_path = Path(__file__).parent
 | 
				
			||||||
 | 
					    for child in this_path.iterdir():
 | 
				
			||||||
 | 
					        if child.name.startswith("_"):
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        commands.append(child.stem)
 | 
				
			||||||
 | 
					    return commands
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								tg.py
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								tg.py
									
									
									
									
									
								
							@ -2,7 +2,7 @@ import argparse
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from telebot import TeleBot
 | 
					from telebot import TeleBot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from handlers import load_handlers
 | 
					from handlers import available_commands, load_handlers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
@ -19,6 +19,7 @@ def main():
 | 
				
			|||||||
        dest="disable_commands",
 | 
					        dest="disable_commands",
 | 
				
			||||||
        help="Specify a command to disable. Can be used multiple times.",
 | 
					        help="Specify a command to disable. Can be used multiple times.",
 | 
				
			||||||
        default=[],
 | 
					        default=[],
 | 
				
			||||||
 | 
					        choices=available_commands(),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    options = parser.parse_args()
 | 
					    options = parser.parse_args()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user