Add files via upload
This commit is contained in:
19 files changed
+1527
No files matched your search
@@ -0,0 +1,2 @@
|
||||
#EXAMPLE ACTION IDEA FOR IMPROVE YOURSELF
|
||||
#TAKE THE API KEY FROM A RADAR WEB SITE TO SEE ALL PLANES ON THE AIR
|
||||
@@ -0,0 +1,63 @@
|
||||
import time
|
||||
import pyautogui
|
||||
from tts import edge_speak
|
||||
|
||||
|
||||
def open_app(
|
||||
parameters: dict,
|
||||
response: str | None = None,
|
||||
player=None,
|
||||
session_memory=None
|
||||
) -> bool:
|
||||
"""
|
||||
Opens an application using Windows search.
|
||||
|
||||
parameters:
|
||||
- app_name (str)
|
||||
|
||||
Memory behavior:
|
||||
- Uses ONLY session memory
|
||||
- No long-term memory writes
|
||||
"""
|
||||
|
||||
app_name = (parameters or {}).get("app_name", "").strip()
|
||||
|
||||
if not app_name and session_memory:
|
||||
app_name = session_memory.open_app or ""
|
||||
|
||||
if not app_name:
|
||||
msg = "Sir, I couldn't determine which application to open."
|
||||
if player:
|
||||
player.write_log(msg)
|
||||
edge_speak(msg, player)
|
||||
return False
|
||||
|
||||
if response:
|
||||
if player:
|
||||
player.write_log(response)
|
||||
edge_speak(response, player)
|
||||
|
||||
try:
|
||||
pyautogui.PAUSE = 0.1
|
||||
|
||||
|
||||
pyautogui.press("win")
|
||||
time.sleep(0.3)
|
||||
|
||||
pyautogui.write(app_name, interval=0.03)
|
||||
time.sleep(0.2)
|
||||
|
||||
pyautogui.press("enter")
|
||||
time.sleep(0.6)
|
||||
|
||||
if session_memory:
|
||||
session_memory.set_open_app(app_name)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
msg = f"Sir, I failed to open {app_name}."
|
||||
if player:
|
||||
player.write_log(f"{msg} ({e})")
|
||||
edge_speak(msg, player)
|
||||
return False
|
||||
@@ -0,0 +1,96 @@
|
||||
import time
|
||||
import pyautogui
|
||||
from tts import edge_speak
|
||||
|
||||
REQUIRED_PARAMS = ["receiver", "message_text", "platform"]
|
||||
|
||||
def send_message(parameters: dict, response: str | None = None, player=None, session_memory=None) -> bool:
|
||||
"""
|
||||
Send a message via Windows app (WhatsApp, Telegram, etc.)
|
||||
|
||||
Multi-step support: asks for missing parameters using temporary memory.
|
||||
|
||||
Expected parameters:
|
||||
- receiver (str)
|
||||
- message_text (str)
|
||||
- platform (str, default: "WhatsApp")
|
||||
"""
|
||||
|
||||
if session_memory is None:
|
||||
msg = "Session memory missing, cannot proceed."
|
||||
if player:
|
||||
player.write_log(msg)
|
||||
edge_speak(msg, player)
|
||||
return False
|
||||
|
||||
if parameters:
|
||||
session_memory.update_parameters(parameters)
|
||||
|
||||
for param in REQUIRED_PARAMS:
|
||||
value = session_memory.get_parameter(param)
|
||||
if not value:
|
||||
|
||||
session_memory.set_current_question(param)
|
||||
question_text = ""
|
||||
if param == "receiver":
|
||||
question_text = "Sir, who should I send the message to?"
|
||||
elif param == "message_text":
|
||||
question_text = "Sir, what should I say?"
|
||||
elif param == "platform":
|
||||
question_text = "Sir, which platform should I use? (WhatsApp, Telegram, etc.)"
|
||||
else:
|
||||
question_text = f"Sir, please provide {param}."
|
||||
|
||||
if player:
|
||||
player.write_log("AI :", question_text)
|
||||
edge_speak(question_text, player)
|
||||
return False
|
||||
|
||||
receiver = session_memory.get_parameter("receiver").strip()
|
||||
platform = session_memory.get_parameter("platform").strip() or "WhatsApp"
|
||||
message_text = session_memory.get_parameter("message_text").strip()
|
||||
|
||||
if response:
|
||||
if player:
|
||||
player.write_log(response)
|
||||
edge_speak(response, player)
|
||||
|
||||
try:
|
||||
pyautogui.PAUSE = 0.1
|
||||
|
||||
pyautogui.press("win")
|
||||
time.sleep(0.3)
|
||||
pyautogui.write(platform, interval=0.03)
|
||||
pyautogui.press("enter")
|
||||
time.sleep(0.6)
|
||||
|
||||
pyautogui.hotkey("ctrl", "f")
|
||||
time.sleep(0.2)
|
||||
pyautogui.write(receiver, interval=0.03)
|
||||
time.sleep(0.2)
|
||||
pyautogui.press("enter")
|
||||
time.sleep(0.2)
|
||||
|
||||
pyautogui.write(message_text, interval=0.03)
|
||||
pyautogui.press("enter")
|
||||
|
||||
session_memory.clear_current_question()
|
||||
session_memory.clear_pending_intent()
|
||||
session_memory.update_parameters({})
|
||||
|
||||
# -----------------------------
|
||||
# Log success
|
||||
# -----------------------------
|
||||
success_msg = f"Sir, message sent to {receiver} via {platform}."
|
||||
if player:
|
||||
player.write_log(success_msg)
|
||||
edge_speak(success_msg, player)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
msg = f"Sir, I failed to send the message. ({e})"
|
||||
if player:
|
||||
player.write_log(msg)
|
||||
edge_speak(msg, player)
|
||||
return False
|
||||
@@ -0,0 +1,67 @@
|
||||
import webbrowser
|
||||
from urllib.parse import quote_plus
|
||||
from tts import edge_speak
|
||||
|
||||
|
||||
def weather_action(
|
||||
parameters: dict,
|
||||
player=None,
|
||||
session_memory=None
|
||||
):
|
||||
"""
|
||||
Weather report action.
|
||||
Opens a Google weather search and gives a short spoken confirmation.
|
||||
"""
|
||||
|
||||
city = parameters.get("city")
|
||||
time = parameters.get("time")
|
||||
if not city or not isinstance(city, str):
|
||||
msg = "Sir, the city is missing for the weather report."
|
||||
_speak_and_log(msg, player)
|
||||
return msg
|
||||
|
||||
city = city.strip()
|
||||
|
||||
if not time or not isinstance(time, str):
|
||||
time = "today"
|
||||
else:
|
||||
time = time.strip()
|
||||
|
||||
search_query = f"weather in {city} {time}"
|
||||
encoded_query = quote_plus(search_query)
|
||||
url = f"https://www.google.com/search?q={encoded_query}"
|
||||
|
||||
try:
|
||||
webbrowser.open(url)
|
||||
except Exception:
|
||||
msg = f"Sir, I couldn't open the browser for the weather report."
|
||||
_speak_and_log(msg, player)
|
||||
return msg
|
||||
|
||||
msg = f"Showing the weather for {city}, {time}, sir."
|
||||
_speak_and_log(msg, player)
|
||||
|
||||
if session_memory:
|
||||
try:
|
||||
session_memory.set_last_search(
|
||||
query=search_query,
|
||||
response=msg
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
def _speak_and_log(message: str, player=None):
|
||||
"""Helper: log + TTS safely"""
|
||||
if player:
|
||||
try:
|
||||
player.write_log(f"JARVIS: {message}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
edge_speak(message)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -0,0 +1,142 @@
|
||||
import re
|
||||
from serpapi import Client
|
||||
from tts import edge_speak
|
||||
from memory.config_manager import get_serpapi_key
|
||||
|
||||
MAX_NEWS_ITEMS = 3
|
||||
|
||||
def clean(text: str) -> str:
|
||||
if not text:
|
||||
return ""
|
||||
text = re.sub(r"\s+", " ", text)
|
||||
text = re.sub(r"\(.*?\)|\[.*?\]", "", text)
|
||||
text = text.strip()
|
||||
text = re.sub(r"\.{2,}", ".")
|
||||
text = re.sub(r"\s*—\s*", " - ", text)
|
||||
return text
|
||||
|
||||
def is_trash(text: str) -> bool:
|
||||
t = text.lower()
|
||||
trash_patterns = [
|
||||
r"\bstock(?:s)?\b.*\btoday\b",
|
||||
r"\bshare(?:s)?\b.*\bprice\b",
|
||||
r"\binvestor(?:s)?\b",
|
||||
r"\btrading\b",
|
||||
r"\bmarket(?:s)?\b.*\bopen(?:s|ed)?\b",
|
||||
r"\bticker\b",
|
||||
r"\bnyse\b",
|
||||
r"\bnasdaq\b",
|
||||
r"\.\w{2,4}\sis\b",
|
||||
]
|
||||
spam_keywords = [
|
||||
"click here", "read more", "advertisement", "sponsored",
|
||||
"subscribe", "newsletter", "sign up",
|
||||
"best things to do", "events this week", "calendar",
|
||||
"official website", "visit our", "learn more",
|
||||
"year in review", "trending now", "top 10"
|
||||
]
|
||||
for pattern in trash_patterns:
|
||||
if re.search(pattern, t):
|
||||
return True
|
||||
return any(keyword in t for keyword in spam_keywords)
|
||||
|
||||
def extract_clean_news(result: dict) -> str:
|
||||
title = clean(result.get("title", ""))
|
||||
snippet = clean(result.get("snippet", ""))
|
||||
if not title:
|
||||
return ""
|
||||
if snippet.startswith(title[:30]) or snippet == title:
|
||||
return title
|
||||
if len(snippet) > 120:
|
||||
snippet = snippet[:120]
|
||||
last_period = snippet.rfind(".")
|
||||
last_space = snippet.rfind(" ")
|
||||
if last_period > 80:
|
||||
snippet = snippet[:last_period + 1]
|
||||
elif last_space > 80:
|
||||
snippet = snippet[:last_space] + "..."
|
||||
return f"{title}. {snippet}"
|
||||
return title
|
||||
|
||||
def format_news_output(news_items: list) -> str:
|
||||
if len(news_items) == 1:
|
||||
return news_items[0]
|
||||
elif len(news_items) == 2:
|
||||
return f"{news_items[0]}. Also, {news_items[1]}"
|
||||
else:
|
||||
result = news_items[0]
|
||||
for item in news_items[1:-1]:
|
||||
result += f". {item}"
|
||||
result += f". Additionally, {news_items[-1]}"
|
||||
return result
|
||||
|
||||
def serpapi_search(query: str) -> str:
|
||||
api_key = get_serpapi_key()
|
||||
if not api_key:
|
||||
return "Sir, the web search system is not configured."
|
||||
|
||||
clean_query = query
|
||||
if "what happened" in query.lower():
|
||||
clean_query = re.sub(r"what happened (?:in|at|to)\s*", "", query, flags=re.IGNORECASE)
|
||||
clean_query += " news today"
|
||||
|
||||
params = {
|
||||
"q": clean_query,
|
||||
"engine": "google_news",
|
||||
"hl": "en",
|
||||
"gl": "us",
|
||||
"num": 15
|
||||
}
|
||||
|
||||
try:
|
||||
client = Client(api_key=api_key)
|
||||
data = client.search(params)
|
||||
results = data.get("news_results", [])
|
||||
except Exception:
|
||||
|
||||
params["engine"] = "google"
|
||||
try:
|
||||
client = Client(api_key=api_key)
|
||||
data = client.search(params)
|
||||
results = data.get("organic_results", [])
|
||||
except Exception:
|
||||
return "Sir, I couldn't connect to the search service."
|
||||
|
||||
if not results:
|
||||
return "Sir, I couldn't find any recent news about that."
|
||||
|
||||
news_items = []
|
||||
for result in results:
|
||||
title = result.get("title", "")
|
||||
snippet = result.get("snippet", "")
|
||||
if is_trash(title) or is_trash(snippet):
|
||||
continue
|
||||
news_text = extract_clean_news(result)
|
||||
if news_text and len(news_text.split()) >= 6:
|
||||
news_items.append(news_text)
|
||||
if len(news_items) >= MAX_NEWS_ITEMS:
|
||||
break
|
||||
|
||||
if not news_items:
|
||||
return "Sir, I found some results but they weren't clear news stories."
|
||||
|
||||
return format_news_output(news_items)
|
||||
|
||||
def web_search(parameters, player=None, session_memory=None):
|
||||
query = (parameters or {}).get("query", "").strip()
|
||||
if not query:
|
||||
msg = "Sir, I couldn't understand the search request."
|
||||
edge_speak(msg)
|
||||
return msg
|
||||
|
||||
answer = serpapi_search(query)
|
||||
|
||||
if player:
|
||||
player.write_log(f"AI: {answer}")
|
||||
|
||||
edge_speak(answer)
|
||||
|
||||
if session_memory:
|
||||
session_memory.set_last_search(query, answer)
|
||||
|
||||
return answer
|
||||
Reference in new issue
Block a user