feat: initial discord meeting bot
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
|
||||
def chunk_message(text: str, limit: int = 1900) -> list[str]:
|
||||
if len(text) <= limit:
|
||||
return [text]
|
||||
|
||||
chunks: list[str] = []
|
||||
remaining = text
|
||||
while remaining:
|
||||
if len(remaining) <= limit:
|
||||
chunks.append(remaining)
|
||||
break
|
||||
|
||||
split_at = remaining.rfind("\n", 0, limit)
|
||||
if split_at <= 0:
|
||||
split_at = limit
|
||||
|
||||
chunks.append(remaining[:split_at])
|
||||
remaining = remaining[split_at:]
|
||||
if remaining.startswith("\n"):
|
||||
remaining = remaining[1:]
|
||||
|
||||
return chunks
|
||||
|
||||
|
||||
def summarize_error(body: Any, fallback: str) -> str:
|
||||
if isinstance(body, dict):
|
||||
err = body.get("error")
|
||||
if isinstance(err, dict):
|
||||
msg = err.get("message")
|
||||
if isinstance(msg, str) and msg.strip():
|
||||
return msg.strip()
|
||||
|
||||
msg = body.get("message")
|
||||
if isinstance(msg, str) and msg.strip():
|
||||
return msg.strip()
|
||||
|
||||
return fallback
|
||||
|
||||
|
||||
def build_transcript_block(display_name: str, transcript: str) -> str:
|
||||
clean_name = display_name.strip() or "Unknown User"
|
||||
clean_transcript = transcript.strip()
|
||||
return f"[{clean_name}]\n{clean_transcript}"
|
||||
|
||||
|
||||
def command_channel_error(current_channel_id: int | None, allowed_channel_id: int | None) -> str | None:
|
||||
if allowed_channel_id is None:
|
||||
return "⚠️ This bot doesn't have a command channel yet. Use `/set_output` first."
|
||||
|
||||
if current_channel_id != allowed_channel_id:
|
||||
return f"⚠️ This command only works in <#{allowed_channel_id}>."
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user