🎮 New Tic-Tac-Toe Game Features: - Compact 3x3 board display using ASCII art - Smart AI opponent with win/block/random strategy - All messages under 200-character meshtastic limit (tested: 10-50 chars) - Player vs Bot gameplay with X (player) vs O (bot) - Win detection for rows, columns, and diagonals - Tie game detection when board is full - Game statistics tracking (games played, won) 🔧 Integration Features: - Follows established game patterns from hangman/hamtest - Added to restrictedCommands (DM-only like other games) - Integrated with game tracker system for memory cleanup - Added configuration option in config.template - Automatic cleanup of stale game sessions 🎯 Game Mechanics: - Players pick positions 1-9 corresponding to board layout - Simple input parsing (extracts first digit from message) - Graceful error handling for invalid moves - 'end' command to quit game - Automatic game cleanup on completion 📊 Message Examples: - New game: 39 chars - Game moves: 50 chars - Win/lose: 40 chars - Invalid move: 23 chars - All well under 200-char limit Tested: Complete game scenarios, AI behavior, message lengths Follows: Existing game implementation patterns and memory management
Modules and Adding stuff
To help with code testing see etc/simulator.py to simulate a bot. I also enjoy meshtasticd(linux-native) in noradio with MQTT server and client to just emulate a mesh.
By following these steps, you can add a new bbs option to the bot.
-
Define the Command Handler: Add a new function in mesh_bot.py to handle the new command. For example, if you want to add a command
newcommand:def handle_newcommand(message, message_from_id, deviceID): return "This is a response from the new command."Additionally you can add a whole new module.py, I recommend doing this if you need to import more stuff, try and wedge it into similar spots if you can. You will need to import the file as well, look further at
modules/system.pyfor more. -
Add the Command to the Auto Response: Update the auto_response function in mesh_bot.py to include the new command:
def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_number, deviceID, isDM): #... "newcommand": lambda: handle_newcommand(message, message_from_id, deviceID), #... -
Update the Trap List and Help: A quick way to do this is to edit the line 16/17 in
modules/system.pyto include the new command:#... trap_list = ("cmd", "cmd?", "newcommand") # default trap list, with the new command added help_message = "Bot CMD?:newcommand, " #...If looking to merge the prefered way would be to update
modules/system.pyAdding this block belowpingwhich ends around line 28:# newcommand Configuration newcommand_enabled = True # settings.py handles the config.ini values; this is a placeholder if newcommand_enabled: trap_list_newcommand = ("newcommand",) trap_list = trap_list + trap_list_newcommand help_message = help_message + ", newcommand" -
Test the New Command: Run MeshBot and test the new command by sending a message with the command
newcommandto ensure it responds correctly.
Running a Shell command
Using the above example and enabling the filemon module, you can make a command which calls a bash file to do things on the system.
def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_number, deviceID, isDM):
#...
"switchON": lambda: call_external_script(message)
This would call the default script located in script/runShell.sh and return its output.