Add files via upload

This commit is contained in:
FatihMakes authored and GitHub committed 2026-02-01 20:38:51 +03:00
1 parent b599082b22
commit c780b2ef21
16 files changed
+1324

No files matched your search

+2
View File
@@ -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
+63
View File
@@ -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
+96
View File
@@ -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
+67
View File
@@ -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
+165
View File
@@ -0,0 +1,165 @@
import re
from serpapi import GoogleSearch
from tts import edge_speak
MAX_SNIPPETS = 3
MIN_SENTENCE_LENGTH = 30
def clean(text: str) -> str:
"""Clean text: remove extra spaces, ..., brackets."""
if not text:
return ""
text = re.sub(r"\s+", " ", text)
text = re.sub(r"\.\.\.+", ".", text)
text = re.sub(r"\[.*?\]", "", text)
text = re.sub(r"\(.*?\)", "", text)
return text.strip()
def split_sentences(text: str):
"""Split text into sentences and avoid very short or incomplete ones."""
sentences = re.split(r"(?<=[.!?])\s+", text)
valid_sentences = []
buffer = ""
for s in sentences:
s = clean(s)
if not s:
continue
last_word = s.split()[-1].lower()
if last_word in [
"of", "in", "at", "on", "by",
"after", "before", "with", "for", "to"
]:
buffer += s + " "
continue
if buffer:
s = buffer + s
buffer = ""
if len(s) >= MIN_SENTENCE_LENGTH:
valid_sentences.append(s)
return valid_sentences
def is_noise(text: str) -> bool:
"""Check if a sentence is noise or irrelevant."""
t = text.lower()
noise_keywords = [
"read more",
"learn more",
"click here",
"infographic",
"google trends",
"year in search",
"most searched",
"top 100",
"subscribe",
"share this",
"advertisement",
"ad:"
]
return any(word in t for word in noise_keywords)
def select_best_sentence(snippets):
"""Combine up to MAX_SNIPPETS and return a single coherent sentence."""
final_text = ""
count = 0
for snippet in snippets:
if not snippet or is_noise(snippet):
continue
sentences = split_sentences(snippet)
for s in sentences:
if is_noise(s):
continue
final_text = f"{final_text} {s}".strip()
count += 1
if count >= MAX_SNIPPETS:
return final_text
return final_text if final_text else None
def serpapi_answer(query: str, api_key: str) -> str:
"""Perform search and return a single coherent sentence."""
params = {
"q": query,
"engine": "google",
"hl": "en",
"gl": "us",
"num": 3,
"api_key": api_key
}
try:
data = GoogleSearch(params).get_dict()
except Exception:
return "Sir, the web search failed."
organic = data.get("organic_results", [])
if not organic:
return "Sir, I couldn't find relevant information."
snippets = [
r.get("snippet", "")
for r in organic
if r.get("snippet")
]
answer = select_best_sentence(snippets)
if not answer:
return "Sir, I found information online, but couldn't summarize it clearly."
return answer
def web_search(
parameters: dict,
player=None,
session_memory=None,
api_key: str = ""
):
"""
Main web search:
- Returns 1 coherent sentence
- Does NOT append previous answers
- Combines multiple snippets if needed to avoid cut-offs
"""
query = (parameters or {}).get("query", "").strip()
if not query:
msg = "Sir, I couldn't understand the search request."
if player:
player.write_log(msg)
edge_speak(msg)
return msg
answer = serpapi_answer(query, api_key)
if player:
player.write_log(f"AI: {answer}")
edge_speak(answer)
if session_memory:
session_memory.set_last_search(query, answer)
return answer