feat(cli): add telegram bot backup interval management
This commit is contained in:
19
core/cli.py
19
core/cli.py
@ -511,19 +511,26 @@ def warp_status():
|
|||||||
|
|
||||||
|
|
||||||
@cli.command('telegram')
|
@cli.command('telegram')
|
||||||
@click.option('--action', '-a', required=True, help='Action to perform: start or stop', type=click.Choice(['start', 'stop'], case_sensitive=False))
|
@click.option('--action', '-a', required=True, help='Action to perform: start, stop, or set_backup_interval', type=click.Choice(['start', 'stop', 'set_backup_interval'], case_sensitive=False))
|
||||||
@click.option('--token', '-t', required=False, help='Token for running the telegram bot', type=str)
|
@click.option('--token', '-t', required=False, help='Token for running the telegram bot (for start)', type=str)
|
||||||
@click.option('--adminid', '-aid', required=False, help='Telegram admins ID for running the telegram bot', type=str)
|
@click.option('--adminid', '-aid', required=False, help='Telegram admins ID for running the telegram bot (for start)', type=str)
|
||||||
def telegram(action: str, token: str, adminid: str):
|
@click.option('--interval', '-i', required=False, help='Automatic backup interval in hours (for start and set_backup_interval)', type=str)
|
||||||
|
def telegram(action: str, token: str, adminid: str, interval: str):
|
||||||
|
"""Manage the Telegram bot service."""
|
||||||
try:
|
try:
|
||||||
if action == 'start':
|
if action == 'start':
|
||||||
if not token or not adminid:
|
if not token or not adminid:
|
||||||
raise click.UsageError('Error: Both --token and --adminid are required for the start action.')
|
raise click.UsageError('Error: --token and --adminid are required for the start action.')
|
||||||
cli_api.start_telegram_bot(token, adminid)
|
cli_api.start_telegram_bot(token, adminid, interval)
|
||||||
click.echo(f'Telegram bot started successfully.')
|
click.echo(f'Telegram bot started successfully.')
|
||||||
elif action == 'stop':
|
elif action == 'stop':
|
||||||
cli_api.stop_telegram_bot()
|
cli_api.stop_telegram_bot()
|
||||||
click.echo(f'Telegram bot stopped successfully.')
|
click.echo(f'Telegram bot stopped successfully.')
|
||||||
|
elif action == 'set_backup_interval':
|
||||||
|
if not interval:
|
||||||
|
raise click.UsageError('Error: --interval is required for the set_backup_interval action.')
|
||||||
|
cli_api.set_telegram_bot_backup_interval(interval)
|
||||||
|
click.echo(f'Telegram bot backup interval set to {interval} hours.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
click.echo(f'{e}', err=True)
|
click.echo(f'{e}', err=True)
|
||||||
|
|
||||||
|
|||||||
@ -566,17 +566,27 @@ def warp_status() -> str | None:
|
|||||||
return run_cmd(['python3', Command.STATUS_WARP.value])
|
return run_cmd(['python3', Command.STATUS_WARP.value])
|
||||||
|
|
||||||
|
|
||||||
def start_telegram_bot(token: str, adminid: str):
|
def start_telegram_bot(token: str, adminid: str, backup_interval: str = None):
|
||||||
'''Starts the Telegram bot.'''
|
'''Starts the Telegram bot.'''
|
||||||
if not token or not adminid:
|
if not token or not adminid:
|
||||||
raise InvalidInputError('Error: Both --token and --adminid are required for the start action.')
|
raise InvalidInputError('Error: Both --token and --adminid are required for the start action.')
|
||||||
run_cmd(['python3', Command.INSTALL_TELEGRAMBOT.value, 'start', token, adminid])
|
|
||||||
|
|
||||||
|
command = ['python3', Command.INSTALL_TELEGRAMBOT.value, 'start', token, adminid]
|
||||||
|
if backup_interval:
|
||||||
|
command.append(backup_interval)
|
||||||
|
|
||||||
|
run_cmd(command)
|
||||||
|
|
||||||
def stop_telegram_bot():
|
def stop_telegram_bot():
|
||||||
'''Stops the Telegram bot.'''
|
'''Stops the Telegram bot.'''
|
||||||
run_cmd(['python3', Command.INSTALL_TELEGRAMBOT.value, 'stop'])
|
run_cmd(['python3', Command.INSTALL_TELEGRAMBOT.value, 'stop'])
|
||||||
|
|
||||||
|
def set_telegram_bot_backup_interval(backup_interval: str):
|
||||||
|
'''Sets the backup interval for the Telegram bot.'''
|
||||||
|
if not backup_interval:
|
||||||
|
raise InvalidInputError('Error: Backup interval is required.')
|
||||||
|
run_cmd(['python3', Command.INSTALL_TELEGRAMBOT.value, 'set_backup_interval', backup_interval])
|
||||||
|
|
||||||
|
|
||||||
def start_singbox(domain: str, port: int):
|
def start_singbox(domain: str, port: int):
|
||||||
'''Starts Singbox.'''
|
'''Starts Singbox.'''
|
||||||
|
|||||||
Reference in New Issue
Block a user