generated from exteraGramPlugins/pluginBase
Client commands tokens cover all your panel accounts
Publish plugin / publish (push) Successful in 5s
Publish plugin / publish (push) Successful in 5s
One token runs the commands of every account of its owner on the panel: /me lists them, the plugin asks for the commands of each one signed in on the device, and every request names its account by Telegram user id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ecb4c0d97f
commit
0b174fea7e
7 files changed
+112
-67
No files matched your search
+21
-12
@@ -81,7 +81,10 @@ class _SettingsRow:
|
||||
|
||||
|
||||
class _UserConfig:
|
||||
"""org.telegram.messenger.UserConfig: account slot n is Telegram user 1000 + n."""
|
||||
"""org.telegram.messenger.UserConfig: account slot n is Telegram user
|
||||
1000 + n; slots 0-2 are signed in."""
|
||||
|
||||
MAX_ACCOUNT_COUNT = 5
|
||||
|
||||
def __init__(self, slot):
|
||||
self.slot = slot
|
||||
@@ -93,6 +96,9 @@ class _UserConfig:
|
||||
def getClientUserId(self):
|
||||
return 1000 + self.slot
|
||||
|
||||
def isClientActivated(self):
|
||||
return self.slot < 3
|
||||
|
||||
|
||||
FILES_DIR = tempfile.mkdtemp(prefix="cc-verify-")
|
||||
|
||||
@@ -125,11 +131,13 @@ def install_fakes() -> None:
|
||||
|
||||
|
||||
class FakeApi:
|
||||
"""The panel, as api.Api's methods answer."""
|
||||
"""The panel, as api.Api's methods answer: token -> {tg id: [command
|
||||
json]} (the owner's accounts), or an ApiError."""
|
||||
|
||||
def __init__(self, tokens):
|
||||
self._tokens = tokens # token -> (tg id, [command json]) or an ApiError
|
||||
self._tokens = tokens
|
||||
self.configured = True
|
||||
self.listed = []
|
||||
|
||||
def tokens(self):
|
||||
return list(self._tokens)
|
||||
@@ -141,12 +149,12 @@ class FakeApi:
|
||||
return found
|
||||
|
||||
def me(self, token):
|
||||
tg_id, _ = self._of(token)
|
||||
return {"tg_id": tg_id, "account_name": f"acc{tg_id}", "running": True}
|
||||
accounts = [{"tg_id": tg, "name": f"acc{tg}", "running": True} for tg in self._of(token)]
|
||||
return {"name": "Op", "accounts": accounts}
|
||||
|
||||
def commands(self, token):
|
||||
_, commands = self._of(token)
|
||||
return {"commands": commands, "refresh_seconds": 3600}
|
||||
def commands(self, token, tg_id):
|
||||
self.listed.append(tg_id)
|
||||
return {"commands": self._of(token)[tg_id], "refresh_seconds": 3600}
|
||||
|
||||
|
||||
KEY_TO_DUNDER = {
|
||||
@@ -314,8 +322,8 @@ def check_catalog(load, library):
|
||||
roll_shadow = {"name": "roll", "summary": "Panel roll", "params": []}
|
||||
api = FakeApi(
|
||||
{
|
||||
"tok_a": (1000, [getid, roll_shadow]),
|
||||
"tok_b": (1001, [{"name": "ping"}]),
|
||||
# One token for all of a panel user's accounts; 1009 isn't signed in here.
|
||||
"tok_a": {1000: [getid, roll_shadow], 1001: [{"name": "ping"}], 1009: []},
|
||||
"tok_bad": from_api.ApiError("403: Not a commands token", 403),
|
||||
}
|
||||
)
|
||||
@@ -327,7 +335,8 @@ def check_catalog(load, library):
|
||||
check("a panel command shadows a plugin's", catalog.find(0, "roll").summary == "Panel roll")
|
||||
names1 = [c.name for c in catalog.commands_for(1)]
|
||||
check("account 1 has its own panel commands", names1 == ["ping", "roll"], repr(names1))
|
||||
check("tokens picked by Telegram id", catalog.token_for(0) == "tok_a" and catalog.token_for(1) == "tok_b")
|
||||
check("one token covers every account", catalog.token_for(0) == "tok_a" and catalog.token_for(1) == "tok_a")
|
||||
check("only accounts signed in here are asked for", sorted(api.listed) == [1000, 1001], repr(api.listed))
|
||||
check("a refused token is reported", "tok_bad" in catalog.errors())
|
||||
check("accounts without a token only get plugins'", [c.name for c in catalog.commands_for(5)] == ["roll"])
|
||||
cached = catalog_mod.Catalog(plugin, FakeApi({}), library)
|
||||
@@ -335,7 +344,7 @@ def check_catalog(load, library):
|
||||
plugin.set_setting("server_commands", False)
|
||||
check("panel commands can be turned off", [c.name for c in catalog.commands_for(0)] == ["roll"])
|
||||
plugin.set_setting("server_commands", True)
|
||||
api._tokens.pop("tok_b")
|
||||
api._tokens.pop("tok_a")
|
||||
api._tokens.pop("tok_bad")
|
||||
catalog._refresh_due()
|
||||
check("a removed token's commands go", [c.name for c in catalog.commands_for(1)] == ["roll"])
|
||||
|
||||
Reference in new issue
Block a user