Add 'Detect and Join Conversation' button to Web UI and CLI

- Added /autonomous/join-conversation API endpoint in api.py
- Added 'Detect and Join Conversation' button to Web UI under Autonomous Actions
- Added 'autonomous join-conversation' command to CLI tool (miku-cli.py)
- Updated miku_detect_and_join_conversation_for_server to support force=True parameter
- When force=True: skips time limit, activity checks, and random chance
- Force mode uses last 10 user messages regardless of age
- Manual triggers via Web UI/CLI now work even with old messages
This commit is contained in:
2025-12-10 14:57:59 +02:00
parent 76aaf6c437
commit 65e6c3e7ea
4 changed files with 82 additions and 18 deletions

View File

@@ -171,6 +171,14 @@ class MikuCLI:
result = self._post("/autonomous/reaction")
print(f"{result['message']}")
def autonomous_join_conversation(self, guild_id: Optional[int] = None):
"""Trigger detect and join conversation."""
if guild_id:
result = self._post(f"/autonomous/join-conversation?guild_id={guild_id}")
else:
result = self._post("/autonomous/join-conversation")
print(f"{result['message']}")
def autonomous_custom(self, prompt: str, guild_id: Optional[int] = None):
"""Send custom autonomous message."""
if guild_id:
@@ -408,6 +416,7 @@ def print_help():
autonomous-engage [server_id] - Engage with conversation
autonomous-tweet [server_id] - Post tweet-style message
autonomous-reaction [server_id] - Generate reaction
autonomous-join-conversation [server_id] - Detect and join conversation
autonomous-custom <prompt> [server_id] - Custom autonomous action
autonomous-stats - Show autonomous statistics
@@ -489,6 +498,9 @@ def execute_command(cli: MikuCLI, command: str, args: list):
elif command == 'autonomous-reaction':
server_id = int(args[0]) if args and args[0].isdigit() else None
cli.autonomous_reaction(server_id)
elif command == 'autonomous-join-conversation':
server_id = int(args[0]) if args and args[0].isdigit() else None
cli.autonomous_join_conversation(server_id)
elif command == 'autonomous-custom':
if not args:
print("❌ Usage: autonomous-custom <prompt> [server_id]")
@@ -610,7 +622,7 @@ Examples:
# Autonomous commands
auto_parser = subparsers.add_parser('autonomous', help='Autonomous actions')
auto_parser.add_argument('action', choices=['general', 'engage', 'tweet', 'reaction', 'custom', 'stats'])
auto_parser.add_argument('action', choices=['general', 'engage', 'tweet', 'reaction', 'join-conversation', 'custom', 'stats'])
auto_parser.add_argument('--prompt', help='Custom prompt (for custom action)')
auto_parser.add_argument('--server', type=int, help='Server/guild ID')
@@ -702,6 +714,8 @@ Examples:
cli.autonomous_tweet(args.server)
elif args.action == 'reaction':
cli.autonomous_reaction(args.server)
elif args.action == 'join-conversation':
cli.autonomous_join_conversation(args.server)
elif args.action == 'custom':
if not args.prompt:
print("❌ --prompt is required for custom action")