Change !sub list/del/on/off to use line numbers
!sub list now shows numbered lines; del/on/off operate by line number instead of internal rule id — simpler to use from chat. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
51bd0b4b03
commit
4fdde9a9dc
@ -143,17 +143,27 @@ class Bot():
|
||||
return "Already exists: {0} [{1}] '{2}' -> {3}".format(src, ftype, value, dst)
|
||||
return "Added #{0}: {1}".format(rule['id'], rule.get('name', ''))
|
||||
if cmd in ('del', 'rm', 'delete'):
|
||||
sub_id = int(parts[2])
|
||||
ok = self.__config.remove_subscription(sub_id)
|
||||
return "Removed #{0}".format(sub_id) if ok else "Not found: #{0}".format(sub_id)
|
||||
line_no = int(parts[2])
|
||||
subs = self.__config.list_subscriptions()
|
||||
if line_no < 1 or line_no > len(subs):
|
||||
return "No such line: {0} (total: {1})".format(line_no, len(subs))
|
||||
sub_id = subs[line_no - 1]['id']
|
||||
self.__config.remove_subscription(sub_id)
|
||||
return "Removed line {0}".format(line_no)
|
||||
if cmd in ('on', 'enable'):
|
||||
sub_id = int(parts[2])
|
||||
ok = self.__config.set_enabled(sub_id, True)
|
||||
return "Enabled #{0}".format(sub_id) if ok else "Not found: #{0}".format(sub_id)
|
||||
line_no = int(parts[2])
|
||||
subs = self.__config.list_subscriptions()
|
||||
if line_no < 1 or line_no > len(subs):
|
||||
return "No such line: {0} (total: {1})".format(line_no, len(subs))
|
||||
self.__config.set_enabled(subs[line_no - 1]['id'], True)
|
||||
return "Enabled line {0}".format(line_no)
|
||||
if cmd in ('off', 'disable'):
|
||||
sub_id = int(parts[2])
|
||||
ok = self.__config.set_enabled(sub_id, False)
|
||||
return "Disabled #{0}".format(sub_id) if ok else "Not found: #{0}".format(sub_id)
|
||||
line_no = int(parts[2])
|
||||
subs = self.__config.list_subscriptions()
|
||||
if line_no < 1 or line_no > len(subs):
|
||||
return "No such line: {0} (total: {1})".format(line_no, len(subs))
|
||||
self.__config.set_enabled(subs[line_no - 1]['id'], False)
|
||||
return "Disabled line {0}".format(line_no)
|
||||
except (ValueError, IndexError):
|
||||
return self.__sub_help()
|
||||
return self.__sub_help()
|
||||
@ -170,23 +180,24 @@ class Bot():
|
||||
if not subs:
|
||||
return "No subscriptions"
|
||||
lines = []
|
||||
for s in subs:
|
||||
for i, s in enumerate(subs, start=1):
|
||||
flt = s.get('filter', {})
|
||||
act = s.get('action', {})
|
||||
status = 'on' if s.get('enabled', True) else 'off'
|
||||
name = s.get('name', '')
|
||||
lines.append("#{0} [{1}] {2} {3}:'{4}' -> {5}{6}".format(
|
||||
s.get('id'), status, s.get('srcChatId'),
|
||||
flt.get('type'), flt.get('value'), act.get('chatId'),
|
||||
" ({0})".format(name) if name else ""))
|
||||
lines.append("{0}. [{1}] {2}{3}".format(
|
||||
i, status,
|
||||
name if name else "{0} {1}:'{2}' -> {3}".format(
|
||||
s.get('srcChatId'), flt.get('type'), flt.get('value'), act.get('chatId')),
|
||||
"" if name else ""))
|
||||
return "\n".join(lines)
|
||||
|
||||
def __sub_help(self) -> str:
|
||||
return ("Commands:\n"
|
||||
"!sub list\n"
|
||||
"!sub add <src_chat_id> <dst_chat_id> <contain|regexp> <value>\n"
|
||||
"!sub del <id>\n"
|
||||
"!sub on <id> | !sub off <id>")
|
||||
"!sub del <line>\n"
|
||||
"!sub on <line> | !sub off <line>")
|
||||
|
||||
async def __send_all_chats_to_owner(self) -> None:
|
||||
text = ""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user