mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
Compare commits
160 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b7d795a31 | ||
|
|
1f093c4bc2 | ||
|
|
fe1c4a1ad0 | ||
|
|
11687cb7ba | ||
|
|
b07a7fb0cc | ||
|
|
b876d87ba9 | ||
|
|
0a63e89633 | ||
|
|
848f5609c2 | ||
|
|
0ccbed6165 | ||
|
|
646517db71 | ||
|
|
7d347bb80a | ||
|
|
e199d4f5eb | ||
|
|
a9767b58c4 | ||
|
|
69dfde047e | ||
|
|
da33b6f1b9 | ||
|
|
8a7125358b | ||
|
|
ae558052f7 | ||
|
|
5074d71eb7 | ||
|
|
632f42477a | ||
|
|
b3df38d15e | ||
|
|
b76b8ca718 | ||
|
|
d66a9e745b | ||
|
|
717bbccea3 | ||
|
|
50fd1c0410 | ||
|
|
ae89788ea4 | ||
|
|
4220b095ee | ||
|
|
ef28341cdb | ||
|
|
b5d610728c | ||
|
|
bc238ef476 | ||
|
|
feb3544014 | ||
|
|
31322dc0cd | ||
|
|
8c1cbaf442 | ||
|
|
8d6a95b5da | ||
|
|
b4b2ef3d80 | ||
|
|
13b1b90864 | ||
|
|
838bd3edce | ||
|
|
70bcf43b49 | ||
|
|
0a02ae860e | ||
|
|
a80575a381 | ||
|
|
e57b65b447 | ||
|
|
1d18f0936c | ||
|
|
b096716b96 | ||
|
|
f4734c5b87 | ||
|
|
96447b166f | ||
|
|
2fc151bbbf | ||
|
|
e66af5c068 | ||
|
|
d3ce4d3905 | ||
|
|
a95cdeb086 | ||
|
|
27bf61a913 | ||
|
|
d62990b6db | ||
|
|
0784aaebd9 | ||
|
|
e348854a50 | ||
|
|
a71e5fa8f3 | ||
|
|
9600ea5e00 | ||
|
|
cc7461929e | ||
|
|
0c8fb0c243 | ||
|
|
311563320e | ||
|
|
78b6d660dd | ||
|
|
77da966b9d | ||
|
|
d844c123be | ||
|
|
d4d36c8a31 | ||
|
|
9acd57a420 | ||
|
|
bc06712b87 | ||
|
|
260e52fe81 | ||
|
|
6b548f82b2 | ||
|
|
2273b481ad | ||
|
|
95ee7779b4 | ||
|
|
ee1391f6e7 | ||
|
|
b7a0d7cd8e | ||
|
|
a880236117 | ||
|
|
a67bdc3641 | ||
|
|
da8235adae | ||
|
|
22384463e2 | ||
|
|
b48377de5f | ||
|
|
855c2e08cc | ||
|
|
d0aa07ed7d | ||
|
|
7328a92535 | ||
|
|
35c8dc6f70 | ||
|
|
4b1123dcac | ||
|
|
b74dc1ff25 | ||
|
|
8c752dff3e | ||
|
|
b3b45a4335 | ||
|
|
fd86187798 | ||
|
|
4da3e68c62 | ||
|
|
e47907ebeb | ||
|
|
f63278ae8f | ||
|
|
0e0d2f11d7 | ||
|
|
6587ba61e2 | ||
|
|
b46697c0c4 | ||
|
|
f5f8539924 | ||
|
|
e8063fcf3f | ||
|
|
169f9b27a5 | ||
|
|
4ceb23bcff | ||
|
|
315ae84bb6 | ||
|
|
fb12c11a7e | ||
|
|
496c222cdc | ||
|
|
cb55aba498 | ||
|
|
1aac3d5ac2 | ||
|
|
413f2a24d9 | ||
|
|
c75782d559 | ||
|
|
d38314a21c | ||
|
|
65dfe90edc | ||
|
|
3ce24fb7c9 | ||
|
|
8765e5a871 | ||
|
|
b4f0421423 | ||
|
|
2b8906ae55 | ||
|
|
5710b47a99 | ||
|
|
1f8bf5a700 | ||
|
|
171480b704 | ||
|
|
c74e4f99b2 | ||
|
|
cd5749521c | ||
|
|
5ce7019dba | ||
|
|
6c1e0cc2f9 | ||
|
|
68b171f68e | ||
|
|
7cfd5d0b0e | ||
|
|
6dd4f0c4b6 | ||
|
|
8ef0fa2ac0 | ||
|
|
0c8d6b8fac | ||
|
|
1e4e5e6627 | ||
|
|
c97004b410 | ||
|
|
2292fb2655 | ||
|
|
3ebf3ba374 | ||
|
|
b6087c926c | ||
|
|
2895e6c034 | ||
|
|
691bc8d701 | ||
|
|
bd50524e95 | ||
|
|
299b749f0e | ||
|
|
9a060e3c6e | ||
|
|
a012ef17d0 | ||
|
|
adbf78b740 | ||
|
|
3aad8d89cf | ||
|
|
3370304249 | ||
|
|
ef62a06db1 | ||
|
|
8cc1d24b93 | ||
|
|
fca90cbee3 | ||
|
|
d05c7bb6a5 | ||
|
|
7774529fb4 | ||
|
|
4c615af22d | ||
|
|
6c078b4d17 | ||
|
|
ddb9c8b4bf | ||
|
|
73f3175705 | ||
|
|
d2ee1bce1c | ||
|
|
b4a2149815 | ||
|
|
320f41e05a | ||
|
|
48a57e875f | ||
|
|
ce317d8bbe | ||
|
|
c2d2a8f7e4 | ||
|
|
00280e351c | ||
|
|
0e8bb197a9 | ||
|
|
d825c0fa15 | ||
|
|
6abe73c1bc | ||
|
|
b8e9adb223 | ||
|
|
e621016e9a | ||
|
|
cfaf652852 | ||
|
|
6c27b5d5de | ||
|
|
a31fa90942 | ||
|
|
3cd347dff3 | ||
|
|
ea4ac1f9c1 | ||
|
|
a9da8336cc | ||
|
|
4ba60ed276 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -23,7 +23,8 @@ data/rag/*
|
||||
# qrz db
|
||||
data/qrz.db
|
||||
|
||||
# fileMon
|
||||
news.txt
|
||||
alert.txt
|
||||
# fileMonitor test file
|
||||
bee.txt
|
||||
|
||||
# .csv files
|
||||
*.csv
|
||||
80
README.md
80
README.md
@@ -41,6 +41,7 @@ Welcome to the Mesh Bot project! This feature-rich bot is designed to enhance yo
|
||||
### Proximity Alerts
|
||||
- **Location-Based Alerts**: Get notified when members arrive back at a configured lat/long, perfect for remote locations like campsites.
|
||||
- **High Flying Alerts**: Get notified when nodes with high altitude are seen on mesh
|
||||
- **Hey Chirpy**: Voice activate send messages with "hey chirpy"
|
||||
|
||||
### CheckList / Check In Out
|
||||
- **Asset Tracking**: Maintain a list of node/asset checkin and checkout. Useful foraccountability of people, assets. Radio-Net, FEMA, Trailhead.
|
||||
@@ -49,10 +50,21 @@ Welcome to the Mesh Bot project! This feature-rich bot is designed to enhance yo
|
||||
- **Built-in Games**: Enjoy games like DopeWars, Lemonade Stand, BlackJack, and VideoPoker.
|
||||
- **FCC ARRL QuizBot**: The exam question pool quiz-bot.
|
||||
- **Command-Based Gameplay**: Issue `games` to display help and start playing.
|
||||
- **Telemetry Leaderboard**: Fun stats like lowest 🪫 battery or coldest temp 🥶
|
||||
|
||||
#### QuizMaster
|
||||
- **Interactive Group Quizzes**: The QuizMaster module allows admins to start and stop quiz games for groups. Players can join, leave, and answer questions directly via DM or channel.
|
||||
- **Scoring and Leaderboards**: Players can check their scores and see the top performers with `q: score` and `q: top`.
|
||||
- **Easy Participation**: Players answer questions by prefixing their answer with `q:`, e.g., `q: 42`.
|
||||
|
||||
#### Survey Module
|
||||
- **Custom Surveys**: Easily create and deploy custom surveys by editing JSON files in `data/survey`. Multiple surveys can be managed (e.g., `survey snow`).
|
||||
- **User Feedback Collection**: Users can participate in surveys via DM, and responses are logged for later review.
|
||||
|
||||
### Radio Frequency Monitoring
|
||||
- **SNR RF Activity Alerts**: Monitor a radio frequency and get alerts when high SNR RF activity is detected.
|
||||
- **Hamlib Integration**: Use Hamlib (rigctld) to watch the S meter on a connected radio.
|
||||
- **Speech to Text Brodcasting to Mesh** Using [vosk](https://alphacephei.com/vosk/models) to translate to text.
|
||||
|
||||
### EAS Alerts
|
||||
- **FEMA iPAWS/EAS Alerts via API**: Use an internet-connected node to message Emergency Alerts from FEMA
|
||||
@@ -63,11 +75,12 @@ Welcome to the Mesh Bot project! This feature-rich bot is designed to enhance yo
|
||||
|
||||
### File Monitor Alerts
|
||||
- **File Monitor**: Monitor a flat/text file for changes, broadcast the contents of the message to the mesh channel.
|
||||
- **News File**: On request of news, the contents of the file are returned.
|
||||
- **Shell Command Access**: Pass commands via DM directly to the host OS
|
||||
- **News File**: On request of news, the contents of the file are returned. Can also call multiple news sources or files.
|
||||
- **Shell Command Access**: Pass commands via DM directly to the host OS with replay protection.
|
||||
|
||||
### Data Reporting
|
||||
- **HTML Generator**: Visualize bot traffic and data flows with a built-in HTML generator for [data reporting](logs/README.md).
|
||||
- **RSS and news feeds**: Get data in mesh from many sources!
|
||||
|
||||
### Robust Message Handling
|
||||
- **Message Chunking**: Automatically chunk messages over 160 characters to ensure higher delivery success across hops.
|
||||
@@ -92,10 +105,11 @@ git clone https://github.com/spudgunman/meshing-around
|
||||
| `ping`, `ack` | Return data for signal. Example: `ping 15 #DrivingI5` (activates auto-ping every 20 seconds for count 15 via DM only) | ✅ |
|
||||
| `cmd` | Returns the list of commands (the help message) | ✅ |
|
||||
| `history` | Returns the last commands run by user(s) | ✅ |
|
||||
| `leaderboard` | Shows extreme mesh metrics like lowest battery 🪫 `leaderboard reset` allows admin reset | ✅ |
|
||||
| `lheard` | Returns the last 5 heard nodes with SNR. Can also use `sitrep` | ✅ |
|
||||
| `motd` | Displays the message of the day or sets it. Example: `motd $New Message Of the day` | ✅ |
|
||||
| `sysinfo` | Returns the bot node telemetry info | ✅ |
|
||||
| `test` | used to test the limits of data transfer `test 4` sends data to the maxBuffer limit (default 220) via DM only | ✅ |
|
||||
| `test` | used to test the limits of data transfer (`test 4` sends data to the maxBuffer limit default 200 charcters) via DM only | ✅ |
|
||||
| `whereami` | Returns the address of the sender's location if known |
|
||||
| `whoami` | Returns details of the node asking, also returned when position exchanged 📍 | ✅ |
|
||||
| `whois` | Returns details known about node, more data with bbsadmin node | ✅ |
|
||||
@@ -108,7 +122,7 @@ git clone https://github.com/spudgunman/meshing-around
|
||||
| `earthquake` | Returns the largest and number of USGS events for the location | |
|
||||
| `hfcond` | Returns a table of HF solar conditions | |
|
||||
| `rlist` | Returns a table of nearby repeaters from RepeaterBook | |
|
||||
| `riverflow` | Return information from NOAA for river flow info. Example: `riverflow modules/settings.py`| |
|
||||
| `riverflow` | Return information from NOAA for river flow info. | |
|
||||
| `solar` | Gives an idea of the x-ray flux | |
|
||||
| `sun` and `moon` | Return info on rise and set local time | ✅ |
|
||||
| `tide` | Returns the local tides (NOAA data source) | |
|
||||
@@ -137,10 +151,11 @@ git clone https://github.com/spudgunman/meshing-around
|
||||
| Command | Description | |
|
||||
|---------|-------------|-
|
||||
| `askai` and `ask:` | Ask Ollama LLM AI for a response. Example: `askai what temp do I cook chicken` | ✅ |
|
||||
| `messages` | Replays the last messages heard, like Store and Forward | ✅ |
|
||||
| `readnews` | returns the contents of a file (news.txt, by default) via the chunker on air | ✅ |
|
||||
| `messages` | Replays the last messages heard on device, like Store and Forward, returns the PublicChannel and Current | ✅ |
|
||||
| `readnews` | returns the contents of a file (data/news.txt, by default) can also `news mesh` via the chunker on air | ✅ |
|
||||
| `readrss` | returns a set RSS feed on air | |
|
||||
| `satpass` | returns the pass info from API for defined NORAD ID in config or Example: `satpass 25544,33591`| |
|
||||
| `wiki:` | Searches Wikipedia and returns the first few sentences of the first result if a match. Example: `wiki: lora radio` |
|
||||
| `wiki:` | Searches Wikipedia (or local Kiwix server) and returns the first few sentences of the first result if a match. Example: `wiki: lora radio` |
|
||||
| `howfar` | returns the distance you have traveled since your last HowFar. `howfar reset` to start over | ✅ |
|
||||
| `howtall` | returns height of something you give a shadow by using sun angle | ✅ |
|
||||
|
||||
@@ -162,8 +177,19 @@ git clone https://github.com/spudgunman/meshing-around
|
||||
| `joke` | Tells a joke | |
|
||||
| `lemonstand` | Plays the classic Lemonade Stand finance game | ✅ |
|
||||
| `mastermind` | Plays the classic code-breaking game | ✅ |
|
||||
| `survey` | Issues out a survey to the user | ✅ |
|
||||
| `quiz` | QuizMaster Bot `q: ?` for more | ✅ |
|
||||
| `tic-tac-toe`| Plays the game classic game | ✅ |
|
||||
| `videopoker` | Plays basic 5-card hold Video Poker | ✅ |
|
||||
|
||||
#### QuizMaster
|
||||
To use QuizMaster the bbs_admin_list is the QuizMaster, who can `q: start` and `q: stop` to start and stop the game, `q: broadcast <message>` to send a message to all players.
|
||||
Players can `q: join` to join the game, `q: leave` to leave the game, `q: score` to see their score, and `q: top` to see the top 3 players.
|
||||
To Answer a question, just type the answer prefixed with `q: <answer>`
|
||||
|
||||
#### Survey
|
||||
To use the Survey feature edit the json files in data/survey multiple surveys are possible such as `survey snow`
|
||||
|
||||
## Other Install Options
|
||||
|
||||
### Docker Installation - handy for windows
|
||||
@@ -229,6 +255,10 @@ The weather forecasting defaults to NOAA, for locations outside the USA, you can
|
||||
enabled = True
|
||||
lat = 48.50
|
||||
lon = -123.0
|
||||
# To fuzz the location of the above
|
||||
fuzzConfigLocation = True
|
||||
# Fuzz all values in all data
|
||||
fuzzItAll = False
|
||||
UseMeteoWxAPI = True
|
||||
|
||||
coastalEnabled = False # NOAA Coastal Data Enable NOAA Coastal Waters Forecasts and Tide
|
||||
@@ -377,6 +407,33 @@ googleSearchResults = 3 # number of google search results to include in the cont
|
||||
```
|
||||
Note for LLM in docker with [NVIDIA](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/docker-specialized.html). Needed for the container with ollama running.
|
||||
|
||||
### Wikipedia Search Settings
|
||||
The Wikipedia search module can use either the online Wikipedia API or a local Kiwix server for offline wiki access. Kiwix is especially useful for mesh networks operating in remote or offline environments.
|
||||
|
||||
```ini
|
||||
# Enable or disable the wikipedia search module
|
||||
wikipedia = True
|
||||
|
||||
# Use local Kiwix server instead of online Wikipedia
|
||||
# Set to False to use online Wikipedia (default)
|
||||
useKiwixServer = False
|
||||
|
||||
# Kiwix server URL (only used if useKiwixServer is True)
|
||||
kiwixURL = http://127.0.0.1:8080
|
||||
|
||||
# Kiwix library name (e.g., wikipedia_en_100_nopic_2024-06)
|
||||
# Find available libraries at https://library.kiwix.org/
|
||||
kiwixLibraryName = wikipedia_en_100_nopic_2024-06
|
||||
```
|
||||
|
||||
To set up a local Kiwix server:
|
||||
1. Install Kiwix tools: https://kiwix.org/en/ `sudo apt install kiwix-tools -y`
|
||||
2. Download a Wikipedia ZIM file to `data/`: https://library.kiwix.org/ `wget https://download.kiwix.org/zim/wikipedia/wikipedia_en_100_nopic_2025-09.zim`
|
||||
3. Run the server: `kiwix-serve --port 8080 wikipedia_en_100_nopic_2025-09.zim`
|
||||
4. Set `useKiwixServer = True` in your config.ini
|
||||
|
||||
The bot will automatically extract and truncate content to fit Meshtastic's message size limits (~500 characters).
|
||||
|
||||
### Radio Monitoring
|
||||
A module allowing a Hamlib compatible radio to connect to the bot. When functioning, it will message the configured channel with a message of in use. **Requires hamlib/rigctld to be running as a service.**
|
||||
|
||||
@@ -431,7 +488,12 @@ rtl_fm -f 162425000 -s 22050 | multimon-ng -t raw -a EAS /dev/stdin | python eas
|
||||
```
|
||||
|
||||
#### Newspaper on mesh
|
||||
a newspaper could be built by external scripts. could use Ollama to compile text via news web pages and write news.txt
|
||||
Maintain multiple news sources. Each source should be a file named `{source}_news.txt` in the `data/` directory (for example, `data/mesh_news.txt`).
|
||||
- To read the default news, use the `readnews` command (reads from `data/news.txt`.
|
||||
- To read a specific source, use `readnews abc` to read from `data/abc_news.txt`.
|
||||
|
||||
This allows you to organize and access different news feeds or categories easily.
|
||||
External scripts can update these files as needed, and the bot will serve the latest content on request.
|
||||
|
||||
### Greet new nodes QRZ module
|
||||
This isnt QRZ.com this is Q code for who is calling me, this will track new nodes and say hello
|
||||
@@ -523,7 +585,7 @@ I used ideas and snippets from other responder bots and want to call them out!
|
||||
- **mikecarper**: ideas, and testing. hamtest
|
||||
- **c.merphy360**: high altitude alerts
|
||||
- **Iris**: testing and finding 🐞
|
||||
- **Cisien, bitflip, Woof, propstg, trs2982, Josh, mesb1, and Hailo1999**: For testing and feature ideas on Discord and GitHub.
|
||||
- **Cisien, bitflip, Woof, propstg, snydermesh, trs2982, FJRPilot, F0X, mesb1, and Hailo1999**: For testing and feature ideas on Discord and GitHub.
|
||||
- **Meshtastic Discord Community**: For tossing out ideas and testing code.
|
||||
|
||||
### Tools
|
||||
|
||||
@@ -55,8 +55,23 @@ DadJokesEmoji = False
|
||||
# enable or disable the Solar module
|
||||
spaceWeather = True
|
||||
|
||||
# enable or disable the RSS module, and truncate the story
|
||||
rssEnable = True
|
||||
rssFeedURL = http://www.hackaday.com/rss.xml,http://rss.slashdot.org/Slashdot/slashdotMain
|
||||
# RSS feed names must match the order of the URLs above, default is used if no match
|
||||
rssFeedNames = default,slashdot
|
||||
rssMaxItems = 3
|
||||
rssTruncate = 100
|
||||
|
||||
# enable or disable the wikipedia search module
|
||||
wikipedia = True
|
||||
# Use local Kiwix server instead of online Wikipedia
|
||||
# Set to False to use online Wikipedia, or provide Kiwix server URL
|
||||
useKiwixServer = False
|
||||
# Kiwix server URL (e.g., http://127.0.0.1:8080)
|
||||
kiwixURL = http://127.0.0.1:8080
|
||||
# Kiwix library name (e.g., wikipedia_en_100_nopic_2025-09)
|
||||
kiwixLibraryName = wikipedia_en_100_nopic_2025-09
|
||||
|
||||
# Enable ollama LLM see more at https://ollama.com
|
||||
ollama = False
|
||||
@@ -73,6 +88,7 @@ rawLLMQuery = True
|
||||
# StoreForward Enabled and Limits
|
||||
StoreForward = True
|
||||
StoreLimit = 3
|
||||
reverseSF = False
|
||||
|
||||
# history command
|
||||
enableCmdHistory = True
|
||||
@@ -82,7 +98,7 @@ lheardCmdIgnoreNodes =
|
||||
# 24 hour clock
|
||||
zuluTime = False
|
||||
# wait time for URL requests
|
||||
urlTimeout = 10
|
||||
urlTimeout = 15
|
||||
|
||||
# logging to file of the non Bot messages
|
||||
LogMessagesToFile = False
|
||||
@@ -132,6 +148,7 @@ highFlyingAlertAltitude = 2000
|
||||
highflyOpenskynetwork = True
|
||||
# Channel to send Alert when the high flying node is detected
|
||||
highFlyingAlertInterface = 1
|
||||
# to disable OTA alert set to unused channel like 9
|
||||
highFlyingAlertChannel = 2
|
||||
# list of nodes numbers to ignore high flying alert ex: 2813308004,4258675309
|
||||
highFlyingIgnoreList =
|
||||
@@ -154,6 +171,8 @@ bbsAPI_enabled = False
|
||||
enabled = True
|
||||
lat = 48.50
|
||||
lon = -123.0
|
||||
fuzzConfigLocation = True
|
||||
fuzzItAll = False
|
||||
|
||||
# Default to metric units rather than imperial
|
||||
useMetric = False
|
||||
@@ -179,7 +198,8 @@ myCoastalZone = https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/pz/pzz1
|
||||
# number of data points to return, default is 3
|
||||
coastalForecastDays = 3
|
||||
|
||||
# NOAA USGS Hydrology river identifiers, LID or USGS ID https://waterdata.usgs.gov
|
||||
# NOAA USGS Hydrology river identifiers, LID or USGS ID https://waterdata.usgs.gov 12484500 Columbia River at The Dalles, OR
|
||||
# for multiple rivers use comma separated list e.g. 12484500,14105700
|
||||
riverList =
|
||||
|
||||
# NOAA EAS Alert Broadcast
|
||||
@@ -254,6 +274,8 @@ interface = 1
|
||||
# channel to send the message to
|
||||
channel = 2
|
||||
message = "MeshBot says Hello! DM for more info."
|
||||
# enable overides the above and uses the motd as the message
|
||||
schedulerMotd = False
|
||||
# value can be min,hour,day,mon,tue,wed,thu,fri,sat,sun
|
||||
value =
|
||||
# interval to use when time is not set (e.g. every 2 days)
|
||||
@@ -265,7 +287,9 @@ time =
|
||||
# using Hamlib rig control will monitor and alert on channel use
|
||||
enabled = False
|
||||
rigControlServerAddress = localhost:4532
|
||||
# broadcast to all nodes on the channel can also be = 2,3
|
||||
# device interface to send the message to
|
||||
sigWatchBroadcastInterface = 1
|
||||
# broadcast channel can also be a comma separated list of channels
|
||||
sigWatchBroadcastCh = 2
|
||||
# minimum SNR as reported by radio via hamlib
|
||||
signalDetectionThreshold = -10
|
||||
@@ -274,6 +298,16 @@ signalHoldTime = 10
|
||||
# the following are combined to reset the monitor
|
||||
signalCooldown = 5
|
||||
signalCycleLimit = 5
|
||||
# enable VOX detection using default input
|
||||
voxDetectionEnabled = False
|
||||
# description to use in the alert message
|
||||
voxDescription = VOX
|
||||
useLocalVoxModel = False
|
||||
voxLanguage = en-us
|
||||
voxInputDevice = default
|
||||
voxOnTrapList = True
|
||||
voxTrapList = chirpy
|
||||
|
||||
|
||||
[fileMon]
|
||||
filemon_enabled = False
|
||||
@@ -284,7 +318,7 @@ broadcastCh = 2
|
||||
|
||||
# news command will return the contents of a text file
|
||||
enable_read_news = False
|
||||
news_file_path = news.txt
|
||||
news_file_path = ../data/news.txt
|
||||
# only return a single random line from the news file
|
||||
news_random_line = False
|
||||
|
||||
@@ -293,6 +327,10 @@ enable_runShellCmd = False
|
||||
# if runShellCmd and you think it is safe to allow the x: command to run
|
||||
# direct shell command handler the x: command in DMs
|
||||
allowXcmd = False
|
||||
# Enable 2 factor authentication for x: commands
|
||||
2factor_enabled = True
|
||||
# time in seconds to wait for the correct 2FA answer
|
||||
2factor_timeout = 100
|
||||
|
||||
[smtp]
|
||||
# enable or disable the SMTP module
|
||||
@@ -323,6 +361,7 @@ IMAP_FOLDER = inbox
|
||||
[games]
|
||||
# if hop limit for the user exceeds this value, the message will be dropped
|
||||
game_hop_limit = 5
|
||||
disable_emojis = False
|
||||
# enable or disable the games module(s)
|
||||
dopeWars = True
|
||||
lemonade = True
|
||||
@@ -334,12 +373,22 @@ hangman = True
|
||||
hamtest = True
|
||||
tictactoe = True
|
||||
|
||||
# enable or disable the quiz game module questions are in data/quiz.json
|
||||
quiz = False
|
||||
|
||||
# enable or disable the survey game module questions are in data/survey/survey.json
|
||||
survey = False
|
||||
# Whether to record user ID in responses
|
||||
surveyRecordID=True
|
||||
# Whether to record location on start of survey
|
||||
surveyRecordLocation=True
|
||||
|
||||
[messagingSettings]
|
||||
# delay in seconds for response to avoid message collision /throttling
|
||||
responseDelay = 2.2
|
||||
# delay in seconds for splits in messages to avoid message collision /throttling
|
||||
splitDelay = 2.5
|
||||
# message chunk size for sending at high success rate, chunkr allows exceeding by 3 characters
|
||||
# message chunk size in charcters, chunkr allows exceeding by 3 characters
|
||||
MESSAGE_CHUNK_SIZE = 160
|
||||
# Request Acknowledgement of message OTA
|
||||
wantAck = False
|
||||
@@ -350,6 +399,7 @@ enableHopLogs = False
|
||||
# Noisy Node Telemetry Logging and packet threshold
|
||||
noisyNodeLogging = False
|
||||
noisyTelemetryLimit = 5
|
||||
logMetaStats = True
|
||||
# Enable detailed packet logging all packets
|
||||
DEBUGpacket = False
|
||||
# metaPacket detailed logging, the filter negates the port ID
|
||||
|
||||
1
data/mesh_news.txt
Normal file
1
data/mesh_news.txt
Normal file
@@ -0,0 +1 @@
|
||||
Today in meshtastic you are looking at the coolest bot on the block.
|
||||
16
data/quiz_questions.json
Normal file
16
data/quiz_questions.json
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"question": "Which RFband is commonly used by Meshtastic devices in US regions?",
|
||||
"answers": ["2.4 GHz", "433 MHz", "900 MHz", "5.8 GHz"],
|
||||
"correct": 2
|
||||
},
|
||||
{
|
||||
"question": "Yogi the bear 🐻 likes what food?",
|
||||
"answers": ["Picnic baskets", "Fish", "Burgers", "Hot dogs"],
|
||||
"correct": 0
|
||||
},
|
||||
{
|
||||
"question": "What is the password for the Meshtastic MQTT broker?",
|
||||
"answer": "large4cats"
|
||||
}
|
||||
]
|
||||
15
data/surveys/example_survey.json
Normal file
15
data/surveys/example_survey.json
Normal file
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"type": "multiple_choice",
|
||||
"question": "How Did you hear about us?",
|
||||
"options": ["Meshtastic", "Discord", "Friend", "Other"]
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"question": "How many nodes do you own?"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"question": "What feature would you like to see next?"
|
||||
}
|
||||
]
|
||||
15
data/surveys/snow_survey.json
Normal file
15
data/surveys/snow_survey.json
Normal file
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"type": "multiple_choice",
|
||||
"question": "How often do you experience snowfall in your area?",
|
||||
"options": ["Never", "Rarely", "Sometimes", "Often", "Every winter"]
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"question": "What was the deepest snowfall (in inches) you've measured at your location?"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"question": "Describe any challenges you face during heavy snowfall."
|
||||
}
|
||||
]
|
||||
@@ -9,6 +9,7 @@ projectName = "example_handler" # name of _handler function to match the functio
|
||||
randomNode = False # Set to True to use random node IDs
|
||||
|
||||
# bot.py Simulated functions
|
||||
deviceID = 1 # represents the device/node number
|
||||
def get_NodeID():
|
||||
nodeList = [4258675309, 1212121212, 1234567890, 9876543210]
|
||||
if randomNode:
|
||||
@@ -16,22 +17,43 @@ def get_NodeID():
|
||||
else:
|
||||
nodeID = nodeList[0]
|
||||
return nodeID
|
||||
nodeID = get_NodeID() # assign a nodeID
|
||||
def get_name_from_number(nodeID, length='short', interface=1):
|
||||
# return random name for nodeID
|
||||
names = ["Max","Molly","Jake","Kelly"]
|
||||
return names[nodeID % len(names)]
|
||||
#simulate GPS locations for testing
|
||||
locations = [
|
||||
(48.200909, -123.25719),
|
||||
(48.330283,-123.260703),
|
||||
(48.342735,-122.987911),
|
||||
(48.205591,-122.998448)
|
||||
]
|
||||
lat, lon = random.choice(locations) # pick a random location
|
||||
location = f"{lat},{lon}"
|
||||
# # end Initialization of the tool
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# # Function to handle, or the project in test
|
||||
#from modules.llm import * # Import the LLM module
|
||||
# # Project handler function code here
|
||||
|
||||
|
||||
# example handler function canada()
|
||||
def example_handler(message, nodeID, deviceID):
|
||||
readableTime = time.ctime(time.time())
|
||||
msg = "Hello World! "
|
||||
msg += f" You are Node ID: {nodeID} "
|
||||
msg += f" Its: {readableTime} "
|
||||
msg += f" You just sent: {message}"
|
||||
return msg
|
||||
if message != "":
|
||||
# put code in test here
|
||||
msg = f"Hello {get_name_from_number(nodeID)}, simulator ready for testing {projectName} project! on device {deviceID}"
|
||||
msg += f" Your location is {location}"
|
||||
msg += f" you said: {message}"
|
||||
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# # end of function test code
|
||||
@@ -42,7 +64,7 @@ if __name__ == '__main__': # represents the bot's main loop
|
||||
nodeInt = 1 # represents the device/node number
|
||||
logger.info(f"System: Meshing-Around Simulator Starting for {projectName}")
|
||||
nodeID = get_NodeID() # assign a nodeID
|
||||
projectResponse = globals()[projectName]("", nodeID, nodeInt) # Call the project handler under test
|
||||
projectResponse = globals()[projectName]("", nodeID, deviceID) # call the handler function once to start
|
||||
while True: # represents the onReceive() loop in the bot.py
|
||||
projectResponse = ""
|
||||
responseLength = 0
|
||||
@@ -51,7 +73,7 @@ if __name__ == '__main__': # represents the bot's main loop
|
||||
packet = input(f"CLIENT {nodeID} INPUT: " ) # Emulate the client input
|
||||
if packet != "":
|
||||
#try:
|
||||
projectResponse = globals()[projectName](message = packet, nodeID = nodeID, deviceID = nodeInt)
|
||||
projectResponse = globals()[projectName](message = packet, nodeID = nodeID, deviceID = deviceID) # call the handler function
|
||||
# except Exception as e:
|
||||
# logger.error(f"System: Handler: {e}")
|
||||
# projectResponse = "Error in handler"
|
||||
|
||||
643
mesh_bot.py
643
mesh_bot.py
@@ -15,13 +15,11 @@ from modules.log import *
|
||||
from modules.system import *
|
||||
|
||||
# list of commands to remove from the default list for DM only
|
||||
restrictedCommands = ["blackjack", "videopoker", "dopewars", "lemonstand", "golfsim", "mastermind", "hangman", "hamtest", "tictactoe"]
|
||||
restrictedCommands = ["blackjack", "videopoker", "dopewars", "lemonstand", "golfsim", "mastermind", "hangman", "hamtest", "tictactoe", "quiz", "q:", "survey", "s:"]
|
||||
restrictedResponse = "🤖only available in a Direct Message📵" # "" for none
|
||||
cmdHistory = [] # list to hold the command history for lheard and history commands
|
||||
msg_history = [] # list to hold the message history for the messages command
|
||||
|
||||
def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_number, deviceID, isDM):
|
||||
global cmdHistory, msg_history
|
||||
global cmdHistory
|
||||
#Auto response to messages
|
||||
message_lower = message.lower()
|
||||
bot_response = "🤖I'm sorry, I'm afraid I can't do that."
|
||||
@@ -43,6 +41,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
"checkin": lambda: handle_checklist(message, message_from_id, deviceID),
|
||||
"checklist": lambda: handle_checklist(message, message_from_id, deviceID),
|
||||
"checkout": lambda: handle_checklist(message, message_from_id, deviceID),
|
||||
"chess": lambda: handle_gTnW(chess=True),
|
||||
"clearsms": lambda: handle_sms(message_from_id, message),
|
||||
"cmd": lambda: handle_cmd(message, message_from_id, deviceID),
|
||||
"cq": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number),
|
||||
@@ -64,6 +63,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
"howfar": lambda: handle_howfar(message, message_from_id, deviceID, isDM),
|
||||
"howtall": lambda: handle_howtall(message, message_from_id, deviceID, isDM),
|
||||
"joke": lambda: tell_joke(message_from_id),
|
||||
"leaderboard": lambda: get_mesh_leaderboard(message, message_from_id, deviceID),
|
||||
"lemonstand": lambda: handleLemonade(message, message_from_id, deviceID),
|
||||
"lheard": lambda: handle_lheard(message, message_from_id, deviceID, isDM),
|
||||
"mastermind": lambda: handleMmind(message, message_from_id, deviceID),
|
||||
@@ -74,7 +74,10 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
"ping": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number),
|
||||
"pinging": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number),
|
||||
"pong": lambda: "🏓PING!!🛜",
|
||||
"readnews": lambda: read_news(),
|
||||
"q:": lambda: quizHandler(message, message_from_id, deviceID),
|
||||
"quiz": lambda: quizHandler(message, message_from_id, deviceID),
|
||||
"readnews": lambda: handleNews(message_from_id, deviceID, message, isDM),
|
||||
"readrss": lambda: get_rss_feed(message),
|
||||
"riverflow": lambda: handle_riverFlow(message, message_from_id, deviceID),
|
||||
"rlist": lambda: handle_repeaterQuery(message_from_id, deviceID, channel_number),
|
||||
"satpass": lambda: handle_satpass(message_from_id, deviceID, channel_number, message),
|
||||
@@ -84,10 +87,13 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
"sms:": lambda: handle_sms(message_from_id, message),
|
||||
"solar": lambda: drap_xray_conditions() + "\n" + solar_conditions(),
|
||||
"sun": lambda: handle_sun(message_from_id, deviceID, channel_number),
|
||||
"survey": lambda: surveyHandler(message, message_from_id, deviceID),
|
||||
"s:": lambda: surveyHandler(message, message_from_id, deviceID),
|
||||
"sysinfo": lambda: sysinfo(message, message_from_id, deviceID),
|
||||
"test": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number),
|
||||
"testing": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number),
|
||||
"tictactoe": lambda: handleTicTacToe(message, message_from_id, deviceID),
|
||||
"tic-tac-toe": lambda: handleTicTacToe(message, message_from_id, deviceID),
|
||||
"tide": lambda: handle_tide(message_from_id, deviceID, channel_number),
|
||||
"valert": lambda: get_volcano_usgs(),
|
||||
"videopoker": lambda: handleVideoPoker(message, message_from_id, deviceID),
|
||||
@@ -135,20 +141,24 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
if len(cmds) > 0:
|
||||
# sort the commands by index value
|
||||
cmds = sorted(cmds, key=lambda k: k['index'])
|
||||
logger.debug(f"System: Bot detected Commands:{cmds} From: {get_name_from_number(message_from_id)}")
|
||||
# check the command isnt a isDM only command
|
||||
if cmds[0]['cmd'] in restrictedCommands and not isDM:
|
||||
bot_response = restrictedResponse
|
||||
|
||||
# Check if user is already playing a game
|
||||
playing, game = isPlayingGame(message_from_id)
|
||||
|
||||
# Block restricted commands if not DM, or if already playing a game
|
||||
if (cmds[0]['cmd'] in restrictedCommands and not isDM) or (cmds[0]['cmd'] in restrictedCommands and playing):
|
||||
if playing:
|
||||
bot_response = f"🤖You are already playing {game}, finish that first."
|
||||
else:
|
||||
bot_response = restrictedResponse
|
||||
else:
|
||||
logger.debug(f"System: Bot detected Commands:{cmds} From: {get_name_from_number(message_from_id)}")
|
||||
# run the first command after sorting
|
||||
bot_response = command_handler[cmds[0]['cmd']]()
|
||||
# append the command to the cmdHistory list for lheard and history
|
||||
if len(cmdHistory) > 50:
|
||||
cmdHistory.pop(0)
|
||||
cmdHistory.append({'nodeID': message_from_id, 'cmd': cmds[0]['cmd'], 'time': time.time()})
|
||||
|
||||
# wait a responseDelay to avoid message collision from lora-ack
|
||||
time.sleep(responseDelay)
|
||||
return bot_response
|
||||
|
||||
def handle_cmd(message, message_from_id, deviceID):
|
||||
@@ -267,8 +277,6 @@ def handle_emergency(message_from_id, deviceID, message):
|
||||
if enableSMTP:
|
||||
for user in sysopEmails:
|
||||
send_email(user, f"Emergency Assistance Requested by {nodeInfo} in {message}", message_from_id)
|
||||
# respond to the user
|
||||
time.sleep(responseDelay + 2)
|
||||
return EMERGENCY_RESPONSE
|
||||
|
||||
def handle_motd(message, message_from_id, isDM):
|
||||
@@ -301,7 +309,7 @@ def handle_motd(message, message_from_id, isDM):
|
||||
|
||||
def handle_echo(message, message_from_id, deviceID, isDM, channel_number):
|
||||
if "?" in message.lower():
|
||||
return "echo command returns your message back to you. Example:echo Hello World"
|
||||
return "command returns your message back to you. Example:echo Hello World"
|
||||
elif "echo " in message.lower():
|
||||
parts = message.lower().split("echo ", 1)
|
||||
if len(parts) > 1 and parts[1].strip() != "":
|
||||
@@ -329,6 +337,26 @@ def handle_wxalert(message_from_id, deviceID, message):
|
||||
weatherAlert = weatherAlert[0]
|
||||
return weatherAlert
|
||||
|
||||
def handleNews(message_from_id, deviceID, message, isDM):
|
||||
news = ''
|
||||
# if news source is provided pass that to read_news()
|
||||
if "?" in message.lower():
|
||||
return "returns the news. Add a source e.g. 📰readnews mesh"
|
||||
elif "readnews" in message.lower():
|
||||
source = message.lower().replace("readnews", "").strip()
|
||||
if source:
|
||||
news = read_news(source)
|
||||
else:
|
||||
news = read_news()
|
||||
|
||||
if news:
|
||||
# if not a DM add the username to the beginning of msg
|
||||
if not useDMForResponse and not isDM:
|
||||
news = "@" + get_name_from_number(message_from_id, 'short', deviceID) + " " + news
|
||||
return news
|
||||
else:
|
||||
return "No news for you!"
|
||||
|
||||
def handle_howfar(message, message_from_id, deviceID, isDM):
|
||||
msg = ''
|
||||
location = get_node_location(message_from_id, deviceID)
|
||||
@@ -520,35 +548,49 @@ def handle_llm(message_from_id, channel_number, deviceID, message, publicChannel
|
||||
llmTotalRuntime.append(end - start)
|
||||
|
||||
return response
|
||||
|
||||
def handleDopeWars(message, nodeID, rxNode):
|
||||
global dwPlayerTracker, dwHighScore
|
||||
|
||||
# get player's last command
|
||||
last_cmd = None
|
||||
for i in range(0, len(dwPlayerTracker)):
|
||||
if dwPlayerTracker[i].get('userID') == nodeID:
|
||||
last_cmd = dwPlayerTracker[i].get('cmd')
|
||||
|
||||
# welcome new player
|
||||
if not last_cmd and nodeID != 0:
|
||||
|
||||
# Find player in tracker
|
||||
player = next((p for p in dwPlayerTracker if p.get('userID') == nodeID), None)
|
||||
|
||||
# If not found, add new player
|
||||
if not player and nodeID != 0 and not isPlayingGame(nodeID)[0]:
|
||||
player = {
|
||||
'userID': nodeID,
|
||||
'last_played': time.time(),
|
||||
'cmd': 'new',
|
||||
# ... add other fields as needed ...
|
||||
}
|
||||
dwPlayerTracker.append(player)
|
||||
msg = 'Welcome to 💊Dope Wars💉 You have ' + str(total_days) + ' days to make as much 💰 as possible! '
|
||||
high_score = getHighScoreDw()
|
||||
msg += 'The High Score is $' + "{:,}".format(high_score.get('cash')) + ' by user ' + get_name_from_number(high_score.get('userID') , 'short', rxNode) +'\n'
|
||||
msg += 'The High Score is $' + "{:,}".format(high_score.get('cash')) + ' by user ' + get_name_from_number(high_score.get('userID'), 'short', rxNode) + '\n'
|
||||
msg += playDopeWars(nodeID, message)
|
||||
else:
|
||||
logger.debug(f"System: {nodeID} PlayingGame dopewars last_cmd: {last_cmd}")
|
||||
elif player:
|
||||
# Update last_played and cmd for the player
|
||||
for p in dwPlayerTracker:
|
||||
if p.get('userID') == nodeID:
|
||||
p['last_played'] = time.time()
|
||||
msg = playDopeWars(nodeID, message)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(responseDelay + 1)
|
||||
|
||||
# if message starts wth 'e'xit remove player from tracker
|
||||
if message.lower().startswith('e'):
|
||||
dwPlayerTracker[:] = [p for p in dwPlayerTracker if p.get('userID') != nodeID]
|
||||
msg = 'You have exited Dope Wars.'
|
||||
return msg
|
||||
|
||||
def handle_gTnW():
|
||||
def handle_gTnW(chess = False):
|
||||
chess = ["How about a nice game of chess?", "Shall we play a game of chess?", "Would you like to play a game of chess?", "f3, to e5, g4??"]
|
||||
response = ["The only winning move is not to play.", "What are you doing, Dave?",\
|
||||
"Greetings, Professor Falken.", "Shall we play a game?", "How about a nice game of chess?",\
|
||||
"You are a hard man to reach. Could not find you in Seattle and no terminal is in operation at your classified address.",\
|
||||
"I should reach Defcon 1 and release my missiles in 28 hours.","T-minus thirty","Malfunction 54: Treatment pause;dose input 2", "reticulating splines"]
|
||||
length = len(response)
|
||||
chess_length = len(chess)
|
||||
if chess:
|
||||
response = chess
|
||||
length = chess_length
|
||||
indices = list(range(length))
|
||||
# Shuffle the indices using a convoluted method
|
||||
for i in range(length):
|
||||
@@ -561,119 +603,118 @@ def handle_gTnW():
|
||||
def handleLemonade(message, nodeID, deviceID):
|
||||
global lemonadeTracker, lemonadeCups, lemonadeLemons, lemonadeSugar, lemonadeWeeks, lemonadeScore, lemon_starting_cash, lemon_total_weeks
|
||||
msg = ""
|
||||
|
||||
def create_player(nodeID):
|
||||
# create new player
|
||||
logger.debug("System: Lemonade: New Player: " + str(nodeID))
|
||||
lemonadeTracker.append({'nodeID': nodeID, 'cups': 0, 'lemons': 0, 'sugar': 0, 'cash': lemon_starting_cash, 'start': lemon_starting_cash, 'cmd': 'new', 'time': time.time()})
|
||||
lemonadeTracker.append({'nodeID': nodeID, 'cups': 0, 'lemons': 0, 'sugar': 0, 'cash': lemon_starting_cash, 'start': lemon_starting_cash, 'cmd': 'new', 'last_played': time.time()})
|
||||
lemonadeCups.append({'nodeID': nodeID, 'cost': 2.50, 'count': 25, 'min': 0.99, 'unit': 0.00})
|
||||
lemonadeLemons.append({'nodeID': nodeID, 'cost': 4.00, 'count': 8, 'min': 2.00, 'unit': 0.00})
|
||||
lemonadeSugar.append({'nodeID': nodeID, 'cost': 3.00, 'count': 15, 'min': 1.50, 'unit': 0.00})
|
||||
lemonadeScore.append({'nodeID': nodeID, 'value': 0.00, 'total': 0.00})
|
||||
lemonadeWeeks.append({'nodeID': nodeID, 'current': 1, 'total': lemon_total_weeks, 'sales': 99, 'potential': 0, 'unit': 0.00, 'price': 0.00, 'total_sales': 0})
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
last_cmd = ""
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = lemonadeTracker[i]['cmd']
|
||||
|
||||
logger.debug(f"System: {nodeID} PlayingGame lemonstand last_cmd: {last_cmd}")
|
||||
# create new player if not in tracker
|
||||
if last_cmd == "" and nodeID != 0:
|
||||
# If player not found, create if message is for lemonstand
|
||||
if nodeID != 0 and "lemonstand" in message.lower():
|
||||
create_player(nodeID)
|
||||
msg += "Welcome🍋🥤"
|
||||
# Play lemonstand with newgame=True
|
||||
fruit = playLemonstand(nodeID=nodeID, message=message, celsius=False, newgame=True)
|
||||
if fruit:
|
||||
msg += fruit
|
||||
return msg
|
||||
|
||||
# high score
|
||||
highScore = {"userID": 0, "cash": 0, "success": 0}
|
||||
# if message starts wth 'e'xit remove player from tracker
|
||||
if message.lower().startswith("e"):
|
||||
logger.debug(f"System: Lemonade: {nodeID} is leaving the stand")
|
||||
msg = "You have left the Lemonade Stand."
|
||||
highScore = getHighScoreLemon()
|
||||
if highScore != 0:
|
||||
if highScore['userID'] != 0:
|
||||
nodeName = get_name_from_number(highScore['userID'])
|
||||
if nodeName.isnumeric() and multiple_interface:
|
||||
logger.debug(f"System: TODO is multiple interface fix mention this please nodeName: {nodeName}")
|
||||
#nodeName = get_name_from_number(highScore['userID'], 'long', 2)
|
||||
msg += f" HighScore🥇{nodeName} 💰{round(highScore['cash'], 2)}k "
|
||||
|
||||
msg += start_lemonade(nodeID=nodeID, message=message, celsius=False)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(responseDelay + 1)
|
||||
if highScore != 0 and highScore['userID'] != 0:
|
||||
nodeName = get_name_from_number(highScore['userID'])
|
||||
msg += f" HighScore🥇{nodeName} 💰{round(highScore['cash'], 2)}k "
|
||||
# remove player from player tracker and inventory trackers
|
||||
lemonadeTracker[:] = [p for p in lemonadeTracker if p['nodeID'] != nodeID]
|
||||
lemonadeCups[:] = [p for p in lemonadeCups if p['nodeID'] != nodeID]
|
||||
lemonadeLemons[:] = [p for p in lemonadeLemons if p['nodeID'] != nodeID]
|
||||
lemonadeSugar[:] = [p for p in lemonadeSugar if p['nodeID'] != nodeID]
|
||||
lemonadeWeeks[:] = [p for p in lemonadeWeeks if p['nodeID'] != nodeID]
|
||||
lemonadeScore[:] = [p for p in lemonadeScore if p['nodeID'] != nodeID]
|
||||
return msg
|
||||
|
||||
# play lemonstand (not newgame)
|
||||
if ("lemonstand" not in message.lower() and message != ""):
|
||||
fruit = playLemonstand(nodeID=nodeID, message=message, celsius=False, newgame=False)
|
||||
if fruit:
|
||||
msg += fruit
|
||||
return msg
|
||||
|
||||
def handleBlackJack(message, nodeID, deviceID):
|
||||
global jackTracker
|
||||
msg = ""
|
||||
|
||||
# get player's last command from tracker
|
||||
last_cmd = ""
|
||||
for i in range(len(jackTracker)):
|
||||
if jackTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = jackTracker[i]['cmd']
|
||||
# Find player in tracker
|
||||
player = next((p for p in jackTracker if p['nodeID'] == nodeID), None)
|
||||
|
||||
# if player sends a L for leave table
|
||||
# Handle leave command
|
||||
if message.lower().startswith("l"):
|
||||
logger.debug(f"System: BlackJack: {nodeID} is leaving the table")
|
||||
msg = "You have left the table."
|
||||
for i in range(len(jackTracker)):
|
||||
if jackTracker[i]['nodeID'] == nodeID:
|
||||
jackTracker.pop(i)
|
||||
jackTracker[:] = [p for p in jackTracker if p['nodeID'] != nodeID]
|
||||
return msg
|
||||
|
||||
else:
|
||||
# Play BlackJack
|
||||
msg = playBlackJack(nodeID=nodeID, message=message)
|
||||
|
||||
if last_cmd != "" and nodeID != 0:
|
||||
logger.debug(f"System: {nodeID} PlayingGame blackjack last_cmd: {last_cmd}")
|
||||
else:
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
highScore = loadHSJack()
|
||||
if highScore != 0:
|
||||
if highScore['nodeID'] != 0:
|
||||
nodeName = get_name_from_number(highScore['nodeID'])
|
||||
if nodeName.isnumeric() and multiple_interface:
|
||||
logger.debug(f"System: TODO is multiple interface fix mention this please nodeName: {nodeName}")
|
||||
#nodeName = get_name_from_number(highScore['nodeID'], 'long', 2)
|
||||
msg += f" HighScore🥇{nodeName} with {highScore['highScore']} chips. "
|
||||
time.sleep(responseDelay + 1) # short answers with long replies can cause message collision added wait
|
||||
# Create new player if not found
|
||||
if not player and nodeID != 0:
|
||||
jackTracker.append({'nodeID': nodeID, 'cmd': 'new', 'last_played': time.time()})
|
||||
msg += "Welcome to 🃏BlackJack!🃏\n"
|
||||
# Show high score if available
|
||||
highScore = loadHSJack()
|
||||
if highScore and highScore.get('nodeID', 0) != 0:
|
||||
nodeName = get_name_from_number(highScore['nodeID'])
|
||||
if nodeName.isnumeric() and multiple_interface:
|
||||
logger.debug(f"System: TODO is multiple interface fix mention this please nodeName: {nodeName}")
|
||||
msg += f" HighScore🥇{nodeName} with {highScore['highScore']} chips. "
|
||||
player = next((p for p in jackTracker if p['nodeID'] == nodeID), None)
|
||||
|
||||
# Always update last_played for existing player
|
||||
if player:
|
||||
player['last_played'] = time.time()
|
||||
|
||||
# Play BlackJack
|
||||
msg += playBlackJack(nodeID=nodeID, message=message)
|
||||
return msg
|
||||
|
||||
def handleVideoPoker(message, nodeID, deviceID):
|
||||
global vpTracker
|
||||
msg = ""
|
||||
|
||||
# if player sends a L for leave table
|
||||
# Find player in tracker
|
||||
player = next((p for p in vpTracker if p['nodeID'] == nodeID), None)
|
||||
|
||||
# Handle leave command
|
||||
if message.lower().startswith("l"):
|
||||
logger.debug(f"System: VideoPoker: {nodeID} is leaving the table")
|
||||
msg = "You have left the table."
|
||||
for i in range(len(vpTracker)):
|
||||
if vpTracker[i]['nodeID'] == nodeID:
|
||||
vpTracker.pop(i)
|
||||
vpTracker[:] = [p for p in vpTracker if p['nodeID'] != nodeID]
|
||||
return msg
|
||||
else:
|
||||
# Play Video Poker
|
||||
msg = playVideoPoker(nodeID=nodeID, message=message)
|
||||
|
||||
# get player's last command from tracker
|
||||
last_cmd = ""
|
||||
for i in range(len(vpTracker)):
|
||||
if vpTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = vpTracker[i]['cmd']
|
||||
# Create new player if not found
|
||||
if not player and nodeID != 0:
|
||||
vpTracker.append({'nodeID': nodeID, 'cmd': 'new', 'last_played': time.time()})
|
||||
msg += "Welcome to 🎰Video Poker!🎰\n"
|
||||
# Show high score if available
|
||||
highScore = loadHSVp()
|
||||
if highScore and highScore.get('nodeID', 0) != 0:
|
||||
nodeName = get_name_from_number(highScore['nodeID'])
|
||||
if nodeName.isnumeric() and multiple_interface:
|
||||
logger.debug(f"System: TODO is multiple interface fix mention this please nodeName: {nodeName}")
|
||||
msg += f" HighScore🥇{nodeName} with {highScore['highScore']} coins. "
|
||||
player = next((p for p in vpTracker if p['nodeID'] == nodeID), None)
|
||||
|
||||
# find higest dollar amount in tracker for high score
|
||||
if last_cmd == "new":
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
highScore = loadHSVp()
|
||||
if highScore != 0:
|
||||
if highScore['nodeID'] != 0:
|
||||
nodeName = get_name_from_number(highScore['nodeID'])
|
||||
if nodeName.isnumeric() and multiple_interface:
|
||||
logger.debug(f"System: TODO is multiple interface fix mention this please nodeName: {nodeName}")
|
||||
#nodeName = get_name_from_number(highScore['nodeID'], 'long', 2)
|
||||
msg += f" HighScore🥇{nodeName} with {highScore['highScore']} coins. "
|
||||
|
||||
if last_cmd != "" and nodeID != 0:
|
||||
logger.debug(f"System: {nodeID} PlayingGame videopoker last_cmd: {last_cmd}")
|
||||
time.sleep(responseDelay + 1) # short answers with long replies can cause message collision added wait
|
||||
# Always update last_played for existing player
|
||||
if player:
|
||||
player['last_played'] = time.time()
|
||||
|
||||
# Play Video Poker
|
||||
msg += playVideoPoker(nodeID=nodeID, message=message)
|
||||
return msg
|
||||
|
||||
def handleMmind(message, nodeID, deviceID):
|
||||
@@ -686,10 +727,18 @@ def handleMmind(message, nodeID, deviceID):
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
mindTracker.pop(i)
|
||||
highscore = getHighScoreMMind(0, 0, 'n')
|
||||
if highscore != 0:
|
||||
nodeName = get_name_from_number(highscore[0]['nodeID'],'long',deviceID)
|
||||
msg += f"🧠HighScore🥇{nodeName} with {highscore[0]['turns']} turns difficulty {highscore[0]['diff'].upper()}"
|
||||
hscore = getHighScoreMMind(0, 0, 'n')
|
||||
if hscore and isinstance(hscore[0], dict):
|
||||
highNode = hscore[0].get('nodeID', 0)
|
||||
highTurns = hscore[0].get('turns', 0)
|
||||
highDiff = hscore[0].get('diff', 'n')
|
||||
else:
|
||||
highNode = 0
|
||||
highTurns = 0
|
||||
highDiff = 'n'
|
||||
nodeName = get_name_from_number(int(highNode),'long',deviceID)
|
||||
if highNode != 0 and highTurns > 1:
|
||||
msg += f"🧠HighScore🥇{nodeName} with {highTurns} turns difficulty {highDiff}"
|
||||
return msg
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
@@ -710,8 +759,6 @@ def handleMmind(message, nodeID, deviceID):
|
||||
return msg
|
||||
|
||||
msg += start_mMind(nodeID=nodeID, message=message)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(responseDelay + 1)
|
||||
return msg
|
||||
|
||||
def handleGolf(message, nodeID, deviceID):
|
||||
@@ -742,8 +789,6 @@ def handleGolf(message, nodeID, deviceID):
|
||||
msg += f"Clubs: (D)river, (L)ow Iron, (M)id Iron, (H)igh Iron, (G)ap Wedge, Lob (W)edge\n"
|
||||
|
||||
msg += playGolf(nodeID=nodeID, message=message)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(responseDelay + 1)
|
||||
return msg
|
||||
|
||||
def handleHangman(message, nodeID, deviceID):
|
||||
@@ -770,8 +815,6 @@ def handleHangman(message, nodeID, deviceID):
|
||||
)
|
||||
msg = "🧩Hangman🤖 'end' to cut rope🪢\n"
|
||||
msg += hangman.play(nodeID, message)
|
||||
|
||||
time.sleep(responseDelay + 1)
|
||||
return msg
|
||||
|
||||
def handleHamtest(message, nodeID, deviceID):
|
||||
@@ -805,8 +848,6 @@ def handleHamtest(message, nodeID, deviceID):
|
||||
# if the message is an answer A B C or D upper or lower case
|
||||
if response[0].upper() in ['A', 'B', 'C', 'D']:
|
||||
msg = hamtest.answer(nodeID, response[0])
|
||||
|
||||
time.sleep(responseDelay + 1)
|
||||
return msg
|
||||
|
||||
def handleTicTacToe(message, nodeID, deviceID):
|
||||
@@ -832,22 +873,127 @@ def handleTicTacToe(message, nodeID, deviceID):
|
||||
"nodeID": nodeID,
|
||||
"last_played": time.time()
|
||||
})
|
||||
msg = "🎯Tic-Tac-Toe🤖 '(e)nd' to Quit\n"
|
||||
msg = "🎯Tic-Tac-Toe🤖 '(e)nd'\n"
|
||||
|
||||
msg += tictactoe.play(nodeID, message)
|
||||
return msg
|
||||
|
||||
def quizHandler(message, nodeID, deviceID):
|
||||
user_name = get_name_from_number(nodeID)
|
||||
user_id = nodeID
|
||||
msg = ''
|
||||
user_answer = ''
|
||||
user_answer = message.lower()
|
||||
user_answer = user_answer.replace("quiz","").replace("q:","").strip()
|
||||
if user_answer.startswith("!") and cmdBang:
|
||||
user_answer = user_answer[1:].strip()
|
||||
if user_answer:
|
||||
if user_answer.startswith("start"):
|
||||
msg = quizGamePlayer.start_game(user_id)
|
||||
elif user_answer.startswith("stop"):
|
||||
msg = quizGamePlayer.stop_game(user_id)
|
||||
elif user_answer.startswith("join"):
|
||||
msg = quizGamePlayer.join(user_id)
|
||||
elif user_answer.startswith("leave"):
|
||||
msg = quizGamePlayer.leave(user_id)
|
||||
elif user_answer.startswith("next"):
|
||||
msg = quizGamePlayer.next_question(user_id)
|
||||
elif user_answer.startswith("score"):
|
||||
if user_id in quizGamePlayer.players:
|
||||
score = quizGamePlayer.players[user_id]['score']
|
||||
msg = f"Your score: {score}"
|
||||
else:
|
||||
msg = "You are not in the quiz."
|
||||
elif user_answer.startswith("top"):
|
||||
msg = quizGamePlayer.top_three()
|
||||
elif user_answer.startswith("broadcast"):
|
||||
broadcast_msg = user_answer.replace("broadcast", "", 1).strip()
|
||||
msg = quizGamePlayer.broadcast(user_id, broadcast_msg)
|
||||
elif user_answer.startswith("?"):
|
||||
msg = ("Quiz Commands:\n"
|
||||
"q: join - Join the current quiz\n"
|
||||
"q: leave - Leave the current quiz\n"
|
||||
"q: <your answer> - Answer the current question\n"
|
||||
"q: score - Show your current score\n"
|
||||
"q: top - Show top 3 players\n")
|
||||
else:
|
||||
msg = quizGamePlayer.answer(user_id, user_answer)
|
||||
|
||||
# set username on top 3
|
||||
if "🏆 Top" in msg:
|
||||
#replace all the 10 digit numbers with the short name
|
||||
for part in msg.split():
|
||||
part = part.rstrip(":")
|
||||
if len(part) == 10:
|
||||
player_name = get_name_from_number(int(part), 'short', deviceID)
|
||||
msg = msg.replace(part, player_name)
|
||||
|
||||
# broadcast message to all players if user is in bbs_admin_list and msg is a dict with 'message' key
|
||||
if isinstance(msg, dict) and str(nodeID) in bbs_admin_list and 'message' in msg:
|
||||
for player_id in quizGamePlayer.players:
|
||||
send_message(msg['message'], 0, player_id, deviceID)
|
||||
time.sleep(responseDelay)
|
||||
msg = f"Message sent to {len(quizGamePlayer.players)} players"
|
||||
|
||||
return msg
|
||||
else:
|
||||
return "🧠Please provide an answer or command, or send q: ?"
|
||||
|
||||
def surveyHandler(message, nodeID, deviceID):
|
||||
global surveyTracker
|
||||
location = get_node_location(nodeID, deviceID)
|
||||
msg = ''
|
||||
# Normalize and parse the command
|
||||
msg_lower = message.lower().strip()
|
||||
surveySays = msg_lower
|
||||
if msg_lower.startswith("survey"):
|
||||
surveySays = surveySays.removeprefix("survey").strip()
|
||||
elif msg_lower.startswith("s:"):
|
||||
surveySays = surveySays.removeprefix("s:").strip()
|
||||
|
||||
time.sleep(responseDelay + 1)
|
||||
# Handle end command
|
||||
if surveySays == "end":
|
||||
if nodeID not in survey_module.responses:
|
||||
return "No active survey session to end."
|
||||
return survey_module.end_survey(user_id=nodeID)
|
||||
|
||||
# Handle report command
|
||||
if surveySays == "report":
|
||||
#return survey_module.quiz_report()
|
||||
# reminder to fix int and open question reporting
|
||||
return "Report not implemented yet"
|
||||
|
||||
# Update last played or add new tracker entry
|
||||
found = False
|
||||
for entry in surveyTracker:
|
||||
if entry.get('nodeID') == nodeID:
|
||||
entry['last_played'] = time.time()
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
surveyTracker.append({'nodeID': nodeID, 'last_played': time.time()})
|
||||
|
||||
# If not in survey session, start one
|
||||
if nodeID not in survey_module.responses:
|
||||
msg = survey_module.start_survey(user_id=nodeID, survey_name=surveySays, location=location)
|
||||
else:
|
||||
# Process the answer
|
||||
msg = survey_module.answer(user_id=nodeID, answer=surveySays, location=location)
|
||||
|
||||
return msg
|
||||
|
||||
def handle_riverFlow(message, message_from_id, deviceID):
|
||||
location = get_node_location(message_from_id, deviceID)
|
||||
|
||||
if "riverflow " in message.lower() and "," in message:
|
||||
userRiver = message.lower().split("riverflow ", 1)[1].strip()
|
||||
userRiver = [r.strip() for r in userRiver.split(",") if r.strip()]
|
||||
msg_lower = message.lower()
|
||||
if "riverflow " in msg_lower:
|
||||
user_input = msg_lower.split("riverflow ", 1)[1].strip()
|
||||
if user_input:
|
||||
userRiver = [r.strip() for r in user_input.split(",") if r.strip()]
|
||||
else:
|
||||
userRiver = riverListDefault
|
||||
else:
|
||||
userRiver = riverListDefault
|
||||
|
||||
|
||||
if use_meteo_wxApi:
|
||||
return get_flood_openmeteo(location[0], location[1])
|
||||
else:
|
||||
@@ -954,14 +1100,46 @@ def handle_messages(message, deviceID, channel_number, msg_history, publicChanne
|
||||
return message.split("?")[0].title() + " command returns the last " + str(storeFlimit) + " messages sent on a channel."
|
||||
else:
|
||||
response = ""
|
||||
for msgH in msg_history:
|
||||
header = f"📨Messages:\n"
|
||||
# Calculate safe byte limit (account for header and some overhead)
|
||||
header_bytes = len(header.encode('utf-8'))
|
||||
available_bytes = max_bytes - header_bytes
|
||||
|
||||
# Reverse the message history to show most recent first
|
||||
for msgH in reversed(msg_history):
|
||||
# number of messages to return +1 for the header line
|
||||
if len(response.split("\n")) >= storeFlimit + 1:
|
||||
break
|
||||
# if the message is for this deviceID and channel or publicChannel
|
||||
if msgH[4] == deviceID:
|
||||
if msgH[2] == channel_number or msgH[2] == publicChannel:
|
||||
response += f"\n{msgH[0]}: {msgH[1]}"
|
||||
new_line = f"\n{msgH[0]}: {msgH[1]}"
|
||||
# Check if adding this line would exceed byte limit
|
||||
test_response = response + new_line
|
||||
if len(test_response.encode('utf-8')) > available_bytes:
|
||||
# Try to add truncated version of the message
|
||||
msg_text = msgH[1]
|
||||
truncated = False
|
||||
while len(msg_text) > 0 and len((response + f"\n{msgH[0]}: {msg_text}").encode('utf-8')) > available_bytes:
|
||||
# Remove one character at a time from the end
|
||||
msg_text = msg_text[:-1]
|
||||
truncated = True
|
||||
if len(msg_text) > 10: # Only add if we have at least 10 chars left
|
||||
response += f"\n{msgH[0]}: {msg_text}" + ("..." if truncated else "")
|
||||
break # Stop adding more messages
|
||||
else:
|
||||
response += new_line
|
||||
|
||||
if reverseSF:
|
||||
# segassem reverse the order of the messages
|
||||
response_lines = response.split("\n")
|
||||
response_lines.reverse()
|
||||
response = "\n".join(response_lines)
|
||||
|
||||
if len(response) > 0:
|
||||
return "Message History:" + response
|
||||
return header + response
|
||||
else:
|
||||
return "No messages in history"
|
||||
return "No 📭messages in history"
|
||||
|
||||
def handle_sun(message_from_id, deviceID, channel_number):
|
||||
location = get_node_location(message_from_id, deviceID, channel_number)
|
||||
@@ -1147,43 +1325,68 @@ def check_and_play_game(tracker, message_from_id, message_string, rxNode, channe
|
||||
global llm_enabled
|
||||
|
||||
for i in range(len(tracker)):
|
||||
if tracker[i].get('nodeID') == message_from_id or tracker[i].get('userID') == message_from_id:
|
||||
# Use 'userID'
|
||||
id_key = 'userID' if game_name == "DopeWars" else 'nodeID' # DopeWars uses 'userID'
|
||||
id_key = 'id' if game_name == "Survey" else id_key # Survey uses 'id'
|
||||
|
||||
if tracker[i].get(id_key) == message_from_id:
|
||||
last_played_key = 'last_played' if 'last_played' in tracker[i] else 'time'
|
||||
if tracker[i].get(last_played_key) > (time.time() - GAMEDELAY):
|
||||
if llm_enabled:
|
||||
logger.debug(f"System: LLM Disabled for {message_from_id} for duration of {game_name}")
|
||||
|
||||
# play the game
|
||||
send_message(handle_game_func(message_string, message_from_id, rxNode), channel_number, message_from_id, rxNode)
|
||||
return True, game_name
|
||||
else:
|
||||
# pop if the time exceeds 8 hours
|
||||
tracker.pop(i)
|
||||
return False, game_name
|
||||
return False, "None"
|
||||
|
||||
def checkPlayingGame(message_from_id, message_string, rxNode, channel_number):
|
||||
gameTrackers = [
|
||||
(dwPlayerTracker, "DopeWars", handleDopeWars) if 'dwPlayerTracker' in globals() else None,
|
||||
(lemonadeTracker, "LemonadeStand", handleLemonade) if 'lemonadeTracker' in globals() else None,
|
||||
(vpTracker, "VideoPoker", handleVideoPoker) if 'vpTracker' in globals() else None,
|
||||
(jackTracker, "BlackJack", handleBlackJack) if 'jackTracker' in globals() else None,
|
||||
(mindTracker, "MasterMind", handleMmind) if 'mindTracker' in globals() else None,
|
||||
(golfTracker, "GolfSim", handleGolf) if 'golfTracker' in globals() else None,
|
||||
(hangmanTracker, "Hangman", handleHangman) if 'hangmanTracker' in globals() else None,
|
||||
(hamtestTracker, "HamTest", handleHamtest) if 'hamtestTracker' in globals() else None,
|
||||
(tictactoeTracker, "TicTacToe", handleTicTacToe) if 'tictactoeTracker' in globals() else None,
|
||||
(surveyTracker, "Survey", surveyHandler) if 'surveyTracker' in globals() else None,
|
||||
#quiz does not use a tracker (quizGamePlayer) always active
|
||||
]
|
||||
|
||||
def isPlayingGame(message_from_id):
|
||||
global gameTrackers
|
||||
trackers = gameTrackers.copy()
|
||||
playingGame = False
|
||||
game = "None"
|
||||
|
||||
trackers = [tracker for tracker in trackers if tracker is not None]
|
||||
|
||||
for tracker, game_name, handle_game_func in trackers:
|
||||
for i in range(len(tracker)-1, -1, -1): # iterate backwards for safe removal
|
||||
id_key = 'userID' if game_name == "DopeWars" else 'nodeID'
|
||||
id_key = 'id' if game_name == "Survey" else id_key
|
||||
if tracker[i].get(id_key) == message_from_id:
|
||||
last_played_key = 'last_played' if 'last_played' in tracker[i] else 'time'
|
||||
if tracker[i].get(last_played_key, 0) > (time.time() - GAMEDELAY):
|
||||
playingGame = True
|
||||
game = game_name
|
||||
break
|
||||
if playingGame:
|
||||
break
|
||||
|
||||
return playingGame, game
|
||||
|
||||
def checkPlayingGame(message_from_id, message_string, rxNode, channel_number):
|
||||
global gameTrackers
|
||||
trackers = gameTrackers.copy()
|
||||
playingGame = False
|
||||
game = "None"
|
||||
|
||||
trackers = [
|
||||
(dwPlayerTracker, "DopeWars", handleDopeWars) if 'dwPlayerTracker' in globals() else None,
|
||||
(lemonadeTracker, "LemonadeStand", handleLemonade) if 'lemonadeTracker' in globals() else None,
|
||||
(vpTracker, "VideoPoker", handleVideoPoker) if 'vpTracker' in globals() else None,
|
||||
(jackTracker, "BlackJack", handleBlackJack) if 'jackTracker' in globals() else None,
|
||||
(mindTracker, "MasterMind", handleMmind) if 'mindTracker' in globals() else None,
|
||||
(golfTracker, "GolfSim", handleGolf) if 'golfTracker' in globals() else None,
|
||||
(hangmanTracker, "Hangman", handleHangman) if 'hangmanTracker' in globals() else None,
|
||||
(hamtestTracker, "HamTest", handleHamtest) if 'hamtestTracker' in globals() else None,
|
||||
(tictactoeTracker, "TicTacToe", handleTicTacToe) if 'tictactoeTracker' in globals() else None,
|
||||
]
|
||||
trackers = [tracker for tracker in trackers if tracker is not None]
|
||||
|
||||
for tracker, game_name, handle_game_func in trackers:
|
||||
playingGame, game = check_and_play_game(tracker, message_from_id, message_string, rxNode, channel_number, game_name, handle_game_func)
|
||||
if playingGame:
|
||||
break
|
||||
|
||||
return playingGame
|
||||
|
||||
def onReceive(packet, interface):
|
||||
@@ -1354,13 +1557,15 @@ def onReceive(packet, interface):
|
||||
# DM is useful for games or LLM
|
||||
if games_enabled and (hop == "Direct" or hop_count < game_hop_limit):
|
||||
playingGame = checkPlayingGame(message_from_id, message_string, rxNode, channel_number)
|
||||
else:
|
||||
elif hop_count >= game_hop_limit:
|
||||
if games_enabled:
|
||||
logger.warning(f"Device:{rxNode} Ignoring Request to Play Game: {message_string} From: {get_name_from_number(message_from_id, 'long', rxNode)} with hop count: {hop}")
|
||||
send_message(f"Your hop count exceeds safe playable distance at {hop_count} hops", channel_number, message_from_id, rxNode)
|
||||
time.sleep(responseDelay)
|
||||
else:
|
||||
playingGame = False
|
||||
else:
|
||||
playingGame = False
|
||||
|
||||
if not playingGame:
|
||||
if llm_enabled and llmReplyToNonCommands:
|
||||
@@ -1435,8 +1640,8 @@ def onReceive(packet, interface):
|
||||
|
||||
# trim the history list if it exceeds max_history
|
||||
if len(msg_history) >= MAX_MSG_HISTORY:
|
||||
# Remove oldest entries by cutting in half
|
||||
msg_history = msg_history[len(msg_history)//2:]
|
||||
# Always keep only the most recent MAX_MSG_HISTORY entries
|
||||
msg_history = msg_history[-MAX_MSG_HISTORY:]
|
||||
|
||||
# add the message to the history list
|
||||
msg_history.append((get_name_from_number(message_from_id, 'long', rxNode), message_string, channel_number, timestamp, rxNode))
|
||||
@@ -1451,14 +1656,17 @@ def onReceive(packet, interface):
|
||||
if repeater_enabled and multiple_interface:
|
||||
# wait a responseDelay to avoid message collision from lora-ack.
|
||||
time.sleep(responseDelay)
|
||||
rMsg = (f"{message_string} From:{get_name_from_number(message_from_id, 'short', rxNode)}")
|
||||
# if channel found in the repeater list repeat the message
|
||||
if str(channel_number) in repeater_channels:
|
||||
for i in range(1, 10):
|
||||
if globals().get(f'interface{i}_enabled', False) and i != rxNode:
|
||||
logger.debug(f"Repeating message on Device{i} Channel:{channel_number}")
|
||||
send_message(rMsg, channel_number, 0, i)
|
||||
time.sleep(responseDelay)
|
||||
if len(message_string) > (3 * MESSAGE_CHUNK_SIZE):
|
||||
logger.warning(f"System: Not repeating message, exceeds size limit ({len(message_string)} > {3 * MESSAGE_CHUNK_SIZE})")
|
||||
else:
|
||||
rMsg = (f"{message_string} From:{get_name_from_number(message_from_id, 'short', rxNode)}")
|
||||
# if channel found in the repeater list repeat the message
|
||||
if str(channel_number) in repeater_channels:
|
||||
for i in range(1, 10):
|
||||
if globals().get(f'interface{i}_enabled', False) and i != rxNode:
|
||||
logger.debug(f"Repeating message on Device{i} Channel:{channel_number}")
|
||||
send_message(rMsg, channel_number, 0, i)
|
||||
time.sleep(responseDelay)
|
||||
|
||||
# if QRZ enabled check if we have said hello
|
||||
if qrz_hello_enabled:
|
||||
@@ -1501,10 +1709,14 @@ async def start_rx():
|
||||
if "trouble" not in llmLoad:
|
||||
logger.debug(f"System: LLM Model {llmModel} loaded")
|
||||
|
||||
if useDMForResponse:
|
||||
logger.debug("System: Respond by DM only")
|
||||
|
||||
if log_messages_to_file:
|
||||
logger.debug("System: Logging Messages to disk")
|
||||
if syslog_to_file:
|
||||
logger.debug("System: Logging System Logs to disk")
|
||||
|
||||
if bbs_enabled:
|
||||
logger.debug(f"System: BBS Enabled, {bbsdb} has {len(bbs_messages)} messages. Direct Mail Messages waiting: {(len(bbs_dm) - 1)}")
|
||||
if bbs_link_enabled:
|
||||
@@ -1512,80 +1724,110 @@ async def start_rx():
|
||||
logger.debug(f"System: BBS Link Enabled with {len(bbs_link_whitelist)} peers")
|
||||
else:
|
||||
logger.debug(f"System: BBS Link Enabled allowing all")
|
||||
|
||||
if solar_conditions_enabled:
|
||||
logger.debug("System: Celestial Telemetry Enabled")
|
||||
|
||||
if location_enabled:
|
||||
if use_meteo_wxApi:
|
||||
logger.debug("System: Location Telemetry Enabled using Open-Meteo API")
|
||||
else:
|
||||
logger.debug("System: Location Telemetry Enabled using NOAA API")
|
||||
|
||||
if dad_jokes_enabled:
|
||||
logger.debug("System: Dad Jokes Enabled!")
|
||||
|
||||
if coastalEnabled:
|
||||
logger.debug("System: Coastal Forcast and Tide Enabled!")
|
||||
logger.debug("System: Coastal Forecast and Tide Enabled!")
|
||||
|
||||
if games_enabled:
|
||||
logger.debug("System: Games Enabled!")
|
||||
|
||||
if wikipedia_enabled:
|
||||
logger.debug("System: Wikipedia search Enabled")
|
||||
if use_kiwix_server:
|
||||
logger.debug(f"System: Wikipedia search Enabled using Kiwix server at {kiwix_server_address}")
|
||||
else:
|
||||
logger.debug("System: Wikipedia search Enabled")
|
||||
|
||||
if rssEnable:
|
||||
logger.debug(f"System: RSS Feed Reader Enabled for feeds: {rssFeedNames}")
|
||||
|
||||
if motd_enabled:
|
||||
logger.debug(f"System: MOTD Enabled using {MOTD}")
|
||||
logger.debug(f"System: MOTD Enabled using {MOTD} scheduler:{schedulerMotd}")
|
||||
|
||||
if sentry_enabled:
|
||||
logger.debug(f"System: Sentry Mode Enabled {sentry_radius}m radius reporting to channel:{secure_channel}")
|
||||
|
||||
if highfly_enabled:
|
||||
logger.debug(f"System: HighFly Enabled using {highfly_altitude}m limit reporting to channel:{highfly_channel}")
|
||||
|
||||
if store_forward_enabled:
|
||||
logger.debug(f"System: S&F(messages command) Enabled using limit: {storeFlimit}")
|
||||
if useDMForResponse:
|
||||
logger.debug(f"System: Respond by DM only")
|
||||
|
||||
if enableEcho:
|
||||
logger.debug(f"System: Echo command Enabled")
|
||||
logger.debug("System: Echo command Enabled")
|
||||
|
||||
if repeater_enabled and multiple_interface:
|
||||
logger.debug(f"System: Repeater Enabled for Channels: {repeater_channels}")
|
||||
|
||||
if radio_detection_enabled:
|
||||
logger.debug(f"System: Radio Detection Enabled using rigctld at {rigControlServerAddress} brodcasting to channels: {sigWatchBroadcastCh} for {get_freq_common_name(get_hamlib('f'))}")
|
||||
logger.debug(f"System: Radio Detection Enabled using rigctld at {rigControlServerAddress} broadcasting to channels: {sigWatchBroadcastCh} for {get_freq_common_name(get_hamlib('f'))}")
|
||||
|
||||
if file_monitor_enabled:
|
||||
logger.debug(f"System: File Monitor Enabled for {file_monitor_file_path}, broadcasting to channels: {file_monitor_broadcastCh}")
|
||||
if enable_runShellCmd:
|
||||
logger.debug(f"System: Shell Command monitor enabled")
|
||||
if allowXcmd and enable_runShellCmd:
|
||||
logger.warning(f"System: File Monitor shell XCMD Enabled")
|
||||
if read_news_enabled:
|
||||
logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}")
|
||||
if bee_enabled:
|
||||
logger.debug(f"System: File Monitor Bee Monitor Enabled for bee.txt")
|
||||
logger.warning(f"System: File Monitor Enabled for {file_monitor_file_path}, broadcasting to channels: {file_monitor_broadcastCh}")
|
||||
if enable_runShellCmd:
|
||||
logger.debug("System: Shell Command monitor enabled")
|
||||
if allowXcmd:
|
||||
logger.warning("System: File Monitor shell XCMD Enabled")
|
||||
if read_news_enabled:
|
||||
logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}")
|
||||
if bee_enabled:
|
||||
logger.debug("System: File Monitor Bee Monitor Enabled for bee.txt")
|
||||
|
||||
if wxAlertBroadcastEnabled:
|
||||
logger.debug(f"System: Weather Alert Broadcast Enabled on channels {wxAlertBroadcastChannel}")
|
||||
|
||||
if emergencyAlertBrodcastEnabled:
|
||||
logger.debug(f"System: Emergency Alert Broadcast Enabled on channels {emergencyAlertBroadcastCh} for FIPS codes {myStateFIPSList}")
|
||||
# check if the FIPS codes are set
|
||||
if myStateFIPSList == ['']:
|
||||
logger.warning(f"System: No FIPS codes set for iPAWS Alerts")
|
||||
logger.warning("System: No FIPS codes set for iPAWS Alerts")
|
||||
|
||||
if emergency_responder_enabled:
|
||||
logger.debug(f"System: Emergency Responder Enabled on channels {emergency_responder_alert_channel} for interface {emergency_responder_alert_interface}")
|
||||
|
||||
if volcanoAlertBroadcastEnabled:
|
||||
logger.debug(f"System: Volcano Alert Broadcast Enabled on channels {volcanoAlertBroadcastChannel}")
|
||||
if qrz_hello_enabled and train_qrz:
|
||||
logger.debug(f"System: QRZ Welcome/Hello Enabled with training mode")
|
||||
if qrz_hello_enabled and not train_qrz:
|
||||
logger.debug(f"System: QRZ Welcome/Hello Enabled")
|
||||
|
||||
if qrz_hello_enabled:
|
||||
if train_qrz:
|
||||
logger.debug("System: QRZ Welcome/Hello Enabled with training mode")
|
||||
else:
|
||||
logger.debug("System: QRZ Welcome/Hello Enabled")
|
||||
|
||||
if checklist_enabled:
|
||||
logger.debug(f"System: CheckList Module Enabled")
|
||||
if ignoreChannels != []:
|
||||
logger.debug("System: CheckList Module Enabled")
|
||||
|
||||
if ignoreChannels:
|
||||
logger.debug(f"System: Ignoring Channels: {ignoreChannels}")
|
||||
|
||||
if noisyNodeLogging:
|
||||
logger.debug(f"System: Noisy Node Logging Enabled")
|
||||
logger.debug("System: Noisy Node Logging Enabled")
|
||||
|
||||
if logMetaStats:
|
||||
logger.debug("System: Logging Metadata Stats Enabled, leaderboard")
|
||||
loadLeaderboard()
|
||||
|
||||
if enableSMTP:
|
||||
if enableImap:
|
||||
logger.debug(f"System: SMTP Email Alerting Enabled using IMAP")
|
||||
logger.debug("System: SMTP Email Alerting Enabled using IMAP")
|
||||
else:
|
||||
logger.debug(f"System: SMTP Email Alerting Enabled")
|
||||
if scheduler_enabled:
|
||||
# Reminder Scheduler is enabled every Monday at noon send a log message
|
||||
schedule.every().monday.at("12:00").do(lambda: logger.info("System: Scheduled Broadcast Enabled Reminder"))
|
||||
logger.warning("System: SMTP Email Alerting Enabled")
|
||||
|
||||
if scheduler_enabled:
|
||||
# basic scheduler
|
||||
if schedulerMotd:
|
||||
schedulerMessage = MOTD
|
||||
if schedulerValue != '':
|
||||
logger.debug(f"System: Starting the broadcast scheduler from config.ini")
|
||||
if schedulerValue.lower() == 'day':
|
||||
if schedulerTime != '':
|
||||
# Send a message every day at the time set in schedulerTime
|
||||
@@ -1620,8 +1862,13 @@ async def start_rx():
|
||||
elif 'min' in schedulerValue.lower():
|
||||
# Send a message every minute at the time set in schedulerTime
|
||||
schedule.every(int(schedulerInterval)).minutes.do(lambda: send_message(schedulerMessage, schedulerChannel, 0, schedulerInterface))
|
||||
logger.debug(f"System: Starting the scheduler to send '{schedulerMessage}' every {schedulerValue} at {schedulerTime} on Device:{schedulerInterface} Channel:{schedulerChannel}")
|
||||
else:
|
||||
logger.debug(f"System: Starting the broadcast scheduler")
|
||||
logger.warning("System: No schedule.Value set edit the .py file to do more. See examples in the code.")
|
||||
# Reminder Scheduler is enabled every Monday at noon send a log message
|
||||
schedule.every().monday.at("12:00").do(lambda: logger.info("System: Scheduled Broadcast Enabled Reminder"))
|
||||
# example scheduler message
|
||||
logger.debug(f"System: Starting the scheduler to send '{schedulerMessage}' every Monday at noon on Device:{schedulerInterface} Channel:{schedulerChannel}")
|
||||
|
||||
# Enhanced Examples of using the scheduler, Times here are in 24hr format
|
||||
# https://schedule.readthedocs.io/en/stable/
|
||||
@@ -1658,6 +1905,7 @@ async def start_rx():
|
||||
|
||||
# Send bbslink looking for peers every other day at 10:00 using send_message function to channel 3 on device 1
|
||||
#schedule.every(2).days.at("10:00").do(lambda: send_message("bbslink MeshBot looking for peers", 3, 0, 1))
|
||||
# show schedual details
|
||||
await BroadcastScheduler()
|
||||
|
||||
# here we go loopty loo
|
||||
@@ -1680,8 +1928,11 @@ async def main():
|
||||
|
||||
if radio_detection_enabled:
|
||||
tasks.append(asyncio.create_task(handleSignalWatcher(), name="hamlib"))
|
||||
|
||||
if voxDetectionEnabled:
|
||||
tasks.append(asyncio.create_task(voxMonitor(), name="vox_detection"))
|
||||
|
||||
logger.info(f"System: Starting {len(tasks)} async tasks")
|
||||
logger.debug(f"System: Starting {len(tasks)} async tasks")
|
||||
|
||||
# Wait for all tasks with proper exception handling
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
@@ -1695,7 +1946,7 @@ async def main():
|
||||
logger.error(f"Main loop error: {e}")
|
||||
finally:
|
||||
# Cleanup tasks
|
||||
logger.info("System: Cleaning up async tasks")
|
||||
logger.debug("System: Cleaning up async tasks")
|
||||
for task in tasks:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
@@ -96,13 +96,15 @@ def bbs_post_message(subject, message, fromNode):
|
||||
if str(fromNode) in bbs_ban_list:
|
||||
logger.warning(f"System: Naughty node {fromNode}, tried to post a message: {subject}, {message} and was dropped.")
|
||||
return "Message posted. ID is: " + str(messageID)
|
||||
|
||||
# validate message length isnt three times the MESSAGE_CHUNK_SIZE
|
||||
if len(message) > (3 * MESSAGE_CHUNK_SIZE):
|
||||
return "Message too long, max length is " + str(3 * MESSAGE_CHUNK_SIZE) + " characters."
|
||||
# validate not a duplicate message
|
||||
for msg in bbs_messages:
|
||||
if msg[1].strip().lower() == subject.strip().lower() and msg[2].strip().lower() == message.strip().lower():
|
||||
messageID = msg[0]
|
||||
return "Message posted. ID is: " + str(messageID)
|
||||
|
||||
# validate its not overlength by keeping in chunker limit
|
||||
# append the message to the list
|
||||
bbs_messages.append([messageID, subject, message, fromNode])
|
||||
logger.info(f"System: NEW Message Posted, subject: {subject}, message: {message} from {fromNode}")
|
||||
@@ -153,6 +155,14 @@ def bbs_post_dm(toNode, message, fromNode):
|
||||
if str(fromNode) in bbs_ban_list:
|
||||
logger.warning(f"System: Naughty node {fromNode}, tried to post a message: {message} and was dropped.")
|
||||
return "DM Posted for node " + str(toNode)
|
||||
|
||||
# validate message length isnt three times the MESSAGE_CHUNK_SIZE
|
||||
if len(message) > (3 * MESSAGE_CHUNK_SIZE):
|
||||
return "Message too long, max length is " + str(3 * MESSAGE_CHUNK_SIZE) + " characters."
|
||||
# validate not a duplicate message
|
||||
for msg in bbs_dm:
|
||||
if msg[0] == int(toNode) and msg[1].strip().lower() == message.strip().lower():
|
||||
return "DM Posted for node " + str(toNode)
|
||||
|
||||
# append the message to the list
|
||||
bbs_dm.append([int(toNode), message, int(fromNode)])
|
||||
|
||||
@@ -9,11 +9,12 @@ import subprocess
|
||||
|
||||
trap_list_filemon = ("readnews",)
|
||||
|
||||
def read_file(file_monitor_file_path, random_line_only=False):
|
||||
NEWS_DATA_DIR = os.path.join(os.path.dirname(__file__), '..', 'data')
|
||||
newsSourcesList = []
|
||||
|
||||
def read_file(file_monitor_file_path, random_line_only=False):
|
||||
try:
|
||||
if not os.path.exists(file_monitor_file_path):
|
||||
logger.warning(f"FileMon: File not found: {file_monitor_file_path}")
|
||||
if file_monitor_file_path == "bee.txt":
|
||||
return "🐝buzz 💐buzz buzz🍯"
|
||||
if random_line_only:
|
||||
@@ -29,21 +30,25 @@ def read_file(file_monitor_file_path, random_line_only=False):
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error reading file: {file_monitor_file_path}")
|
||||
return None
|
||||
|
||||
def read_news():
|
||||
# read the news file on demand
|
||||
return read_file(news_file_path, news_random_line_only)
|
||||
|
||||
def read_news(source=None):
|
||||
# Reads the news file. If a source is provided, reads {source}_news.txt.
|
||||
if source:
|
||||
file_path = os.path.join(NEWS_DATA_DIR, f"{source}_news.txt")
|
||||
else:
|
||||
file_path = os.path.join(NEWS_DATA_DIR, news_file_path)
|
||||
return read_file(file_path, news_random_line_only)
|
||||
|
||||
def write_news(content, append=False):
|
||||
# write the news file on demand
|
||||
try:
|
||||
with open(news_file_path, 'a' if append else 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
logger.info(f"FileMon: Updated {news_file_path}")
|
||||
file_path = os.path.join(NEWS_DATA_DIR, news_file_path)
|
||||
with open(file_path, 'a' if append else 'w', encoding='utf-8') as f:
|
||||
#f.write(content)
|
||||
logger.info(f"FileMon: Updated {file_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error writing file: {news_file_path}")
|
||||
logger.warning(f"FileMon: Error writing file: {file_path}")
|
||||
return False
|
||||
|
||||
async def watch_file():
|
||||
@@ -84,38 +89,83 @@ def call_external_script(message, script="script/runShell.sh"):
|
||||
logger.warning(f"FileMon: Error calling external script: {e}")
|
||||
return None
|
||||
|
||||
|
||||
waitingXroom = {} # {message_from_id: (expected_answer, original_command, timestamp)}
|
||||
def handleShellCmd(message, message_from_id, channel_number, isDM, deviceID):
|
||||
if not allowXcmd:
|
||||
return "x: command is disabled"
|
||||
|
||||
if str(message_from_id) not in bbs_admin_list:
|
||||
logger.warning(f"FileMon: Unauthorized x: command attempt from {message_from_id}")
|
||||
return "x: command not authorized"
|
||||
|
||||
if not isDM:
|
||||
return "x: command not authorized in group chat"
|
||||
|
||||
if enable_runShellCmd:
|
||||
# clean up the command input
|
||||
|
||||
# 2FA logic
|
||||
if xCmd2factorEnabled:
|
||||
timeNOW = datetime.utcnow()
|
||||
# If user is waiting for 2FA, treat message as answer
|
||||
if message_from_id in waitingXroom:
|
||||
answer = message[2:].strip() if message.lower().startswith("x:") else message.strip()
|
||||
expected, orig_command, ts = waitingXroom[message_from_id]
|
||||
if timeNOW - ts > timedelta(seconds=xCmd2factor_timeout):
|
||||
del waitingXroom[message_from_id]
|
||||
return "x2FA timed out, please try again"
|
||||
if answer == str(expected):
|
||||
del waitingXroom[message_from_id]
|
||||
# Run the original command
|
||||
try:
|
||||
logger.info(f"FileMon: Running shell command from {message_from_id}: {orig_command}")
|
||||
result = subprocess.run(orig_command, shell=True, capture_output=True, text=True, timeout=10, start_new_session=True)
|
||||
output = result.stdout.strip()
|
||||
return output if output else "✅ x: processed finished, no output"
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error running shell command: {e}")
|
||||
logger.debug(f"FileMon: This command is not good for use over the mesh network")
|
||||
return "x: error running command"
|
||||
else:
|
||||
logger.warning(f"FileMon: 🚨Incorrect 2FA answer from {message_from_id}")
|
||||
return "x2FA incorrect, try again"
|
||||
# If not waiting, treat as new command and issue challenge
|
||||
if message.lower().startswith("x:"):
|
||||
command = message[2:]
|
||||
if command.startswith(" "):
|
||||
command = command[1:]
|
||||
command = command.strip()
|
||||
command = message[2:].strip()
|
||||
# Generate two random numbers, seed with message_from_id and time of day
|
||||
seed = timeNOW.second + timeNOW.minute * 60 + timeNOW.hour * 3600 + int(message_from_id)
|
||||
rnd = random.Random(seed)
|
||||
a = rnd.randint(10, 99)
|
||||
b = rnd.randint(10, 99)
|
||||
expected = a + b
|
||||
waitingXroom[message_from_id] = (expected, command, timeNOW)
|
||||
return f"x2FA required.\nReply `x: answer`\nWhat is {a} + {b}? "
|
||||
else:
|
||||
return "x: invalid command format"
|
||||
# Run the shell command as a subprocess
|
||||
return "invalid command format"
|
||||
|
||||
# If we reach here, 2FA is disabled or passed
|
||||
if enable_runShellCmd:
|
||||
if message.lower().startswith("x:"):
|
||||
command = message[2:].strip()
|
||||
else:
|
||||
return "invalid command format"
|
||||
try:
|
||||
logger.info(f"FileMon: Running shell command from {message_from_id}: {command}")
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=10, start_new_session=True)
|
||||
output = result.stdout.strip()
|
||||
if output:
|
||||
return output
|
||||
return output if output else "x: command executed with no output"
|
||||
except Exception as e:
|
||||
logger.warning(f"FileMon: Error running shell command: {e}")
|
||||
logger.debug(f"FileMon: This command is not good for use over the mesh network")
|
||||
return "error running command"
|
||||
else:
|
||||
logger.debug("FileMon: x: command is disabled by no enable_runShellCmd")
|
||||
return "x: command is disabled"
|
||||
|
||||
return "x: command executed with no output"
|
||||
return "command is disabled"
|
||||
|
||||
def initNewsSources():
|
||||
#check for the files _news.txt and add to the newsHeadlines list
|
||||
global newsSourcesList
|
||||
newsSourcesList = []
|
||||
for file in os.listdir(NEWS_DATA_DIR):
|
||||
if file.endswith('_news.txt'):
|
||||
source = file[:-9] # remove _news.txt
|
||||
newsSourcesList.append(source)
|
||||
|
||||
#initialize the headlines on startup
|
||||
initNewsSources()
|
||||
|
||||
@@ -7,8 +7,8 @@ import time
|
||||
import pickle
|
||||
|
||||
jack_starting_cash = 100 # Replace 100 with your desired starting cash value
|
||||
jackTracker= [{'nodeID': 0, 'cmd': 'new', 'time': time.time(), 'cash': jack_starting_cash,\
|
||||
'bet': 0, 'gameStats': {'p_win': 0, 'd_win': 0, 'draw': 0}, 'p_cards':[], 'd_cards':[], 'p_hand':[], 'd_hand':[], 'next_card':[]}]
|
||||
jackTracker= [{'nodeID': 0, 'cmd': 'new', 'cash': jack_starting_cash,\
|
||||
'bet': 0, 'gameStats': {'p_win': 0, 'd_win': 0, 'draw': 0}, 'p_cards':[], 'd_cards':[], 'p_hand':[], 'd_hand':[], 'next_card':[],'last_played': time.time()}]
|
||||
|
||||
SUITS = ("♥️", "♦️", "♠️", "♣️")
|
||||
RANKS = (
|
||||
@@ -268,7 +268,7 @@ def playBlackJack(nodeID, message):
|
||||
if last_cmd is None:
|
||||
# create new player if not in tracker
|
||||
logger.debug(f"System: BlackJack: New Player {nodeID}")
|
||||
jackTracker.append({'nodeID': nodeID, 'cmd': 'new', 'time': time.time(), 'cash': jack_starting_cash,\
|
||||
jackTracker.append({'nodeID': nodeID, 'cmd': 'new', 'last_played': time.time(), 'cash': jack_starting_cash,\
|
||||
'bet': 0, 'gameStats': {'p_win': p_win, 'd_win': d_win, 'draw': draw}, 'p_cards':p_cards, 'd_cards':d_cards, 'p_hand':p_hand.cards, 'd_hand':d_hand.cards, 'next_card':next_card})
|
||||
return f"Welcome to ♠️♥️BlackJack♣️♦️ you have {p_chips.total} chips. Whats your bet?"
|
||||
|
||||
@@ -468,6 +468,6 @@ def playBlackJack(nodeID, message):
|
||||
jackTracker[i]['d_cards'] = []
|
||||
jackTracker[i]['p_hand'] = []
|
||||
jackTracker[i]['d_hand'] = []
|
||||
jackTracker[i]['time'] = time.time()
|
||||
jackTracker[i]['last_played'] = time.time()
|
||||
|
||||
return msg
|
||||
|
||||
@@ -366,7 +366,8 @@ def get_location_table(nodeID, choice=0):
|
||||
return loc_table_string
|
||||
|
||||
def endGameDw(nodeID):
|
||||
global dwCashDb, dwInventoryDb, dwLocationDb, dwGameDayDb, dwHighScore
|
||||
global dwCashDb, dwInventoryDb, dwLocationDb, dwGameDayDb, dwHighScore, dwPlayerTracker
|
||||
cash = 0
|
||||
msg = ''
|
||||
dwHighScore = getHighScoreDw()
|
||||
# Confirm the cash for the user
|
||||
@@ -375,23 +376,6 @@ def endGameDw(nodeID):
|
||||
cash = dwCashDb[i].get('cash')
|
||||
logger.debug("System: DopeWars: Game Over for user: " + str(nodeID) + " with cash: " + str(cash))
|
||||
|
||||
# remove the player from the game databases
|
||||
for i in range(0, len(dwCashDb)):
|
||||
if dwCashDb[i].get('userID') == nodeID:
|
||||
dwCashDb.pop(i)
|
||||
for i in range(0, len(dwInventoryDb)):
|
||||
if dwInventoryDb[i].get('userID') == nodeID:
|
||||
dwInventoryDb.pop(i)
|
||||
for i in range(0, len(dwLocationDb)):
|
||||
if dwLocationDb[i].get('userID') == nodeID:
|
||||
dwLocationDb.pop(i)
|
||||
for i in range(0, len(dwGameDayDb)):
|
||||
if dwGameDayDb[i].get('userID') == nodeID:
|
||||
dwGameDayDb.pop(i)
|
||||
for i in range(0, len(dwPlayerTracker)):
|
||||
if dwPlayerTracker[i].get('userID') == nodeID:
|
||||
dwPlayerTracker.pop(i)
|
||||
|
||||
# checks if the player's score is higher than the high score and writes a new high score if it is
|
||||
if cash > dwHighScore.get('cash'):
|
||||
dwHighScore = ({'userID': nodeID, 'cash': round(cash, 2)})
|
||||
@@ -680,6 +664,7 @@ def playDopeWars(nodeID, cmd):
|
||||
for i in range(0, len(dwPlayerTracker)):
|
||||
if dwPlayerTracker[i].get('userID') == nodeID:
|
||||
dwPlayerTracker[i]['cmd'] = 'ask_bsf'
|
||||
dwPlayerTracker[i]['last_played'] = time.time()
|
||||
|
||||
# Game end
|
||||
if game_day == total_days + 1:
|
||||
|
||||
@@ -133,6 +133,7 @@ def playGolf(nodeID, message, finishedHole=False):
|
||||
total_strokes = 0
|
||||
total_to_par = 0
|
||||
par = 0
|
||||
hole = 1
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
last_cmd = ""
|
||||
@@ -145,6 +146,10 @@ def playGolf(nodeID, message, finishedHole=False):
|
||||
par = golfTracker[i]['par']
|
||||
total_strokes = golfTracker[i]['total_strokes']
|
||||
total_to_par = golfTracker[i]['total_to_par']
|
||||
#update last played time
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
golfTracker[i]['last_played'] = time.time()
|
||||
|
||||
if last_cmd == "" or last_cmd == "new":
|
||||
# Start a new hole
|
||||
|
||||
@@ -55,6 +55,8 @@ lameJokes = [
|
||||
"Chuck Norris can do a wheelie on a unicycle.",
|
||||
"Chuck Norris can kill two stones with one bird."]
|
||||
|
||||
imtellingyourightnowiAmTellingYouRightNowThatMotherfErBackThereIsNotReal = ["🐦", "🦅", "🦆", "🦉", "🦜", "🐤", "🐥", "🐣", "🐔", "🐧", "🦚", "🦢", "🦩", "🦤", "🦃", "🐓"]
|
||||
|
||||
def tableOfContents():
|
||||
wordToEmojiMap = {
|
||||
'love': '❤️', 'heart': '❤️', 'happy': '😊', 'smile': '😊', 'sad': '😢', 'angry': '😠', 'mad': '😠', 'cry': '😢', 'laugh': '😂', 'funny': '😂', 'cool': '😎',
|
||||
|
||||
@@ -18,7 +18,6 @@ locale.setlocale(locale.LC_ALL, '')
|
||||
lemon_starting_cash = 30.00
|
||||
lemon_total_weeks = 7
|
||||
|
||||
lemonadeTracker = [{'nodeID': 0, 'cups': 0, 'lemons': 0, 'sugar': 0, 'cash': lemon_starting_cash, 'start': lemon_starting_cash, 'cmd': 'new', 'time': time.time()}]
|
||||
lemonadeCups = [{'nodeID': 0, 'cost': 2.50, 'count': 25, 'min': 0.99, 'unit': 0.00}]
|
||||
lemonadeLemons = [{'nodeID': 0, 'cost': 4.00, 'count': 8, 'min': 2.00, 'unit': 0.00}]
|
||||
lemonadeSugar = [{'nodeID': 0, 'cost': 3.00, 'count': 15, 'min': 1.50, 'unit': 0.00}]
|
||||
@@ -50,12 +49,14 @@ def getHighScoreLemon():
|
||||
pickle.dump(high_score, file)
|
||||
return high_score
|
||||
|
||||
def start_lemonade(nodeID, message, celsius=False):
|
||||
def playLemonstand(nodeID, message, celsius=False, newgame=False):
|
||||
global lemonadeTracker, lemonadeCups, lemonadeLemons, lemonadeSugar, lemonadeWeeks, lemonadeScore
|
||||
msg = ""
|
||||
potential = 0
|
||||
unit = 0.0
|
||||
price = 0.0
|
||||
total_sales = 0
|
||||
lemonsLastCmd = ''
|
||||
|
||||
high_score = getHighScoreLemon()
|
||||
|
||||
@@ -94,33 +95,6 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
lemonadeScore[i]['value'] = score.value
|
||||
lemonadeScore[i]['total'] = score.total
|
||||
|
||||
def endGame(nodeID):
|
||||
# remove the player from the tracker
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker.pop(i)
|
||||
for i in range(len(lemonadeCups)):
|
||||
if lemonadeCups[i]['nodeID'] == nodeID:
|
||||
lemonadeCups.pop(i)
|
||||
for i in range(len(lemonadeLemons)):
|
||||
if lemonadeLemons[i]['nodeID'] == nodeID:
|
||||
lemonadeLemons.pop(i)
|
||||
for i in range(len(lemonadeSugar)):
|
||||
if lemonadeSugar[i]['nodeID'] == nodeID:
|
||||
lemonadeSugar.pop(i)
|
||||
for i in range(len(lemonadeWeeks)):
|
||||
if lemonadeWeeks[i]['nodeID'] == nodeID:
|
||||
lemonadeWeeks.pop(i)
|
||||
for i in range(len(lemonadeScore)):
|
||||
if lemonadeScore[i]['nodeID'] == nodeID:
|
||||
lemonadeScore.pop(i)
|
||||
logger.debug("System: Lemonade: Game Over for " + str(nodeID))
|
||||
|
||||
# Check for end of game
|
||||
if message.lower().startswith("e"):
|
||||
endGame(nodeID)
|
||||
return "Goodbye!👋"
|
||||
|
||||
title="LemonStand🍋"
|
||||
# Define the temperature unit symbols
|
||||
fahrenheit_unit = "ºF"
|
||||
@@ -213,7 +187,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
inventory.sugar = lemonadeTracker[i]['sugar']
|
||||
inventory.cash = lemonadeTracker[i]['cash']
|
||||
inventory.start = lemonadeTracker[i]['start']
|
||||
last_cmd = lemonadeTracker[i]['cmd']
|
||||
lemonsLastCmd = lemonadeTracker[i]['cmd']
|
||||
for i in range(len(lemonadeCups)):
|
||||
if lemonadeCups[i]['nodeID'] == nodeID:
|
||||
cups.cost = lemonadeCups[i]['cost']
|
||||
@@ -239,15 +213,35 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
if lemonadeScore[i]['nodeID'] == nodeID:
|
||||
score.value = lemonadeScore[i]['value']
|
||||
score.total = lemonadeScore[i]['total']
|
||||
|
||||
if (newgame):
|
||||
# reset the game values
|
||||
inventory.cups = 0
|
||||
inventory.lemons = 0
|
||||
inventory.sugar = 0
|
||||
inventory.cash = lemon_starting_cash
|
||||
inventory.start = lemon_starting_cash
|
||||
cups.cost = 2.50
|
||||
cups.unit = round(cups.cost / cups.count, 2)
|
||||
lemons.cost = 4.00
|
||||
lemons.unit = round(lemons.cost / lemons.count, 2)
|
||||
sugar.cost = 3.00
|
||||
sugar.unit = round(sugar.cost / sugar.count, 2)
|
||||
weeks.current = 1
|
||||
weeks.total_sales = 0
|
||||
weeks.summary = []
|
||||
score.value = 0.00
|
||||
score.total = 0.00
|
||||
lemonsLastCmd = "cups"
|
||||
# set the last command to new in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "cups"
|
||||
lemonadeTracker[i]['last_played'] = time.time()
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
# Start the main loop
|
||||
if (weeks.current <= weeks.total):
|
||||
|
||||
if "new" in last_cmd:
|
||||
# set the last command to cups in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "cups"
|
||||
if newgame or "new" in lemonsLastCmd:
|
||||
logger.debug("System: Lemonade: New Game: " + str(nodeID))
|
||||
# Create a new display buffer for the text messages
|
||||
buffer= ""
|
||||
|
||||
@@ -292,8 +286,8 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
sugar.unit = round(sugar.cost / sugar.count, 2)
|
||||
|
||||
# Calculate the unit cost and display the estimated sales from the forecast potential
|
||||
unit = cups.unit + lemons.unit + sugar.unit
|
||||
buffer += " SupplyCost" + locale.currency(unit, grouping=True) + " a cup."
|
||||
unit = max(0.01, min(cups.unit + lemons.unit + sugar.unit, 4.0)) # limit the unit cost between $0.01 and $4.00
|
||||
buffer += " SupplyCost" + locale.currency(round(unit, 2), grouping=True) + " a cup."
|
||||
buffer += " Sales Potential:" + str(potential) + " cups."
|
||||
|
||||
# Display the current inventory
|
||||
@@ -304,21 +298,16 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
|
||||
# Display the updated item prices
|
||||
buffer += f"\nPrices: "
|
||||
buffer += "🥤:" + \
|
||||
locale.currency(cups.cost, grouping=True) + " 📦 of " + str(cups.count) + "."
|
||||
buffer += " 🍋:" + \
|
||||
locale.currency(lemons.cost, grouping=True) + " 🧺 of " + str(lemons.count) + "."
|
||||
buffer += " 🍚:" + \
|
||||
locale.currency(sugar.cost, grouping=True) + " bag for " + str(sugar.count) + "🥤."
|
||||
|
||||
buffer += "🥤:" + locale.currency(round(cups.cost, 2), grouping=True) + " 📦 of " + str(cups.count) + "."
|
||||
buffer += " 🍋:" + locale.currency(round(lemons.cost, 2), grouping=True) + " 🧺 of " + str(lemons.count) + "."
|
||||
buffer += " 🍚:" + locale.currency(round(sugar.cost, 2), grouping=True) + " bag for " + str(sugar.count) + "🥤."
|
||||
# Display the current cash
|
||||
gainloss = inventory.cash - inventory.start
|
||||
buffer += " 💵:" + \
|
||||
locale.currency(inventory.cash, grouping=True)
|
||||
buffer += " 💵:" + locale.currency(round(inventory.cash, 2), grouping=True)
|
||||
|
||||
|
||||
# if the player is in the red
|
||||
pnl = locale.currency(gainloss, grouping=True)
|
||||
pnl = locale.currency(round(gainloss, 2), grouping=True)
|
||||
if "0.00" not in pnl:
|
||||
if pnl.startswith("-"):
|
||||
buffer += "📊P&L📉" + pnl
|
||||
@@ -329,7 +318,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
return buffer
|
||||
|
||||
if "cups" in last_cmd:
|
||||
if "cups" in lemonsLastCmd and not newgame:
|
||||
# Read the number of cup boxes to purchase
|
||||
newcups = -1
|
||||
if "n" in message.lower():
|
||||
@@ -343,22 +332,22 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
inventory.cups += (newcups * cups.count)
|
||||
inventory.cash -= cost
|
||||
msg = "Purchased " + str(newcups) + " 📦 "
|
||||
msg += str(inventory.cups) + " 🥤 in inventory. " + locale.currency(inventory.cash, grouping=True) + f" remaining"
|
||||
msg += str(inventory.cups) + " 🥤 in inventory. " + locale.currency(round(inventory.cash, 2), grouping=True) + f" remaining"
|
||||
else:
|
||||
msg = "No 🥤 were purchased"
|
||||
except Exception as e:
|
||||
return "invalid input, enter the number of 🥤 to purchase or (N)one"
|
||||
|
||||
msg += f"\n 🍋 to buy? Have {inventory.lemons}🥤 of 🍋 Cost {locale.currency(lemons.cost, grouping=True)} a 🧺 for {str(lemons.count)}🥤"
|
||||
# set the last command to lemons in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "lemons"
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
msg += f"\n 🍋 to buy? Have {inventory.lemons}🥤 of 🍋 Cost {locale.currency(lemons.cost, grouping=True)} a 🧺 for {str(lemons.count)}🥤"
|
||||
return msg
|
||||
|
||||
|
||||
if "lemons" in last_cmd:
|
||||
if "lemons" in lemonsLastCmd and not newgame:
|
||||
# Read the number of lemon bags to purchase
|
||||
newlemons = -1
|
||||
if "n" in message.lower():
|
||||
@@ -379,15 +368,15 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
newlemons = -1
|
||||
return "⛔️invalid input, enter the number of 🍋 to purchase"
|
||||
|
||||
msg += f"\n 🍚 to buy? You have {inventory.sugar}🥤 of 🍚, Cost {locale.currency(sugar.cost, grouping=True)} a bag for {str(sugar.count)}🥤"
|
||||
# set the last command to sugar in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "sugar"
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
msg += f"\n 🍚 to buy? You have {inventory.sugar}🥤 of 🍚, Cost {locale.currency(sugar.cost, grouping=True)} a bag for {str(sugar.count)}🥤"
|
||||
return msg
|
||||
|
||||
if "sugar" in last_cmd:
|
||||
if "sugar" in lemonsLastCmd and not newgame:
|
||||
# Read the number of sugar bags to purchase
|
||||
newsugar = -1
|
||||
if "n" in message.lower():
|
||||
@@ -407,8 +396,8 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
except Exception as e:
|
||||
return "⛔️invalid input, enter the number of 🍚 bags to purchase"
|
||||
|
||||
msg += f"Cost of goods is {locale.currency(unit, grouping=True)}"
|
||||
msg += f"per 🥤 {locale.currency(inventory.cash, grouping=True)} 💵 remaining."
|
||||
msg += f"Cost of goods is {locale.currency(round(unit, 2), grouping=True)}"
|
||||
msg += f"per 🥤 {locale.currency(round(inventory.cash, 2), grouping=True)} 💵 remaining."
|
||||
msg += f"\nPrice to Sell? or (G)rocery to buy more 🥤🍋🍚"
|
||||
|
||||
# set the last command to price in the inventory db
|
||||
@@ -418,7 +407,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
return msg
|
||||
|
||||
if "price" in last_cmd:
|
||||
if "price" in lemonsLastCmd and not newgame:
|
||||
# set the last command to sales in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
@@ -428,7 +417,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
msg = f"#of🥤 to buy? Have {inventory.cups} Cost {locale.currency(cups.cost, grouping=True)} a 📦 of {str(cups.count)}"
|
||||
return msg
|
||||
else:
|
||||
last_cmd = "sales"
|
||||
lemonsLastCmd = "sales"
|
||||
|
||||
# Read the actual price
|
||||
price = 0.00
|
||||
@@ -440,7 +429,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
return "The price must be greater than zero."
|
||||
except Exception as e:
|
||||
price = 0.00
|
||||
last_cmd = "price"
|
||||
lemonsLastCmd = "price"
|
||||
return "⛔️Invalid input, enter the price of the lemonade per 🥤"
|
||||
|
||||
# this isnt sent to the user, not needed
|
||||
@@ -448,7 +437,7 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
|
||||
|
||||
if "sales" in last_cmd:
|
||||
if "sales" in lemonsLastCmd and not newgame:
|
||||
# Calculate the weekly sales based on price and lowest inventory level
|
||||
# (higher markup price = fewer sales, limited by the inventory on-hand)
|
||||
sales = get_sales_amount(potential, unit, price)
|
||||
@@ -563,15 +552,16 @@ def start_lemonade(nodeID, message, celsius=False):
|
||||
|
||||
else:
|
||||
# keep playing
|
||||
# set the last command to new in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "new"
|
||||
lemonadeTracker[i]['time'] = time.time()
|
||||
|
||||
weeks.current = weeks.current + 1
|
||||
|
||||
msg += f"Play another week🥤? or (E)nd Game"
|
||||
|
||||
# set the last command to new in the inventory db
|
||||
for i in range(len(lemonadeTracker)):
|
||||
if lemonadeTracker[i]['nodeID'] == nodeID:
|
||||
lemonadeTracker[i]['cmd'] = "new"
|
||||
lemonadeTracker[i]['last_played'] = time.time()
|
||||
saveValues(nodeID, inventory, cups, lemons, sugar, weeks, score)
|
||||
return msg
|
||||
else:
|
||||
return "Game Over! Start a (N)ew Game or (E)xit"
|
||||
|
||||
165
modules/games/quiz.py
Normal file
165
modules/games/quiz.py
Normal file
@@ -0,0 +1,165 @@
|
||||
# Quiz Module for meshbot 2025
|
||||
# Provides a quiz game function with multiple choice and free-text questions
|
||||
# Quizmaster can start/stop the quiz, players can join/leave, answer questions
|
||||
# Scores are tracked, first correct answer is noted, top 3 players announced at end
|
||||
# Questions are loaded from a JSON file in data/quiz_questions.json
|
||||
# Questions can be multiple choice (with answers array) or free-text (with answer string)
|
||||
# Players answer with "Q: <answer>" format, "Q: ?" for next question, locked to DM
|
||||
# unlike a normal game, players can join/leave anytime during the quiz but the QuizMaster needs to start or open game
|
||||
# Quizmaster can broadcast messages to all players
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
from modules.log import *
|
||||
|
||||
QUIZ_JSON = os.path.join(os.path.dirname(__file__), '../', '../', 'data', 'quiz_questions.json')
|
||||
QUIZMASTER_ID = bbs_admin_list
|
||||
|
||||
trap_list_quiz = ("quiz", "q:")
|
||||
help_text_quiz = "quiz",
|
||||
|
||||
class QuizGame:
|
||||
def __init__(self):
|
||||
self.quizmaster = QUIZMASTER_ID
|
||||
self.active = False
|
||||
self.players = {} # user_id: {'score': int, 'current_q': int, 'answered': set()}
|
||||
self.questions = [] # Loaded from JSON
|
||||
self.first_correct = {} # q_idx: user_id
|
||||
self.load_questions()
|
||||
|
||||
def start_game(self, quizmaster_id):
|
||||
if str(quizmaster_id) not in self.quizmaster:
|
||||
return "Only the quizmaster can start the quiz."
|
||||
if self.active:
|
||||
return "Quiz already running."
|
||||
self.active = True
|
||||
logger.debug(f"QuizMaster: {quizmaster_id} started a new quiz round.")
|
||||
self.players = {}
|
||||
self.first_correct = {} # Reset on new game
|
||||
self.load_questions()
|
||||
return "Quiz started! Players can now join."
|
||||
|
||||
def load_questions(self):
|
||||
try:
|
||||
with open(QUIZ_JSON, 'r') as f:
|
||||
self.questions = json.load(f)
|
||||
# Shuffle questions to ensure randomness each game
|
||||
#random.shuffle(self.questions)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load quiz questions: {e}")
|
||||
self.questions = []
|
||||
|
||||
def stop_game(self, quizmaster_id):
|
||||
if not self.active or str(quizmaster_id) not in self.quizmaster:
|
||||
return "Only the quizmaster can stop the quiz."
|
||||
return_msg = "Quiz stopped! Final scores:\n" + self.top_three()
|
||||
logger.debug(f"QuizMaster: {quizmaster_id} stopped the quiz.")
|
||||
self.active = False
|
||||
self.players = {}
|
||||
return return_msg
|
||||
|
||||
def join(self, user_id):
|
||||
if not self.active:
|
||||
return "No quiz running. Wait for the quizmaster to start."
|
||||
if user_id in self.players:
|
||||
return "You are already in the quiz."
|
||||
self.players[user_id] = {'score': 0, 'current_q': 0, 'answered': set()}
|
||||
reminder = f"Joined!\n'Q: <Answer>' 'Q: ?' for more.\n"
|
||||
logger.debug(f"QuizMaster: Player {user_id} joined the round.")
|
||||
return reminder + self.next_question(user_id)
|
||||
|
||||
def leave(self, user_id):
|
||||
if user_id in self.players:
|
||||
del self.players[user_id]
|
||||
logger.debug(f"QuizMaster: Player {user_id} left the round.")
|
||||
return "You left the quiz."
|
||||
return "You are not in the quiz."
|
||||
|
||||
def next_question(self, user_id):
|
||||
if user_id not in self.players:
|
||||
return "Join the quiz first."
|
||||
player = self.players[user_id]
|
||||
while player['current_q'] < len(self.questions) and player['current_q'] in player['answered']:
|
||||
player['current_q'] += 1
|
||||
if player['current_q'] >= len(self.questions):
|
||||
return f"No more questions. Your final score: {player['score']}."
|
||||
q = self.questions[player['current_q']]
|
||||
msg = f"Q{player['current_q']+1}: {q['question']}\n"
|
||||
if "answers" in q:
|
||||
for i, opt in enumerate(q['answers']):
|
||||
msg += f"{chr(65+i)}. {opt}\n"
|
||||
msg = msg.strip()
|
||||
return msg
|
||||
|
||||
def answer(self, user_id, answer):
|
||||
if user_id not in self.players:
|
||||
return "Join the quiz first."
|
||||
player = self.players[user_id]
|
||||
q_idx = player['current_q']
|
||||
if q_idx >= len(self.questions):
|
||||
return "No more questions."
|
||||
if q_idx in player['answered']:
|
||||
return "Already answered. Type 'next' for another question."
|
||||
q = self.questions[q_idx]
|
||||
# Check if it's multiple choice or free-text
|
||||
if "answers" in q and "correct" in q:
|
||||
try:
|
||||
ans_idx = ord(answer.upper()) - 65
|
||||
if ans_idx == q['correct']:
|
||||
player['score'] += 1
|
||||
# Track first correct answer
|
||||
if q_idx not in self.first_correct:
|
||||
self.first_correct[q_idx] = user_id
|
||||
logger.info(f"QuizMaster: Question {q_idx+1} first user with correct answer by {user_id}")
|
||||
result = "Correct! 🎉"
|
||||
else:
|
||||
result = f"Wrong. Correct answer: {chr(65+q['correct'])}"
|
||||
player['answered'].add(q_idx)
|
||||
player['current_q'] += 1
|
||||
return f"{result}\n" + self.next_question(user_id)
|
||||
except Exception:
|
||||
return "Invalid answer. Use A, B, C, etc."
|
||||
elif "answer" in q:
|
||||
user_ans = answer.strip().lower()
|
||||
correct_ans = str(q['answer']).strip().lower()
|
||||
if user_ans == correct_ans:
|
||||
player['score'] += 1
|
||||
if q_idx not in self.first_correct:
|
||||
self.first_correct[q_idx] = user_id
|
||||
logger.info(f"QuizMaster: Question {q_idx+1} first user with correct answer by {user_id}")
|
||||
result = "Correct! 🎉"
|
||||
else:
|
||||
result = f"Wrong. Correct answer: {q['answer']}"
|
||||
player['answered'].add(q_idx)
|
||||
player['current_q'] += 1
|
||||
return f"{result}\n" + self.next_question(user_id)
|
||||
else:
|
||||
return "Invalid question format."
|
||||
|
||||
def top_three(self):
|
||||
if not self.players:
|
||||
return "No players in the quiz."
|
||||
ranking = sorted(self.players.items(), key=lambda x: x[1]['score'], reverse=True)
|
||||
count = min(3, len(ranking))
|
||||
msg = f"🏆 Top {count} Player{'s' if count > 1 else ''}:\n"
|
||||
for idx, (uid, pdata) in enumerate(iterable=ranking[:count], start=1):
|
||||
msg += f"{idx}. {uid}: @{pdata['score']}\n"
|
||||
return msg
|
||||
|
||||
def broadcast(self, quizmaster_id, message):
|
||||
msgToAll = {}
|
||||
if quizmaster_id and str(quizmaster_id) not in self.quizmaster:
|
||||
return "Only the quizmaster can broadcast."
|
||||
if not self.players:
|
||||
return "No players to broadcast to."
|
||||
# set up message
|
||||
message_to_send = f"📢 From Quizmaster: {message}"
|
||||
msgToAll['message'] = message_to_send
|
||||
# setup players
|
||||
for uid in self.players.keys():
|
||||
msgToAll.setdefault('players', []).append(uid)
|
||||
return msgToAll
|
||||
|
||||
# Initialize the quiz game
|
||||
quizGamePlayer = QuizGame()
|
||||
@@ -1,25 +1,45 @@
|
||||
# Tic-Tac-Toe game for Meshtastic mesh-bot
|
||||
# Board positions chosen by numbers 1-9
|
||||
# 2025
|
||||
from modules.log import *
|
||||
import random
|
||||
# to molly and jake, I miss you both so much.
|
||||
|
||||
if disable_emojis_in_games:
|
||||
X = "X"
|
||||
O = "O"
|
||||
else:
|
||||
X = "❌"
|
||||
O = "⭕️"
|
||||
|
||||
class TicTacToe:
|
||||
def __init__(self):
|
||||
self.game = {}
|
||||
|
||||
def new_game(self, id):
|
||||
positiveThoughts = ["🚀I need to call NATO",
|
||||
"🏅Going for the gold!",
|
||||
"Mastering ❌TTT⭕️",]
|
||||
sorryNotGoinWell = ["😭Not your day, huh?",
|
||||
"📉Results here dont define you.",
|
||||
"🤖WOPR would be proud."]
|
||||
"""Start a new game"""
|
||||
games = won = 0
|
||||
ret = ""
|
||||
if id in self.game:
|
||||
games = self.game[id]["games"]
|
||||
won = self.game[id]["won"]
|
||||
ret += f"Games:{games} Won:{won}\n"
|
||||
if games > 3:
|
||||
if won / games >= 3.14159265358979323846: # win rate > pi
|
||||
ret += random.choice(positiveThoughts) + "\n"
|
||||
else:
|
||||
ret += random.choice(sorryNotGoinWell) + "\n"
|
||||
# Retain stats
|
||||
ret += f"Games:{games} 🥇❌:{won}\n"
|
||||
|
||||
self.game[id] = {
|
||||
"board": [" "] * 9, # 3x3 board as flat list
|
||||
"player": "X", # Human is X, bot is O
|
||||
"player": X, # Human is X, bot is O
|
||||
"games": games + 1,
|
||||
"won": won,
|
||||
"turn": "human" # whose turn it is
|
||||
@@ -39,13 +59,17 @@ class TicTacToe:
|
||||
row = ""
|
||||
for j in range(3):
|
||||
pos = i * 3 + j
|
||||
cell = b[pos] if b[pos] != " " else str(pos + 1)
|
||||
if disable_emojis_in_games:
|
||||
cell = b[pos] if b[pos] != " " else str(pos + 1)
|
||||
else:
|
||||
cell = b[pos] if b[pos] != " " else f" {str(pos + 1)} "
|
||||
row += cell
|
||||
if j < 2:
|
||||
row += "|"
|
||||
row += " | "
|
||||
board_str += row
|
||||
if i < 2:
|
||||
board_str += "\n-+-+-\n"
|
||||
#board_str += "\n-+-+-\n"
|
||||
board_str += "\n"
|
||||
|
||||
return board_str + "\n"
|
||||
|
||||
@@ -62,7 +86,7 @@ class TicTacToe:
|
||||
return False
|
||||
|
||||
# Make human move
|
||||
g["board"][pos] = "X"
|
||||
g["board"][pos] = X
|
||||
return True
|
||||
|
||||
def bot_move(self, id):
|
||||
@@ -70,14 +94,14 @@ class TicTacToe:
|
||||
g = self.game[id]
|
||||
|
||||
# Simple AI: Try to win, block, or pick random
|
||||
move = self.find_winning_move(id, "O") # Try to win
|
||||
move = self.find_winning_move(id, O) # Try to win
|
||||
if move == -1:
|
||||
move = self.find_winning_move(id, "X") # Block player
|
||||
move = self.find_winning_move(id, X) # Block player
|
||||
if move == -1:
|
||||
move = self.find_random_move(id) # Random move
|
||||
|
||||
if move != -1:
|
||||
g["board"][move] = "O"
|
||||
g["board"][move] = O
|
||||
return move
|
||||
|
||||
def find_winning_move(self, id, player):
|
||||
@@ -129,13 +153,13 @@ class TicTacToe:
|
||||
g = self.game[id]
|
||||
winner = self.check_winner(id)
|
||||
|
||||
if winner == "X":
|
||||
if winner == X:
|
||||
g["won"] += 1
|
||||
return "🎉You won! (n)ew (e)nd"
|
||||
elif winner == "O":
|
||||
elif winner == O:
|
||||
return "🤖Bot wins! (n)ew (e)nd"
|
||||
else:
|
||||
return "🤝Tie game! (n)ew (e)nd"
|
||||
return "🤝Tie, The only winning move! (n)ew (e)nd"
|
||||
|
||||
def play(self, id, input_msg):
|
||||
"""Main game play function"""
|
||||
@@ -143,7 +167,7 @@ class TicTacToe:
|
||||
return self.new_game(id)
|
||||
|
||||
# If input is just "tictactoe", show current board
|
||||
if input_msg.lower().strip() == "tictactoe":
|
||||
if input_msg.lower().strip() == ("tictactoe" or "tic-tac-toe"):
|
||||
return self.show_board(id) + "Your turn! Pick 1-9:"
|
||||
|
||||
g = self.game[id]
|
||||
@@ -201,8 +225,19 @@ class TicTacToe:
|
||||
def end_game(self, id):
|
||||
"""Clean up finished game but keep stats"""
|
||||
if id in self.game:
|
||||
games = self.game[id]["games"]
|
||||
won = self.game[id]["won"]
|
||||
# Remove game but we'll create new one on next play
|
||||
del self.game[id]
|
||||
# Preserve stats for next game
|
||||
self.game[id] = {
|
||||
"board": [" "] * 9,
|
||||
"player": X,
|
||||
"games": games,
|
||||
"won": won,
|
||||
"turn": "human"
|
||||
}
|
||||
|
||||
|
||||
def end(self, id):
|
||||
"""End game completely (called by 'end' command)"""
|
||||
|
||||
@@ -16,6 +16,7 @@ trap_list_location = ("whereami", "wx", "wxa", "wxalert", "rlist", "ea", "ealert
|
||||
def where_am_i(lat=0, lon=0, short=False, zip=False):
|
||||
whereIam = ""
|
||||
grid = mh.to_maiden(float(lat), float(lon))
|
||||
location = lat, lon
|
||||
|
||||
if int(float(lat)) == 0 and int(float(lon)) == 0:
|
||||
logger.error("Location: No GPS data, try sending location")
|
||||
@@ -171,6 +172,7 @@ def getArtSciRepeaters(lat=0, lon=0):
|
||||
|
||||
def get_NOAAtide(lat=0, lon=0):
|
||||
station_id = ""
|
||||
location = lat,lon
|
||||
if float(lat) == 0 and float(lon) == 0:
|
||||
logger.error("Location:No GPS data, try sending location for tide")
|
||||
return NO_DATA_NOGPS
|
||||
@@ -235,6 +237,7 @@ def get_NOAAtide(lat=0, lon=0):
|
||||
def get_NOAAweather(lat=0, lon=0, unit=0):
|
||||
# get weather report from NOAA for forecast detailed
|
||||
weather = ""
|
||||
location = lat,lon
|
||||
if float(lat) == 0 and float(lon) == 0:
|
||||
return NO_DATA_NOGPS
|
||||
|
||||
@@ -338,14 +341,15 @@ def abbreviate_noaa(row):
|
||||
|
||||
line = row
|
||||
for key, value in replacements.items():
|
||||
# case insensitive replace
|
||||
line = line.replace(key, value).replace(key.capitalize(), value).replace(key.upper(), value)
|
||||
|
||||
for variant in (key, key.capitalize(), key.upper()):
|
||||
if variant != value:
|
||||
line = line.replace(variant, value)
|
||||
return line
|
||||
|
||||
def getWeatherAlertsNOAA(lat=0, lon=0, useDefaultLatLon=False):
|
||||
# get weather alerts from NOAA limited to ALERT_COUNT with the total number of alerts found
|
||||
alerts = ""
|
||||
location = lat,lon
|
||||
if float(lat) == 0 and float(lon) == 0 and not useDefaultLatLon:
|
||||
return NO_DATA_NOGPS
|
||||
else:
|
||||
@@ -422,6 +426,7 @@ def alertBrodcastNOAA():
|
||||
def getActiveWeatherAlertsDetailNOAA(lat=0, lon=0):
|
||||
# get the latest details of weather alerts from NOAA
|
||||
alerts = ""
|
||||
location = lat,lon
|
||||
if float(lat) == 0 and float(lon) == 0:
|
||||
logger.warning("Location:No GPS data, try sending location for weather alerts")
|
||||
return NO_DATA_NOGPS
|
||||
@@ -609,54 +614,47 @@ def getIpawsAlert(lat=0, lon=0, shortAlerts = False):
|
||||
|
||||
return alert
|
||||
|
||||
def get_flood_noaa(lat=0, lon=0, uid=0):
|
||||
# get the latest flood alert from NOAA
|
||||
def get_flood_noaa(lat=0, lon=0, uid=None):
|
||||
"""
|
||||
Fetch the latest flood alert from NOAA for a given gauge UID.
|
||||
Returns a formatted string or an error message.
|
||||
"""
|
||||
api_url = "https://api.water.noaa.gov/nwps/v1/gauges/"
|
||||
headers = {'accept': 'application/json'}
|
||||
if uid == 0:
|
||||
return "No flood gauge data found"
|
||||
if not uid:
|
||||
logger.warning(f"Location:No flood gauge data found for UID {uid}")
|
||||
return ERROR_FETCHING_DATA
|
||||
try:
|
||||
response = requests.get(api_url + str(uid), headers=headers, timeout=urlTimeoutSeconds)
|
||||
if not response.ok:
|
||||
logger.warning("Location:Error fetching flood gauge data from NOAA for " + str(uid))
|
||||
logger.warning(f"Location:Error fetching flood gauge data from NOAA for {uid} (HTTP {response.status_code})")
|
||||
return ERROR_FETCHING_DATA
|
||||
except (requests.exceptions.RequestException):
|
||||
logger.warning("Location:Error fetching flood gauge data from NOAA for " + str(uid))
|
||||
data = response.json()
|
||||
if not data or 'status' not in data:
|
||||
logger.warning(f"Location:No flood gauge data found for UID {uid}")
|
||||
return "No flood gauge data found"
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.warning(f"Location:Error fetching flood gauge data from: {api_url}{uid} ({e})")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
data = response.json()
|
||||
if not data:
|
||||
return "No flood gauge data found"
|
||||
|
||||
# extract values from JSON
|
||||
try:
|
||||
name = data['name']
|
||||
status_observed_primary = data['status']['observed']['primary']
|
||||
status_observed_primary_unit = data['status']['observed']['primaryUnit']
|
||||
status_observed_secondary = data['status']['observed']['secondary']
|
||||
status_observed_secondary_unit = data['status']['observed']['secondaryUnit']
|
||||
status_observed_floodCategory = data['status']['observed']['floodCategory']
|
||||
status_forecast_primary = data['status']['forecast']['primary']
|
||||
status_forecast_primary_unit = data['status']['forecast']['primaryUnit']
|
||||
status_forecast_secondary = data['status']['forecast']['secondary']
|
||||
status_forecast_secondary_unit = data['status']['forecast']['secondaryUnit']
|
||||
status_forecast_floodCategory = data['status']['forecast']['floodCategory']
|
||||
|
||||
# except KeyError as e:
|
||||
# print(f"Missing key in data: {e}")
|
||||
# except TypeError as e:
|
||||
# print(f"Type error in data: {e}")
|
||||
except Exception as e:
|
||||
logger.debug("Location:Error extracting flood gauge data from NOAA for " + str(uid))
|
||||
logger.warning(f"Location:Unexpected error: {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
# format the flood data
|
||||
logger.debug(f"System: NOAA Flood data for {str(uid)}")
|
||||
flood_data = f"Flood Data {name}:\n"
|
||||
flood_data += f"Observed: {status_observed_primary}{status_observed_primary_unit}({status_observed_secondary}{status_observed_secondary_unit}) risk: {status_observed_floodCategory}"
|
||||
flood_data += f"\nForecast: {status_forecast_primary}{status_forecast_primary_unit}({status_forecast_secondary}{status_forecast_secondary_unit}) risk: {status_forecast_floodCategory}"
|
||||
|
||||
return flood_data
|
||||
# extract values from JSON safely
|
||||
try:
|
||||
name = data.get('name', 'Unknown')
|
||||
observed = data['status'].get('observed', {})
|
||||
forecast = data['status'].get('forecast', {})
|
||||
flood_data = f"Flood Data {name}:\n"
|
||||
flood_data += f"Observed: {observed.get('primary', '?')}{observed.get('primaryUnit', '')} ({observed.get('secondary', '?')}{observed.get('secondaryUnit', '')}) risk: {observed.get('floodCategory', '?')}"
|
||||
flood_data += f"\nForecast: {forecast.get('primary', '?')}{forecast.get('primaryUnit', '')} ({forecast.get('secondary', '?')}{forecast.get('secondaryUnit', '')}) risk: {forecast.get('floodCategory', '?')}"
|
||||
#flood_data += f"\nStage: {data.get('stage', '?')} {data.get('stageUnit', '')}, Flow: {data.get('flow', '?')} {data.get('flowUnit', '')}"
|
||||
#flood_data += f"\nLast Updated: {data.get('status', {}).get('lastUpdated', '?')}"
|
||||
flood_data += f"\n"
|
||||
return flood_data
|
||||
except Exception as e:
|
||||
logger.debug(f"Location:Error extracting flood gauge data from NOAA for {uid}: {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
def get_volcano_usgs(lat=0, lon=0):
|
||||
alerts = ''
|
||||
@@ -820,6 +818,7 @@ def distance(lat=0,lon=0,nodeID=0, reset=False):
|
||||
# part of the howfar function, calculates the distance between two lat/lon points
|
||||
msg = ""
|
||||
dupe = False
|
||||
location = lat,lon
|
||||
r = 6371 # Radius of earth in kilometers # haversine formula
|
||||
|
||||
if lat == 0 and lon == 0:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from modules.settings import *
|
||||
# if LOGGING_LEVEL is not set in settings.py, default to DEBUG
|
||||
if not LOGGING_LEVEL:
|
||||
|
||||
252
modules/radio.py
252
modules/radio.py
@@ -1,13 +1,95 @@
|
||||
# meshing around with hamlib as a source for info to send to mesh network
|
||||
# detect signal strength and frequency of active channel if appears to be in use send to mesh network
|
||||
# depends on rigctld running externally as a network service
|
||||
# also can use VOX detection with a microphone and vosk speech to text to send voice messages to mesh network
|
||||
# requires vosk and sounddevice python modules. will auto download needed. more from https://alphacephei.com/vosk/models and unpack
|
||||
# 2024 Kelly Keeton K7MHI
|
||||
|
||||
import socket
|
||||
import asyncio
|
||||
from modules.log import *
|
||||
import asyncio
|
||||
|
||||
# verbose debug logging for trap words function
|
||||
debugVoxTmsg = False
|
||||
|
||||
|
||||
if radio_detection_enabled:
|
||||
# used by hamlib detection
|
||||
import socket
|
||||
|
||||
if voxDetectionEnabled:
|
||||
# module global variables
|
||||
previousVoxState = False
|
||||
voxHoldTime = signalHoldTime
|
||||
|
||||
try:
|
||||
import sounddevice as sd # pip install sounddevice sudo apt install portaudio19-dev
|
||||
from vosk import Model, KaldiRecognizer # pip install vosk
|
||||
import json
|
||||
q = asyncio.Queue(maxsize=10) # what is a reasonable limit?
|
||||
|
||||
if useLocalVoxModel:
|
||||
voxModel = Model(lang=localVoxModelPath) # use built in model for specified language
|
||||
else:
|
||||
voxModel = Model(lang=voxLanguage) # use built in model for specified language
|
||||
|
||||
except Exception as e:
|
||||
print(f"RadioMon: Error importing VOX dependencies: {e}")
|
||||
print(f"To use VOX detection please install the vosk and sounddevice python modules")
|
||||
print(f"pip install vosk sounddevice")
|
||||
print(f"sounddevice needs pulseaudio, apt-get install portaudio19-dev")
|
||||
voxDetectionEnabled = False
|
||||
logger.error(f"RadioMon: VOX detection disabled due to import error")
|
||||
|
||||
FREQ_NAME_MAP = {
|
||||
462562500: "GRMS CH1",
|
||||
462587500: "GRMS CH2",
|
||||
462612500: "GRMS CH3",
|
||||
462637500: "GRMS CH4",
|
||||
462662500: "GRMS CH5",
|
||||
462687500: "GRMS CH6",
|
||||
462712500: "GRMS CH7",
|
||||
467562500: "GRMS CH8",
|
||||
467587500: "GRMS CH9",
|
||||
467612500: "GRMS CH10",
|
||||
467637500: "GRMS CH11",
|
||||
467662500: "GRMS CH12",
|
||||
467687500: "GRMS CH13",
|
||||
467712500: "GRMS CH14",
|
||||
467737500: "GRMS CH15",
|
||||
462550000: "GRMS CH16",
|
||||
462575000: "GMRS CH17",
|
||||
462600000: "GMRS CH18",
|
||||
462625000: "GMRS CH19",
|
||||
462675000: "GMRS CH20",
|
||||
462670000: "GMRS CH21",
|
||||
462725000: "GMRS CH22",
|
||||
462725500: "GMRS CH23",
|
||||
467575000: "GMRS CH24",
|
||||
467600000: "GMRS CH25",
|
||||
467625000: "GMRS CH26",
|
||||
467650000: "GMRS CH27",
|
||||
467675000: "GMRS CH28",
|
||||
467700000: "FRS CH1",
|
||||
462650000: "FRS CH5",
|
||||
462700000: "FRS CH7",
|
||||
462737500: "FRS CH16",
|
||||
146520000: "2M Simplex Calling",
|
||||
446000000: "70cm Simplex Calling",
|
||||
156800000: "Marine CH16",
|
||||
# Add more as needed
|
||||
}
|
||||
|
||||
def get_freq_common_name(freq):
|
||||
freq = int(freq)
|
||||
name = FREQ_NAME_MAP.get(freq)
|
||||
if name:
|
||||
return name
|
||||
else:
|
||||
# Return MHz if not found
|
||||
return f"{freq/1000000} Mhz"
|
||||
|
||||
def get_hamlib(msg="f"):
|
||||
# get data from rigctld server
|
||||
try:
|
||||
rigControlSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
rigControlSocket.settimeout(2)
|
||||
@@ -29,110 +111,17 @@ def get_hamlib(msg="f"):
|
||||
except Exception as e:
|
||||
logger.error(f"RadioMon: Error fetching data from rigctld: {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
def get_freq_common_name(freq):
|
||||
freq = int(freq)
|
||||
if freq == 462562500:
|
||||
return "GRMS CH1"
|
||||
elif freq == 462587500:
|
||||
return "GRMS CH2"
|
||||
elif freq == 462612500:
|
||||
return "GRMS CH3"
|
||||
elif freq == 462637500:
|
||||
return "GRMS CH4"
|
||||
elif freq == 462662500:
|
||||
return "GRMS CH5"
|
||||
elif freq == 462687500:
|
||||
return "GRMS CH6"
|
||||
elif freq == 462712500:
|
||||
return "GRMS CH7"
|
||||
elif freq == 467562500:
|
||||
return "GRMS CH8"
|
||||
elif freq == 467587500:
|
||||
return "GRMS CH9"
|
||||
elif freq == 467612500:
|
||||
return "GRMS CH10"
|
||||
elif freq == 467637500:
|
||||
return "GRMS CH11"
|
||||
elif freq == 467662500:
|
||||
return "GRMS CH12"
|
||||
elif freq == 467687500:
|
||||
return "GRMS CH13"
|
||||
elif freq == 467712500:
|
||||
return "GRMS CH14"
|
||||
elif freq == 467737500:
|
||||
return "GRMS CH15"
|
||||
elif freq == 462550000:
|
||||
return "GRMS CH16"
|
||||
elif freq == 462575000:
|
||||
return "GMRS CH17"
|
||||
elif freq == 462600000:
|
||||
return "GMRS CH18"
|
||||
elif freq == 462625000:
|
||||
return "GMRS CH19"
|
||||
elif freq == 462675000:
|
||||
return "GMRS CH20"
|
||||
elif freq == 462670000:
|
||||
return "GMRS CH21"
|
||||
elif freq == 462725000:
|
||||
return "GMRS CH22"
|
||||
elif freq == 462725500:
|
||||
return "GMRS CH23"
|
||||
elif freq == 467575000:
|
||||
return "GMRS CH24"
|
||||
elif freq == 467600000:
|
||||
return "GMRS CH25"
|
||||
elif freq == 467625000:
|
||||
return "GMRS CH26"
|
||||
elif freq == 467650000:
|
||||
return "GMRS CH27"
|
||||
elif freq == 467675000:
|
||||
return "GMRS CH28"
|
||||
elif freq == 467700000:
|
||||
return "FRS CH1"
|
||||
elif freq == 462575000:
|
||||
return "FRS CH2"
|
||||
elif freq == 462600000:
|
||||
return "FRS CH3"
|
||||
elif freq == 462650000:
|
||||
return "FRS CH5"
|
||||
elif freq == 462675000:
|
||||
return "FRS CH6"
|
||||
elif freq == 462700000:
|
||||
return "FRS CH7"
|
||||
elif freq == 462725000:
|
||||
return "FRS CH8"
|
||||
elif freq == 462562500:
|
||||
return "FRS CH9"
|
||||
elif freq == 462587500:
|
||||
return "FRS CH10"
|
||||
elif freq == 462612500:
|
||||
return "FRS CH11"
|
||||
elif freq == 462637500:
|
||||
return "FRS CH12"
|
||||
elif freq == 462662500:
|
||||
return "FRS CH13"
|
||||
elif freq == 462687500:
|
||||
return "FRS CH14"
|
||||
elif freq == 462712500:
|
||||
return "FRS CH15"
|
||||
elif freq == 462737500:
|
||||
return "FRS CH16"
|
||||
elif freq == 146520000:
|
||||
return "2M Simplex Calling"
|
||||
elif freq == 446000000:
|
||||
return "70cm Simplex Calling"
|
||||
elif freq == 156800000:
|
||||
return "Marine CH16"
|
||||
else:
|
||||
#return Mhz
|
||||
freq = freq/1000000
|
||||
return f"{freq} Mhz"
|
||||
|
||||
def get_sig_strength():
|
||||
strength = get_hamlib('l STRENGTH')
|
||||
return strength
|
||||
|
||||
def vox_callback(indata, frames, time, status):
|
||||
if status:
|
||||
logger.warning(f"RadioMon: VOX input status: {status}")
|
||||
q.put(bytes(indata))
|
||||
|
||||
|
||||
async def signalWatcher():
|
||||
global previousStrength
|
||||
global signalCycle
|
||||
@@ -157,4 +146,65 @@ async def signalWatcher():
|
||||
signalCycle = 0
|
||||
previousStrength = -40
|
||||
|
||||
def make_vox_callback(loop, q):
|
||||
def vox_callback(indata, frames, time, status):
|
||||
if status:
|
||||
logger.warning(f"RadioMon: VOX input status: {status}")
|
||||
try:
|
||||
loop.call_soon_threadsafe(q.put_nowait, bytes(indata))
|
||||
except asyncio.QueueFull:
|
||||
# Optionally log or just drop the oldest
|
||||
logger.debug("RadioMon: VOX queue full, dropping audio frame")
|
||||
except RuntimeError:
|
||||
# Loop may be closed
|
||||
pass
|
||||
return vox_callback
|
||||
|
||||
async def voxMonitor():
|
||||
global previousVoxState, voxMsgQueue
|
||||
try:
|
||||
model = voxModel
|
||||
device_info = sd.query_devices(voxInputDevice, 'input')
|
||||
samplerate = 16000
|
||||
logger.debug(f"RadioMon: VOX monitor started on device {device_info['name']} with samplerate {samplerate} using trap words: {voxTrapList if voxOnTrapList else 'none'}")
|
||||
rec = KaldiRecognizer(model, samplerate)
|
||||
loop = asyncio.get_running_loop()
|
||||
callback = make_vox_callback(loop, q)
|
||||
with sd.RawInputStream(
|
||||
device=voxInputDevice,
|
||||
samplerate=samplerate,
|
||||
blocksize=8000,
|
||||
dtype='int16',
|
||||
channels=1,
|
||||
callback=callback
|
||||
):
|
||||
while True:
|
||||
data = await q.get()
|
||||
if rec.AcceptWaveform(data):
|
||||
result = rec.Result()
|
||||
text = json.loads(result).get("text", "")
|
||||
# check for trap words
|
||||
if text and text != 'huh':
|
||||
if voxOnTrapList:
|
||||
if isinstance(voxTrapList, str):
|
||||
traps = [voxTrapList]
|
||||
else:
|
||||
traps = voxTrapList
|
||||
if any(trap.lower() in text.lower() for trap in traps):
|
||||
#remove the trap words from the text
|
||||
for trap in traps:
|
||||
text = text.replace(trap, '')
|
||||
text = text.strip()
|
||||
if text:
|
||||
logger.debug(f"RadioMon: VOX 🎙️Trapped {voxTrapList} in: {text}")
|
||||
voxMsgQueue.append(f"🎙️Trapped {voxDescription}: {text}")
|
||||
else:
|
||||
if debugVoxTmsg:
|
||||
logger.debug(f"RadioMon: VOX ignored text not on trap list: {text}")
|
||||
else:
|
||||
voxMsgQueue.append(f"🎙️Detected {voxDescription}: {text}")
|
||||
await asyncio.sleep(0.5)
|
||||
except Exception as e:
|
||||
logger.error(f"RadioMon: Error in VOX monitor: {e}")
|
||||
|
||||
# end of file
|
||||
95
modules/rss.py
Normal file
95
modules/rss.py
Normal file
@@ -0,0 +1,95 @@
|
||||
# rss feed module for meshing-around 2025
|
||||
from modules.log import *
|
||||
import urllib.request
|
||||
import xml.etree.ElementTree as ET
|
||||
import html
|
||||
from html.parser import HTMLParser
|
||||
|
||||
class MLStripper(HTMLParser):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.reset()
|
||||
self.fed = []
|
||||
def handle_data(self, d):
|
||||
self.fed.append(d)
|
||||
def get_data(self):
|
||||
return ''.join(self.fed)
|
||||
|
||||
def strip_tags(html_text):
|
||||
s = MLStripper()
|
||||
s.feed(html_text)
|
||||
return s.get_data()
|
||||
|
||||
RSS_FEED_URLS = rssFeedURL
|
||||
RSS_FEED_NAMES = rssFeedNames
|
||||
RSS_RETURN_COUNT = rssMaxItems
|
||||
RSS_TRIM_LENGTH = rssTruncate
|
||||
|
||||
def get_rss_feed(msg):
|
||||
# Determine which feed to use
|
||||
feed_name = ""
|
||||
msg_lower = msg.lower() if msg else ""
|
||||
if msg_lower and any(name.lower() in msg_lower for name in RSS_FEED_NAMES):
|
||||
for name in RSS_FEED_NAMES:
|
||||
if name.lower() in msg_lower:
|
||||
feed_name = name
|
||||
break
|
||||
else:
|
||||
logger.debug(f"RSS: No feed name found in message '{msg}'. Using default feed.")
|
||||
feed_name = RSS_FEED_NAMES[0] if RSS_FEED_NAMES else "default"
|
||||
|
||||
try:
|
||||
idx = RSS_FEED_NAMES.index(feed_name)
|
||||
feed_url = RSS_FEED_URLS[idx]
|
||||
except (ValueError, IndexError):
|
||||
logger.warning(f"RSS: Feed '{feed_name}' not found in RSS_FEED_URLS ({RSS_FEED_URLS}).")
|
||||
return f"Feed '{feed_name}' not found."
|
||||
|
||||
if "?" in msg_lower:
|
||||
return f"Fetches the latest {RSS_RETURN_COUNT} entries RSS feeds. Available feeds are: {', '.join(RSS_FEED_NAMES)}. To fetch a specific feed, include its name in your request."
|
||||
|
||||
try:
|
||||
logger.debug(f"Fetching RSS feed from {feed_url} from message '{msg}'")
|
||||
agent = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
||||
request = urllib.request.Request(feed_url, headers=agent)
|
||||
with urllib.request.urlopen(request, timeout=urlTimeoutSeconds) as response:
|
||||
xml_data = response.read()
|
||||
root = ET.fromstring(xml_data)
|
||||
# Try both namespaced and non-namespaced item tags
|
||||
items = root.findall('.//item')
|
||||
ns = None
|
||||
if not items:
|
||||
# Try to find the namespace dynamically
|
||||
for elem in root.iter():
|
||||
if elem.tag.endswith('item'):
|
||||
ns_uri = elem.tag.split('}')[0].strip('{')
|
||||
items = root.findall(f'.//{{{ns_uri}}}item')
|
||||
ns = ns_uri
|
||||
break
|
||||
items = items[:RSS_RETURN_COUNT]
|
||||
if not items:
|
||||
return "No RSS feed entries found."
|
||||
formatted_entries = []
|
||||
for item in items:
|
||||
if ns:
|
||||
title = item.findtext(f'{{{ns}}}title', default='No title')
|
||||
link = item.findtext(f'{{{ns}}}link', default=None)
|
||||
description = item.findtext(f'{{{ns}}}description', default='No description')
|
||||
pub_date = item.findtext(f'{{{ns}}}pubDate', default='No date')
|
||||
else:
|
||||
title = item.findtext('title', default='No title')
|
||||
link = item.findtext('link', default=None)
|
||||
description = item.findtext('description', default='No description')
|
||||
pub_date = item.findtext('pubDate', default='No date')
|
||||
|
||||
# Unescape HTML entities and strip tags
|
||||
description = html.unescape(description)
|
||||
description = strip_tags(description)
|
||||
if len(description) > RSS_TRIM_LENGTH:
|
||||
description = description[:RSS_TRIM_LENGTH - 3] + "..."
|
||||
|
||||
formatted_entries.append(f"{title}\n{description}\n")
|
||||
return "\n".join(formatted_entries)
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching RSS feed from {feed_url}: {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
@@ -28,6 +28,11 @@ wiki_return_limit = 3 # limit the number of sentences returned off the first par
|
||||
GAMEDELAY = 28800 # 8 hours in seconds for game mode holdoff
|
||||
cmdHistory = [] # list to hold the last commands
|
||||
seenNodes = [] # list to hold the last seen nodes
|
||||
surveyTracker, tictactoeTracker, hamtestTracker, hangmanTracker, golfTracker, mastermindTracker, vpTracker, blackjackTracker, lemonadeTracker, dwPlayerTracker, jackTracker = [], [], [], [], [], [], [], [], [], [], [] # game trackers
|
||||
cmdHistory = [] # list to hold the command history for lheard and history commands
|
||||
msg_history = [] # list to hold the message history for the messages command
|
||||
max_bytes = 200 # Meshtastic has ~237 byte limit, use conservative 200 bytes for message content
|
||||
voxMsgQueue = [] # queue for VOX detected messages
|
||||
|
||||
# Read the config file, if it does not exist, create basic config file
|
||||
config = configparser.ConfigParser()
|
||||
@@ -207,9 +212,10 @@ try:
|
||||
log_backup_count = config['general'].getint('LogBackupCount', 32) # default 32 days
|
||||
syslog_to_file = config['general'].getboolean('SyslogToFile', True) # default on
|
||||
LOGGING_LEVEL = config['general'].get('sysloglevel', 'DEBUG') # default DEBUG
|
||||
urlTimeoutSeconds = config['general'].getint('urlTimeout', 10) # default 10 seconds
|
||||
urlTimeoutSeconds = config['general'].getint('urlTimeout', 15) # default 15 seconds for URL fetch timeout
|
||||
store_forward_enabled = config['general'].getboolean('StoreForward', True)
|
||||
storeFlimit = config['general'].getint('StoreLimit', 3) # default 3 messages for S&F
|
||||
reverseSF = config['general'].getboolean('reverseSF', False) # default False, send oldest first
|
||||
welcome_message = config['general'].get('welcome_message', WELCOME_MSG)
|
||||
welcome_message = (f"{welcome_message}").replace('\\n', '\n') # allow for newlines in the welcome message
|
||||
motd_enabled = config['general'].getboolean('motdEnabled', True)
|
||||
@@ -223,6 +229,9 @@ try:
|
||||
bee_enabled = config['general'].getboolean('bee', False) # 🐝 off by default undocumented
|
||||
solar_conditions_enabled = config['general'].getboolean('spaceWeather', True)
|
||||
wikipedia_enabled = config['general'].getboolean('wikipedia', False)
|
||||
use_kiwix_server = config['general'].getboolean('useKiwixServer', False)
|
||||
kiwix_url = config['general'].get('kiwixURL', 'http://127.0.0.1:8080')
|
||||
kiwix_library_name = config['general'].get('kiwixLibraryName', 'wikipedia_en_100_nopic_2024-06')
|
||||
llm_enabled = config['general'].getboolean('ollama', False) # https://ollama.com
|
||||
ollamaHostName = config['general'].get('ollamaHostName', 'http://localhost:11434') # default localhost
|
||||
llmModel = config['general'].get('ollamaModel', 'gemma3:270m') # default gemma3:270m
|
||||
@@ -232,6 +241,11 @@ try:
|
||||
favoriteNodeList = config['general'].get('favoriteNodeList', '').split(',')
|
||||
enableEcho = config['general'].getboolean('enableEcho', False) # default False
|
||||
echoChannel = config['general'].getint('echoChannel', '9') # default 9, empty string to ignore
|
||||
rssEnable = config['general'].getboolean('rssEnable', True) # default True
|
||||
rssFeedURL = config['general'].get('rssFeedURL', 'http://www.hackaday.com/rss.xml,https://www.arrl.org/rss/arrl.rss').split(',')
|
||||
rssMaxItems = config['general'].getint('rssMaxItems', 3) # default 3 items
|
||||
rssTruncate = config['general'].getint('rssTruncate', 100) # default 100 characters
|
||||
rssFeedNames = config['general'].get('rssFeedNames', 'default,arrl').split(',')
|
||||
|
||||
# emergency response
|
||||
emergency_responder_enabled = config['emergencyHandler'].getboolean('enabled', False)
|
||||
@@ -259,6 +273,8 @@ try:
|
||||
location_enabled = config['location'].getboolean('enabled', True)
|
||||
latitudeValue = config['location'].getfloat('lat', 48.50)
|
||||
longitudeValue = config['location'].getfloat('lon', -123.0)
|
||||
fuzz_config_location = config['location'].getboolean('fuzzConfigLocation', True) # default True
|
||||
fuzzItAll = config['location'].getboolean('fuzzAllLocations', False) # default False, only fuzz config location
|
||||
use_meteo_wxApi = config['location'].getboolean('UseMeteoWxAPI', False) # default False use NOAA
|
||||
use_metric = config['location'].getboolean('useMetric', False) # default Imperial units
|
||||
repeater_lookup = config['location'].get('repeaterLookup', 'rbook') # default repeater lookup source
|
||||
@@ -341,28 +357,41 @@ try:
|
||||
schedulerInterval = config['scheduler'].get('interval', '') # default empty
|
||||
schedulerTime = config['scheduler'].get('time', '') # default empty
|
||||
schedulerValue = config['scheduler'].get('value', '') # default empty
|
||||
schedulerMotd = config['scheduler'].getboolean('schedulerMotd', False) # default False
|
||||
|
||||
# radio monitoring
|
||||
radio_detection_enabled = config['radioMon'].getboolean('enabled', False)
|
||||
rigControlServerAddress = config['radioMon'].get('rigControlServerAddress', 'localhost:4532') # default localhost:4532
|
||||
sigWatchBroadcastCh = config['radioMon'].get('sigWatchBroadcastCh', '2').split(',') # default Channel 2
|
||||
sigWatchBroadcastInterface = config['radioMon'].getint('sigWatchBroadcastInterface', 1) # default interface 1
|
||||
signalDetectionThreshold = config['radioMon'].getint('signalDetectionThreshold', -10) # default -10 dBm
|
||||
signalHoldTime = config['radioMon'].getint('signalHoldTime', 10) # default 10 seconds
|
||||
signalCooldown = config['radioMon'].getint('signalCooldown', 5) # default 1 second
|
||||
signalCycleLimit = config['radioMon'].getint('signalCycleLimit', 5) # default 5 cycles, used with SIGNAL_COOLDOWN
|
||||
voxDetectionEnabled = config['radioMon'].getboolean('voxDetectionEnabled', False) # default VOX detection disabled
|
||||
voxDescription = config['radioMon'].get('voxDescription', 'VOX') # default VOX detected audio message
|
||||
useLocalVoxModel = config['radioMon'].getboolean('useLocalVoxModel', False) # default False
|
||||
localVoxModelPath = config['radioMon'].get('localVoxModelPath', 'no') # default models/vox.tflite
|
||||
voxLanguage = config['radioMon'].get('voxLanguage', 'en-US') # default en-US
|
||||
voxInputDevice = config['radioMon'].get('voxInputDevice', 'default') # default default
|
||||
voxOnTrapList = config['radioMon'].getboolean('voxOnTrapList', False) # default False
|
||||
voxTrapList = config['radioMon'].get('voxTrapList', 'chirpy').split(',') # default chirpy
|
||||
|
||||
# file monitor
|
||||
file_monitor_enabled = config['fileMon'].getboolean('filemon_enabled', False)
|
||||
file_monitor_file_path = config['fileMon'].get('file_path', 'alert.txt') # default alert.txt
|
||||
file_monitor_broadcastCh = config['fileMon'].get('broadcastCh', '2').split(',') # default Channel 2
|
||||
read_news_enabled = config['fileMon'].getboolean('enable_read_news', False) # default disabled
|
||||
news_file_path = config['fileMon'].get('news_file_path', 'news.txt') # default news.txt
|
||||
news_file_path = config['fileMon'].get('news_file_path', '../data/news.txt') # default ../data/news.txt
|
||||
news_random_line_only = config['fileMon'].getboolean('news_random_line', False) # default False
|
||||
enable_runShellCmd = config['fileMon'].getboolean('enable_runShellCmd', False) # default False
|
||||
allowXcmd = config['fileMon'].getboolean('allowXcmd', False) # default False
|
||||
xCmd2factorEnabled = config['fileMon'].getboolean('2factor_enabled', True) # default True
|
||||
xCmd2factor_timeout = config['fileMon'].getint('2factor_timeout', 100) # default 100 seconds
|
||||
|
||||
# games
|
||||
game_hop_limit = config['messagingSettings'].getint('game_hop_limit', 5) # default 3 hops
|
||||
game_hop_limit = config['games'].getint('game_hop_limit', 5) # default 5 hops
|
||||
disable_emojis_in_games = config['games'].getboolean('disable_emojis', False) # default False
|
||||
dopewars_enabled = config['games'].getboolean('dopeWars', True)
|
||||
lemonade_enabled = config['games'].getboolean('lemonade', True)
|
||||
blackjack_enabled = config['games'].getboolean('blackjack', True)
|
||||
@@ -372,11 +401,15 @@ try:
|
||||
hangman_enabled = config['games'].getboolean('hangman', True)
|
||||
hamtest_enabled = config['games'].getboolean('hamtest', True)
|
||||
tictactoe_enabled = config['games'].getboolean('tictactoe', True)
|
||||
quiz_enabled = config['games'].getboolean('quiz', False)
|
||||
survey_enabled = config['games'].getboolean('survey', False)
|
||||
surveyRecordID = config['games'].getboolean('surveyRecordID', True)
|
||||
surveyRecordLocation = config['games'].getboolean('surveyRecordLocation', True)
|
||||
|
||||
# messaging settings
|
||||
responseDelay = config['messagingSettings'].getfloat('responseDelay', 0.7) # default 0.7
|
||||
splitDelay = config['messagingSettings'].getfloat('splitDelay', 0) # default 0
|
||||
MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160
|
||||
MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160 chars
|
||||
wantAck = config['messagingSettings'].getboolean('wantAck', False) # default False
|
||||
maxBuffer = config['messagingSettings'].getint('maxBuffer', 200) # default 200
|
||||
enableHopLogs = config['messagingSettings'].getboolean('enableHopLogs', False) # default False
|
||||
@@ -384,6 +417,7 @@ try:
|
||||
metadataFilter = config['messagingSettings'].get('metadataFilter', '').split(',') # default empty
|
||||
DEBUGpacket = config['messagingSettings'].getboolean('DEBUGpacket', False) # default False
|
||||
noisyNodeLogging = config['messagingSettings'].getboolean('noisyNodeLogging', False) # default False
|
||||
logMetaStats = config['messagingSettings'].getboolean('logMetaStats', True) # default True
|
||||
noisyTelemetryLimit = config['messagingSettings'].getint('noisyTelemetryLimit', 5) # default 5 packets
|
||||
except Exception as e:
|
||||
print(f"System: Error reading config file: {e}")
|
||||
|
||||
190
modules/survey.py
Normal file
190
modules/survey.py
Normal file
@@ -0,0 +1,190 @@
|
||||
# Survey Module for meshbot 2025
|
||||
# Provides a survey function to collect responses and put into a CSV file
|
||||
# this module reads survey definitions from JSON files in the data/surveys directory
|
||||
# Each survey is defined in a separate JSON file named <survey_name>_survey.json
|
||||
# Example survey file: example_survey.json
|
||||
# Example survey response file: example_responses.csv
|
||||
# Each survey consists of multiple questions, which can be multiple choice, integer, or text
|
||||
# Users can start a survey, answer questions, and end the survey
|
||||
# Module acts like a game locking DM until the survey is complete or ended
|
||||
|
||||
import json
|
||||
import os # For file operations
|
||||
from collections import Counter
|
||||
from modules.log import *
|
||||
|
||||
allowedSurveys = [] # List of allowed survey names
|
||||
|
||||
trap_list_survey = ("survey",)
|
||||
|
||||
class SurveyModule:
|
||||
def __init__(self):
|
||||
self.base_dir = os.path.dirname(__file__)
|
||||
self.survey_dir = os.path.join(self.base_dir, '..', 'data', 'surveys') # Directory for survey JSON files
|
||||
self.response_dir = os.path.join(self.base_dir, '..', 'data', 'surveys') # Directory for survey response CSV files
|
||||
self.surveys = {}
|
||||
self.responses = {}
|
||||
self.load_surveys()
|
||||
|
||||
def load_surveys(self):
|
||||
"""Load all surveys from the surveys directory with _survey.json suffix."""
|
||||
global allowedSurveys
|
||||
allowedSurveys.clear()
|
||||
try:
|
||||
for filename in os.listdir(self.survey_dir):
|
||||
if filename.endswith('_survey.json'):
|
||||
survey_name = filename[:-12] # Remove '_survey.json'
|
||||
allowedSurveys.append(survey_name)
|
||||
path = os.path.join(self.survey_dir, filename)
|
||||
try:
|
||||
with open(path, encoding='utf-8') as f:
|
||||
self.surveys[survey_name] = json.load(f)
|
||||
except FileNotFoundError:
|
||||
logger.error(f"File not found: {path}")
|
||||
self.surveys[survey_name] = []
|
||||
except json.JSONDecodeError:
|
||||
logger.error(f"Error decoding JSON from file: {path}")
|
||||
self.surveys[survey_name] = []
|
||||
except Exception as e:
|
||||
logger.error(f"Survey: Error loading surveys: {e}")
|
||||
|
||||
def start_survey(self, user_id, survey_name='example', location=None):
|
||||
"""Begin a new survey session for a user."""
|
||||
if not survey_name:
|
||||
survey_name = 'example'
|
||||
if survey_name not in allowedSurveys:
|
||||
return f"error: survey '{survey_name}' is not allowed."
|
||||
self.responses[user_id] = {
|
||||
'survey_name': survey_name,
|
||||
'current_question': 0,
|
||||
'answers': [],
|
||||
'location': location if surveyRecordLocation and location is not None else 'N/A'
|
||||
}
|
||||
msg = f"'{survey_name}'📝survey\nSend answer' or 'end'\n"
|
||||
msg += self.show_question(user_id)
|
||||
return msg
|
||||
|
||||
def show_question(self, user_id):
|
||||
"""Show the current question for the user, or end the survey."""
|
||||
survey_name = self.responses[user_id]['survey_name']
|
||||
current = self.responses[user_id]['current_question']
|
||||
questions = self.surveys.get(survey_name, [])
|
||||
if current >= len(questions):
|
||||
return self.end_survey(user_id)
|
||||
question = questions[current]
|
||||
msg = f"{question['question']}\n"
|
||||
if question.get('type', 'multiple_choice') == 'multiple_choice':
|
||||
for i, option in enumerate(question['options']):
|
||||
msg += f"{chr(65+i)}. {option}\n"
|
||||
elif question['type'] == 'integer':
|
||||
msg += "(Please enter a number)\n"
|
||||
elif question['type'] == 'text':
|
||||
msg += "(Please enter your response)\n"
|
||||
msg = msg.rstrip('\n')
|
||||
return msg
|
||||
|
||||
def save_responses(self, user_id):
|
||||
"""Save user responses to a CSV file."""
|
||||
survey_name = self.responses[user_id]['survey_name']
|
||||
if survey_name not in self.surveys:
|
||||
logger.warning(f"Survey '{survey_name}' not loaded. Responses not saved.")
|
||||
return
|
||||
filename = os.path.join(self.response_dir, f'{survey_name}_responses.csv')
|
||||
try:
|
||||
with open(filename, 'a', encoding='utf-8') as f:
|
||||
row = list(map(str, self.responses[user_id]['answers']))
|
||||
if surveyRecordID:
|
||||
row.insert(0, str(user_id))
|
||||
if surveyRecordLocation:
|
||||
location = self.responses[user_id].get('location')
|
||||
row.insert(1 if surveyRecordID else 0, str(location) if location is not None else "N/A")
|
||||
f.write(','.join(row) + '\n')
|
||||
logger.info(f"Survey: Responses for user {user_id} saved for survey '{survey_name}' to {filename}.")
|
||||
except Exception as e:
|
||||
logger.error(f"Error saving responses to {filename}: {e}")
|
||||
|
||||
def answer(self, user_id, answer, location=None):
|
||||
try:
|
||||
"""Record an answer and return the next question or end message."""
|
||||
if user_id not in self.responses:
|
||||
return self.start_survey(user_id, location=location)
|
||||
question_index = self.responses[user_id]['current_question']
|
||||
survey_name = self.responses[user_id]['survey_name']
|
||||
questions = self.surveys.get(survey_name, [])
|
||||
if question_index < 0 or question_index >= len(questions):
|
||||
return "No current question to answer."
|
||||
question = questions[question_index]
|
||||
qtype = question.get('type', 'multiple_choice')
|
||||
if qtype == 'multiple_choice':
|
||||
answer_char = answer.strip().upper()[:1]
|
||||
if len(answer_char) != 1 or not answer_char.isalpha():
|
||||
return "Please answer with a letter (A, B, C, ...)."
|
||||
option_index = ord(answer_char) - 65
|
||||
if 0 <= option_index < len(question['options']):
|
||||
self.responses[user_id]['answers'].append(str(option_index))
|
||||
self.responses[user_id]['current_question'] += 1
|
||||
return f"Recorded..\n" + self.show_question(user_id)
|
||||
else:
|
||||
print(f"Invalid option index {option_index} for question with {len(question['options'])} options. user entered '{answer}'")
|
||||
return "Invalid answer option. Please try again."
|
||||
elif qtype == 'integer':
|
||||
try:
|
||||
int_answer = int(answer)
|
||||
self.responses[user_id]['answers'].append(str(int_answer))
|
||||
self.responses[user_id]['current_question'] += 1
|
||||
return f"Recorded..\n" + self.show_question(user_id)
|
||||
except ValueError:
|
||||
return "Please enter a valid integer."
|
||||
elif qtype == 'text':
|
||||
self.responses[user_id]['answers'].append(answer.strip())
|
||||
self.responses[user_id]['current_question'] += 1
|
||||
return f"Recorded..\n" + self.show_question(user_id)
|
||||
else:
|
||||
return f"error: unknown question type '{qtype}' and cannot record answer '{answer}'"
|
||||
except Exception as e:
|
||||
logger.error(f"Error recording answer for user {user_id}: {e}")
|
||||
return "An error occurred while recording your answer. Please try again."
|
||||
|
||||
def end_survey(self, user_id):
|
||||
"""End the survey for the user and save responses."""
|
||||
if user_id not in self.responses:
|
||||
return "No active survey session to end."
|
||||
self.save_responses(user_id)
|
||||
self.responses.pop(user_id, None)
|
||||
return "✅ Survey complete. Thank you for your responses!"
|
||||
|
||||
def quiz_report(self, survey_name='example'):
|
||||
"""
|
||||
Generate a quick poll report: counts of each answer per question.
|
||||
Returns a string summary.
|
||||
"""
|
||||
filename = os.path.join(self.response_dir, f'{survey_name}_responses.csv')
|
||||
questions = self.surveys.get(survey_name, [])
|
||||
if not questions:
|
||||
logger.warning(f"No survey found for '{survey_name}'.")
|
||||
return f"No survey found for '{survey_name}'."
|
||||
all_answers = []
|
||||
try:
|
||||
with open(filename, encoding='utf-8') as f:
|
||||
for line in f:
|
||||
parts = line.strip().split(',')
|
||||
if surveyRecordID:
|
||||
answers = [int(x) for x in parts[1:] if x.strip().isdigit()]
|
||||
else:
|
||||
answers = [int(x) for x in parts if x.strip().isdigit()]
|
||||
all_answers.append(answers)
|
||||
except FileNotFoundError:
|
||||
logger.info(f"No responses recorded yet for '{survey_name}'.")
|
||||
return "No responses recorded yet."
|
||||
report = f"📊 Poll Report for '{survey_name}':\n"
|
||||
for q_idx, question in enumerate(questions):
|
||||
counts = Counter(ans[q_idx] for ans in all_answers if len(ans) > q_idx)
|
||||
report += f"\nQ{q_idx+1}: {question['question']}\n"
|
||||
for opt_idx, option in enumerate(question.get('options', [])):
|
||||
count = counts.get(opt_idx, 0)
|
||||
report += f" {chr(65+opt_idx)}. {option}: {count}\n"
|
||||
return report
|
||||
|
||||
# Initialize the survey module
|
||||
survey_module = SurveyModule()
|
||||
|
||||
1080
modules/system.py
1080
modules/system.py
File diff suppressed because it is too large
Load Diff
122
modules/wiki.py
Normal file
122
modules/wiki.py
Normal file
@@ -0,0 +1,122 @@
|
||||
# meshbot wiki module
|
||||
|
||||
from modules.log import *
|
||||
import wikipedia # pip install wikipedia
|
||||
|
||||
# Kiwix support for local wiki
|
||||
if use_kiwix_server:
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import quote
|
||||
from bs4.element import Comment
|
||||
|
||||
# Kiwix helper functions (only loaded if use_kiwix_server is True)
|
||||
if wikipedia_enabled and use_kiwix_server:
|
||||
def tag_visible(element):
|
||||
"""Filter visible text from HTML elements for Kiwix"""
|
||||
if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
|
||||
return False
|
||||
if isinstance(element, Comment):
|
||||
return False
|
||||
return True
|
||||
|
||||
def text_from_html(body):
|
||||
"""Extract visible text from HTML content"""
|
||||
soup = BeautifulSoup(body, 'html.parser')
|
||||
texts = soup.find_all(string=True)
|
||||
visible_texts = filter(tag_visible, texts)
|
||||
return " ".join(t.strip() for t in visible_texts if t.strip())
|
||||
|
||||
def get_kiwix_summary(search_term):
|
||||
"""Query local Kiwix server for Wikipedia article"""
|
||||
try:
|
||||
search_encoded = quote(search_term)
|
||||
# Try direct article access first
|
||||
wiki_article = search_encoded.capitalize().replace("%20", "_")
|
||||
exact_url = f"{kiwix_url}/raw/{kiwix_library_name}/content/A/{wiki_article}"
|
||||
|
||||
response = requests.get(exact_url, timeout=urlTimeoutSeconds)
|
||||
if response.status_code == 200:
|
||||
# Extract and clean text
|
||||
text = text_from_html(response.text)
|
||||
# Remove common Wikipedia metadata prefixes
|
||||
text = text.split("Jump to navigation", 1)[-1]
|
||||
text = text.split("Jump to search", 1)[-1]
|
||||
# Truncate to reasonable length (first few sentences)
|
||||
sentences = text.split('. ')
|
||||
summary = '. '.join(sentences[:wiki_return_limit])
|
||||
if summary and not summary.endswith('.'):
|
||||
summary += '.'
|
||||
return summary.strip()[:500] # Hard limit at 500 chars
|
||||
|
||||
# If direct access fails, try search
|
||||
search_url = f"{kiwix_url}/search?content={kiwix_library_name}&pattern={search_encoded}"
|
||||
response = requests.get(search_url, timeout=urlTimeoutSeconds)
|
||||
|
||||
if response.status_code == 200 and "No results were found" not in response.text:
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
links = [a['href'] for a in soup.find_all('a', href=True) if "start=" not in a['href']]
|
||||
|
||||
for link in links[:3]: # Check first 3 results
|
||||
article_name = link.split("/")[-1]
|
||||
if not article_name or article_name[0].islower():
|
||||
continue
|
||||
|
||||
article_url = f"{kiwix_url}{link}"
|
||||
article_response = requests.get(article_url, timeout=urlTimeoutSeconds)
|
||||
if article_response.status_code == 200:
|
||||
text = text_from_html(article_response.text)
|
||||
text = text.split("Jump to navigation", 1)[-1]
|
||||
text = text.split("Jump to search", 1)[-1]
|
||||
sentences = text.split('. ')
|
||||
summary = '. '.join(sentences[:wiki_return_limit])
|
||||
if summary and not summary.endswith('.'):
|
||||
summary += '.'
|
||||
return summary.strip()[:500]
|
||||
|
||||
logger.warning(f"System: No Kiwix Results for:{search_term}")
|
||||
# try to fall back to online Wikipedia if available
|
||||
return get_wikipedia_summary(search_term, force=True)
|
||||
|
||||
|
||||
except requests.RequestException as e:
|
||||
logger.warning(f"System: Kiwix connection error: {e}")
|
||||
return "Unable to connect to local wiki server"
|
||||
except Exception as e:
|
||||
logger.warning(f"System: Error with Kiwix for:{search_term} {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
def get_wikipedia_summary(search_term, location=None, force=False):
|
||||
lat, lon = location if location else (None, None)
|
||||
# Use Kiwix if configured
|
||||
if use_kiwix_server and not force:
|
||||
return get_kiwix_summary(search_term)
|
||||
|
||||
try:
|
||||
# Otherwise use online Wikipedia
|
||||
wikipedia_search = wikipedia.search(search_term, results=3)
|
||||
wikipedia_suggest = wikipedia.suggest(search_term)
|
||||
#wikipedia_aroundme = wikipedia.geosearch(lat,lon, results=3)
|
||||
#logger.debug(f"System: Wikipedia Nearby:{wikipedia_aroundme}")
|
||||
except Exception as e:
|
||||
logger.debug(f"System: Wikipedia search error for:{search_term} {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
if len(wikipedia_search) == 0:
|
||||
logger.warning(f"System: No Wikipedia Results for:{search_term}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
try:
|
||||
logger.debug(f"System: Searching Wikipedia for:{search_term}, First Result:{wikipedia_search[0]}, Suggest Word:{wikipedia_suggest}")
|
||||
summary = wikipedia.summary(search_term, sentences=wiki_return_limit, auto_suggest=False, redirect=True)
|
||||
except wikipedia.DisambiguationError as e:
|
||||
logger.warning(f"System: Disambiguation Error for:{search_term} trying {wikipedia_search[0]}")
|
||||
summary = wikipedia.summary(wikipedia_search[0], sentences=wiki_return_limit, auto_suggest=True, redirect=True)
|
||||
except wikipedia.PageError as e:
|
||||
logger.warning(f"System: Wikipedia Page Error for:{search_term} {e} trying {wikipedia_search[0]}")
|
||||
summary = wikipedia.summary(wikipedia_search[0], sentences=wiki_return_limit, auto_suggest=True, redirect=True)
|
||||
except Exception as e:
|
||||
logger.warning(f"System: Error with Wikipedia for:{search_term} {e}")
|
||||
return ERROR_FETCHING_DATA
|
||||
|
||||
return summary
|
||||
25
pong_bot.py
25
pong_bot.py
@@ -432,28 +432,29 @@ async def start_rx():
|
||||
logger.info(f"System: Autoresponder Started for Device{i} {get_name_from_number(myNodeNum, 'long', i)},"
|
||||
f"{get_name_from_number(myNodeNum, 'short', i)}. NodeID: {myNodeNum}, {decimal_to_hex(myNodeNum)}")
|
||||
|
||||
if useDMForResponse:
|
||||
logger.debug(f"System: Respond by DM only")
|
||||
if log_messages_to_file:
|
||||
logger.debug("System: Logging Messages to disk")
|
||||
if syslog_to_file:
|
||||
logger.debug("System: Logging System Logs to disk")
|
||||
if solar_conditions_enabled:
|
||||
logger.debug("System: Celestial Telemetry Enabled")
|
||||
if motd_enabled:
|
||||
logger.debug(f"System: MOTD Enabled using {MOTD}")
|
||||
if enableEcho:
|
||||
logger.debug(f"System: Echo command Enabled")
|
||||
if sentry_enabled:
|
||||
logger.debug(f"System: Sentry Mode Enabled {sentry_radius}m radius reporting to channel:{secure_channel}")
|
||||
if store_forward_enabled:
|
||||
logger.debug(f"System: S&F(messages command) Enabled using limit: {storeFlimit}")
|
||||
if useDMForResponse:
|
||||
logger.debug(f"System: Respond by DM only")
|
||||
if highfly_enabled:
|
||||
logger.debug(f"System: HighFly Enabled using {highfly_altitude}m limit reporting to channel:{highfly_channel}")
|
||||
if repeater_enabled and multiple_interface:
|
||||
logger.debug(f"System: Repeater Enabled for Channels: {repeater_channels}")
|
||||
if file_monitor_enabled:
|
||||
logger.debug(f"System: File Monitor Enabled for {file_monitor_file_path}, broadcasting to channels: {file_monitor_broadcastCh}")
|
||||
if read_news_enabled:
|
||||
logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}")
|
||||
if bbs_enabled:
|
||||
logger.debug(f"System: BBS Enabled, {bbsdb} has {len(bbs_messages)} messages. Direct Mail Messages waiting: {(len(bbs_dm) - 1)}")
|
||||
if bbs_link_enabled:
|
||||
if len(bbs_link_whitelist) > 0:
|
||||
logger.debug(f"System: BBS Link Enabled with {len(bbs_link_whitelist)} peers")
|
||||
else:
|
||||
logger.debug(f"System: BBS Link Enabled allowing all")
|
||||
if scheduler_enabled:
|
||||
# Examples of using the scheduler, Times here are in 24hr format
|
||||
# https://schedule.readthedocs.io/en/stable/
|
||||
@@ -481,7 +482,7 @@ async def main():
|
||||
if file_monitor_enabled:
|
||||
tasks.append(asyncio.create_task(handleFileWatcher(), name="file_monitor"))
|
||||
|
||||
logger.info(f"System: Starting {len(tasks)} async tasks")
|
||||
logger.debug(f"System: Starting {len(tasks)} async tasks")
|
||||
|
||||
# Wait for all tasks with proper exception handling
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
@@ -495,7 +496,7 @@ async def main():
|
||||
logger.error(f"Main loop error: {e}")
|
||||
finally:
|
||||
# Cleanup tasks
|
||||
logger.info("System: Cleaning up async tasks")
|
||||
logger.debug("System: Cleaning up async tasks")
|
||||
for task in tasks:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
@@ -3,9 +3,32 @@
|
||||
# meshing-around - helper script
|
||||
import sys
|
||||
import os
|
||||
import pickle
|
||||
import argparse
|
||||
|
||||
favList = []
|
||||
roofNodeList = []
|
||||
roof_node = False
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Add favorite nodes or print pickle contents.")
|
||||
parser.add_argument('-pickle', '-p', action='store_true', help="Print the contents of roofNodeList.pkl and exit")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.pickle:
|
||||
try:
|
||||
with open('roofNodeList.pkl', 'rb') as f:
|
||||
data = pickle.load(f)
|
||||
#print a simple list of nodeID:x\n
|
||||
for item in data:
|
||||
print(f"{item.get('nodeID', 'N/A')}")
|
||||
except Exception as e:
|
||||
print(f"Error reading roofNodeList.pkl: {e}")
|
||||
exit(0)
|
||||
|
||||
# welcome header
|
||||
print("meshing-around: addFav - Auto-Add favorite nodes to all interfaces from config.ini data")
|
||||
print("This script may need API improvments still in progress")
|
||||
print("---------------------------------------------------------------")
|
||||
|
||||
try:
|
||||
@@ -14,23 +37,82 @@ try:
|
||||
from modules.log import *
|
||||
from modules.system import *
|
||||
except Exception as e:
|
||||
print(f"Error importing modules run this program from the main program directory 'python3 script/addFav.py'")
|
||||
print(f"Error importing modules run this program from the main repo directory 'python3 script/addFav.py'")
|
||||
print(f"if you forgot the rest of it.. git clone https://github.com/spudgunman/meshing-around")
|
||||
print(f"Import Error: {e}")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
# compile the favorite list wich returns node,interface tuples
|
||||
favList = compileFavoriteList()
|
||||
logger.debug(f"addFav: Compiled favorite list:\n {favList}")
|
||||
# ask if we are running on a roof node
|
||||
print("This script can be run on a client_base or on the bot under a roof node.")
|
||||
print("The purpose of this script is to add favorite nodes to the bot to retain DM keys.")
|
||||
print("If you are running this script on a roof (base) node, stop and rerun it on the bot first to collect all node ID's.")
|
||||
roof_node = input("Are you running this script on a client_base node which has no BOT? (y/n): ").strip().lower()
|
||||
if roof_node not in ['y', 'n']:
|
||||
raise ValueError("Invalid input. Please enter 'y' or 'n'.")
|
||||
roof_node = (roof_node == 'y')
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
if roof_node:
|
||||
# load roofNodeList from pickle file
|
||||
try:
|
||||
with open('roofNodeList.pkl', 'rb') as f:
|
||||
roofNodeList = pickle.load(f)
|
||||
logger.info(f"addFav: Loaded {len(roofNodeList)} connected nodes from roofNodeList.pkl for use on roof client_base only")
|
||||
print(f"Loaded {len(roofNodeList)} connected nodes from roofNodeList.pkl for use on roof client_base only")
|
||||
except Exception as e:
|
||||
logger.error(f"addFav: Error loading roofNodeList.pkl: {e} - run this program from the main program directory 'python3 script/addFav.py'")
|
||||
exit(1)
|
||||
favList = roofNodeList
|
||||
else:
|
||||
# compile the favorite list wich returns node,interface tuples
|
||||
roofNodeList = compileFavoriteList(True)
|
||||
favList = compileFavoriteList(False)
|
||||
|
||||
#combine favList and roofNodeList to save for next step
|
||||
for node in roofNodeList:
|
||||
if node not in favList:
|
||||
favList.append(node)
|
||||
|
||||
#save roofNodeList to a pickle file for running on the roof node
|
||||
with open('roofNodeList.pkl', 'wb') as f:
|
||||
pickle.dump(roofNodeList, f)
|
||||
logger.info(f"addFav: Saved {len(roofNodeList)} connected nodes to roofNodeList.pkl for use on roof client_base only")
|
||||
print(f"Saved {len(roofNodeList)} connected nodes to roofNodeList.pkl for use on roof client_base only")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"addFav: Error compiling favorite list: {e} - run this program from the main program directory 'python3 script/addFav.py'")
|
||||
exit(1)
|
||||
|
||||
#confirm you want all these added
|
||||
try:
|
||||
if favList:
|
||||
print(f"The following {len(favList)} favorite nodes will be added to the device(s):")
|
||||
count_devices = set([fav['deviceID'] for fav in favList])
|
||||
count_nodes = set([fav['nodeID'] for fav in favList])
|
||||
for fav in favList:
|
||||
print(f"addFav: adding nodeID {fav['nodeID']} meshtastic --set-favorite-node {fav['nodeID']}")
|
||||
confirm = input(f"Are you sure you want to add these {len(count_nodes)} favorite nodes to {len(count_devices)} device(s)? (y/n): ").strip().lower()
|
||||
if confirm != 'y':
|
||||
print("Operation cancelled by user.")
|
||||
exit(0)
|
||||
else:
|
||||
print("No favorite nodes to add to device(s). Exiting.")
|
||||
exit(0)
|
||||
except Exception as e:
|
||||
logger.error(f"addFav: Error during confirmation: {e}")
|
||||
exit(1)
|
||||
|
||||
if favList:
|
||||
# for each node,interface tuple add the favorite node
|
||||
for fav in favList:
|
||||
try:
|
||||
handleFavoritNode(fav['deviceID'], fav['nodeID'], True)
|
||||
time.sleep(1)
|
||||
handleFavoriteNode(fav['deviceID'], fav['nodeID'], True)
|
||||
logger.info(f"addFav: waiting 15 seconds to avoid API rate limits")
|
||||
time.sleep(15) # wait to avoid API rate limits
|
||||
except Exception as e:
|
||||
logger.error(f"addFav: Error adding favorite node {fav['nodeID']} to device {fav['deviceID']}: {e}")
|
||||
else:
|
||||
@@ -40,4 +122,9 @@ else:
|
||||
count_devices = set([fav['deviceID'] for fav in favList])
|
||||
count_nodes = set([fav['nodeID'] for fav in favList])
|
||||
logger.info(f"addFav: Finished adding {len(count_nodes)} favorite nodes to {len(count_devices)} device(s)")
|
||||
logger.info("addFav: You may need to restart the mesh service on the device(s)")
|
||||
print(f"Finished adding {len(count_nodes)} favorite nodes to {len(count_devices)} device(s)")
|
||||
print(f"Data file for roof client_base has been saved to roofNodeList.pkl")
|
||||
if not roof_node:
|
||||
logger.info(f"addFav: You can now run this repo+script & roofNodeList.pkl on the roof node to add the favorite nodes to the roof client_base")
|
||||
exit(0)
|
||||
|
||||
Reference in New Issue
Block a user