diff --git a/config.template b/config.template index 8e8ee45..f83cb4e 100644 --- a/config.template +++ b/config.template @@ -125,6 +125,6 @@ signalCycleLimit = 5 # delay in seconds for response to avoid message collision responseDelay = 0.7 # delay in seconds for splits in messages to avoid message collision -splitDelay = 0.7 +splitDelay = 0.0 # message chunk size for sending at high success rate MESSAGE_CHUNK_SIZE = 160 diff --git a/etc/mesh_bot.tmp b/etc/mesh_bot.tmp index 51877bf..1f62e2e 100644 --- a/etc/mesh_bot.tmp +++ b/etc/mesh_bot.tmp @@ -7,8 +7,12 @@ Description=MESH-BOT After=network.target [Service] +Type=simple +User=pi +Group=pi WorkingDirectory=/dir/ -ExecStart=/usr/bin/bash /dir/launch.sh mesh +ExecStart=python3 mesh_bot.py +ExecStop=pkill -f mesh_bot.py # Disable Python's buffering of STDOUT and STDERR, so that output from the # service shows up immediately in systemd's logs diff --git a/etc/pong_bot.tmp b/etc/pong_bot.tmp index 7415799..1554279 100644 --- a/etc/pong_bot.tmp +++ b/etc/pong_bot.tmp @@ -7,8 +7,12 @@ Description=PONG-BOT After=network.target [Service] +Type=simple +User=pi +Group=pi WorkingDirectory=/dir/ -ExecStart=/usr/bin/bash /dir/launch.sh pong +ExecStart=python3 pong_bot.py +ExecStop=pkill -f pong_bot.py # Disable Python's buffering of STDOUT and STDERR, so that output from the # service shows up immediately in systemd's logs diff --git a/install.sh b/install.sh index e3db460..9e33044 100755 --- a/install.sh +++ b/install.sh @@ -2,8 +2,13 @@ # install.sh cd "$(dirname "$0")" +program_path=$(pwd) +cp etc/pong_bot.tmp etc/pong_bot.service +cp etc/mesh_bot.tmp etc/mesh_bot.service printf "\nMeshing Around Installer\n" +printf "\nThis script will install the Meshing Around bot and its dependencies works best in debian/ubuntu\n" +printf "\nChecking for dependencies\n" # add user to groups for serial access @@ -33,21 +38,12 @@ printf "\nConfig file generated\n" # set virtual environment and install dependencies printf "\nMeshing Around Installer\n" -#check if python3 has venv module -if ! python3 -m venv --help &> /dev/null -then - printf "Python3 venv module not found, please install python3-venv with your OS\n" -else - printf "Python3 venv module found\n" -fi - echo "Do you want to install the bot in a virtual environment? (y/n)" read venv if [ $venv == "y" ]; then # set virtual environment - if ! python3 -m venv --help &> /dev/null - then + if ! python3 -m venv --help &> /dev/null; then printf "Python3 venv module not found, please install python3-venv with your OS\n" exit 1 else @@ -55,13 +51,28 @@ if [ $venv == "y" ]; then python3 -m venv venv source venv/bin/activate - # install dependencies - pip install -U -r requirements.txt + #check if python3 has venv module + if [ -f venv/bin/activate ]; then + printf "\nFpund virtual environment for python\n" + else + sudo apt-get install python3-venv + printf "\nPython3 venv module not found, please install python3-venv with your OS if not already done. re-run the script\n" + exxt 1 + fi + + # config service files for virtual environment + replace="s|python3 mesh_bot.py|/usr/bin/bash launch.sh mesh|g" + sed -i "$replace" etc/mesh_bot.service + replace="s|python3 pong_bot.py|/usr/bin/bash launch.sh pong|g" + sed -i "$replace" etc/pong_bot.service + + # install dependencies + pip install -U -r requirements.txt fi else printf "\nSkipping virtual environment...\n" # install dependencies - printf "Are you on Raspberry Pi?\nshould we add --break-system-packages to the pip install command? (y/n)" + printf "Are you on Raspberry Pi(debian/ubuntu)?\nshould we add --break-system-packages to the pip install command? (y/n)" read rpi if [ $rpi == "y" ]; then pip install -U -r requirements.txt --break-system-packages @@ -74,33 +85,39 @@ printf "\n\n" echo "Which bot do you want to install as a service? Pong Mesh or None? (pong/mesh/n)" read bot -#set the correct path in the service file -program_path=$(pwd) -cp etc/pong_bot.tmp etc/pong_bot.service -cp etc/mesh_bot.tmp etc/mesh_bot.service +# set the correct path in the service file replace="s|/dir/|$program_path/|g" sed -i $replace etc/pong_bot.service sed -i $replace etc/mesh_bot.service +# set the correct user in the service file? +whoami=$(whoami) +replace="s|User=pi|User=$whoami|g" +sed -i $replace etc/pong_bot.service +sed -i $replace etc/mesh_bot.service +replace="s|Group=pi|Group=$whoami|g" +sed -i $replace etc/pong_bot.service +sed -i $replace etc/mesh_bot.service +sudo systemctl daemon-reload printf "\n service files updated\n" # ask if emoji font should be installed for linux -echo "Do you want to install the emoji font for debian linux? (y/n)" +echo "Do you want to install the emoji font for debian/ubuntu linux? (y/n)" read emoji if [ $emoji == "y" ]; then - sudo apt-get install fonts-noto-color-emoji + sudo apt-get install -y fonts-noto-color-emoji echo "Emoji font installed!, reboot to load the font" fi if [ $bot == "pong" ]; then # install service for pong bot sudo cp etc/pong_bot.service /etc/systemd/system/ - exit 0 + sudo systemctl enable pong_bot.service fi if [ $bot == "mesh" ]; then # install service for mesh bot sudo cp etc/mesh_bot.service /etc/systemd/system/ - exit 0 + sudo systemctl enable mesh_bot.service fi if [ $bot == "n" ]; then @@ -124,11 +141,14 @@ if [ $ollama == "y" ]; then echo "Do you want to install the Gemma2:2b components? (y/n)" read gemma if [ $gemma == "y" ]; then - olamma pull gemma2:2b + ollama pull gemma2:2b fi fi +echo "Good time to reboot? (y/n)" +read reboot +if [ $reboot == "y" ]; then + sudo reboot +fi - -printf "\nGoodbye!" exit 0 diff --git a/mesh_bot.py b/mesh_bot.py index 8fbf7a7..35db035 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # Meshtastic Autoresponder MESH Bot # K7MHI Kelly Keeton 2024 @@ -305,8 +305,16 @@ def handle_gTnW(): 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","?SYNTAX return[ERROR 54]"] - return random.choice(response) + "I should reach Defcon 1 and release my missiles in 28 hours.","T-minus thirty","?SYNTAX return[ERROR 54]", "reticulating splines"] + length = len(response) + indices = list(range(length)) + # Shuffle the indices using a convoluted method + for i in range(length): + swap_idx = (i * 3 + 7) % length + indices[i], indices[swap_idx] = indices[swap_idx], indices[i] + # Select a random response from the shuffled list. anyone enjoy the game, killerbunnies(.com) + selected_index = random.choice(indices) + return response[selected_index] def handleLemonade(nodeID, message): global lemonadeTracker, lemonadeCups, lemonadeLemons, lemonadeSugar, lemonadeWeeks, lemonadeScore, lemon_starting_cash, lemon_total_weeks diff --git a/modules/system.py b/modules/system.py index 5af78b6..27b2c88 100644 --- a/modules/system.py +++ b/modules/system.py @@ -45,6 +45,8 @@ if solar_conditions_enabled: from modules.solarconditions import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_solarconditions # items hfcond, solar, sun, moon help_message = help_message + ", sun, hfcond, solar, moon" +else: + hf_band_conditions = False # Command History Configuration if enableCmdHistory: @@ -63,12 +65,16 @@ if location_enabled: else: # NOAA only features help_message = help_message + ", wxa, tide" - + # BBS Configuration if bbs_enabled: from modules.bbstools import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_bbs # items bbslist, bbspost, bbsread, bbsdelete, bbshelp help_message = help_message + ", bbslist, bbshelp" +else: + bbs_help = False + bbs_list_messages = False + # Dad Jokes Configuration if dad_jokes_enabled: @@ -117,7 +123,7 @@ if games_enabled is True: help_message = help_message + ", games" trap_list = trap_list + ("games",) gTnW_enabled = True - gamesCmdList = "Play via DM! CMD: " + gamesCmdList = "Play via DM🕹️ CMD: " if dopewars_enabled: gamesCmdList += "DopeWars, " if lemonade_enabled: