update and cleanup repo
This commit is contained in:
+19
-12
@@ -1,4 +1,4 @@
|
||||
"""Inline query helpers for providers (choice normalization and filter resolution)."""
|
||||
"""Inline query helpers for plugins (choice normalization and filter resolution)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
@@ -24,7 +24,7 @@ def collect_choice(provider: Any) -> Dict[str, List[Dict[str, Any]]]:
|
||||
"""Collect normalized inline/query argument choice entries from a provider.
|
||||
|
||||
Supports QUERY_ARG_CHOICES, INLINE_QUERY_FIELD_CHOICES, and the
|
||||
helper methods valued by Providers (`query_field_choices` /
|
||||
helper methods exposed by plugins (`query_field_choices` /
|
||||
`inline_query_field_choices`). Each choice is normalized to {value,text,aliases}.
|
||||
"""
|
||||
|
||||
@@ -48,24 +48,31 @@ def collect_choice(provider: Any) -> Dict[str, List[Dict[str, Any]]]:
|
||||
if normalized:
|
||||
mapping[target_key] = normalized
|
||||
|
||||
base = getattr(provider, "QUERY_ARG_CHOICES", None)
|
||||
if isinstance(base, dict):
|
||||
for k, v in base.items():
|
||||
def _merge_mapping(source: Any) -> None:
|
||||
if not isinstance(source, dict):
|
||||
return
|
||||
for k, v in source.items():
|
||||
key_norm = str(k).strip().lower()
|
||||
if not key_norm:
|
||||
continue
|
||||
_ingest(v, key_norm)
|
||||
|
||||
base = getattr(provider, "QUERY_ARG_CHOICES", None)
|
||||
if not isinstance(base, dict):
|
||||
base = getattr(provider, "INLINE_QUERY_FIELD_CHOICES", None)
|
||||
_merge_mapping(base)
|
||||
|
||||
try:
|
||||
fn = getattr(provider, "query_field_choices", None)
|
||||
if callable(fn):
|
||||
_merge_mapping(fn())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
fn = getattr(provider, "inline_query_field_choices", None)
|
||||
if callable(fn):
|
||||
extra = fn()
|
||||
if isinstance(extra, dict):
|
||||
for k, v in extra.items():
|
||||
key_norm = str(k).strip().lower()
|
||||
if not key_norm:
|
||||
continue
|
||||
_ingest(v, key_norm)
|
||||
_merge_mapping(fn())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user