### Starlark Scripting Examples Source: https://context7.com/fweingartshofer/spongebot/llms.txt Examples of using the Starlark scripting context to manipulate message data and perform bot actions like kicking users. ```python s.Result = s.Message.upper() s.Result = "|".join(s.Message.split(" ")) s.Result = s.Message[::-1] # kickUser(s.GuildId, s.AuthorId, "Automated kick") ``` -------------------------------- ### GET /api/configs Source: https://context7.com/fweingartshofer/spongebot/llms.txt Retrieves all bot configurations. ```APIDOC ## GET /api/configs ### Description Fetches a list of all bot configurations. ### Method GET ### Endpoint /api/configs ### Response #### Success Response (200) - **id** (integer) - Config ID - **word** (string) - Discord Token - **active** (boolean) - Status - **prefix** (string) - Command prefix ``` -------------------------------- ### Spongebot Starlark Scripting Example Source: https://github.com/fweingartshofer/spongebot/blob/master/README.md An example of a Starlark script used for custom bot functionality. This script demonstrates how to access message content and modify the bot's response. ```python s.Result = s.Message.upper() ``` -------------------------------- ### Build Spongebot Go Application Source: https://github.com/fweingartshofer/spongebot/blob/master/README.md Instructions for building the Go application for Spongebot. This involves enabling Go modules and configuring environment variables. ```go go build ``` -------------------------------- ### Configure Spongebot Environment Source: https://github.com/fweingartshofer/spongebot/blob/master/README.md Steps to configure the environment for Spongebot. This includes renaming the sample environment file and providing necessary details like database credentials and Discord bot token. ```bash mv .env.sample .env ``` -------------------------------- ### POST /api/configs Source: https://context7.com/fweingartshofer/spongebot/llms.txt Creates a new bot configuration. ```APIDOC ## POST /api/configs ### Description Creates a new configuration entry for the bot. ### Method POST ### Endpoint /api/configs ### Request Body - **word** (string) - Required - Discord Bot Token. - **prefix** (string) - Required - Command prefix. ### Response #### Success Response (201) - **id** (integer) - ID of the new config. ``` -------------------------------- ### Manage Configurations via REST API Source: https://context7.com/fweingartshofer/spongebot/llms.txt Endpoints to retrieve and create bot configurations, including Discord token management and command prefixes. ```bash curl -X GET http://localhost:8080/api/configs -H "Authorization: Bearer " curl -X POST http://localhost:8080/api/configs -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"word": "NEW_DISCORD_BOT_TOKEN", "prefix": "!"}' ``` -------------------------------- ### Build Spongebot Angular Website Source: https://github.com/fweingartshofer/spongebot/blob/master/README.md Instructions for building the Angular website for Spongebot. This requires adding a host entry and running an npm script that compiles the website and places the output in the 'static' folder. ```bash npm run-script "build go" ``` -------------------------------- ### POST /api/commands/new Source: https://context7.com/fweingartshofer/spongebot/llms.txt Creates a new static or scripted command for the bot. ```APIDOC ## POST /api/commands/new ### Description Creates a new command that the bot will respond to. Commands can be static text responses or dynamic scripts written in Starlark. ### Method POST ### Endpoint /api/commands/new ### Request Body - **regex** (string) - Required - The regular expression to trigger the command. - **description** (string) - Required - A brief description of the command. - **response** (string) - Required - The static response text or the Starlark script code. - **script** (boolean) - Required - Set to true if the response is a Starlark script. ### Request Example { "regex": "^hello", "description": "Greets the user", "response": "Hello there!", "script": false } ### Response #### Success Response (201) - **id** (integer) - The ID of the created command. #### Response Example { "id": 3, "regex": "^hello", "description": "Greets the user", "response": "Hello there!", "script": false } ``` -------------------------------- ### Go Command Model Definition Source: https://context7.com/fweingartshofer/spongebot/llms.txt Defines the structure for a command in Spongebot, including its ID, regex pattern for matching, description, response (which can be a static string or a Starlark script), and a flag indicating if the response is a script. ```go type Command struct { Id int `json:"id"` // Primary key Regex string `json:"regex"` // Regular expression pattern (unique) Description string `json:"description"` // Command description Response string `json:"response"` // Static response or Starlark script Script bool `json:"script"` // True if response is a script } ``` -------------------------------- ### Configure Environment Variables Source: https://context7.com/fweingartshofer/spongebot/llms.txt Defines the required environment variables for the Spongebot system, including database credentials, Discord tokens, and server ports. ```bash DISCORD_TOKEN = YOUR_DISCORD_TOKEN JWT_PASSWORD = A_COOL_PASSWORD POSTGRES_HOST = localhost POSTGRES_PORT = 5432 POSTGRES_USER = postgres POSTGRES_PASSWORD = secretpassword DB_NAME = spongebot PORT_API = 8080 PORT_WEBSITE = 8081 ``` -------------------------------- ### Go Config Model Definition Source: https://context7.com/fweingartshofer/spongebot/llms.txt Defines the configuration structure for the Spongebot, including its ID, Discord bot token, an active status flag, and the command prefix. ```go type Config struct { Id int `json:"id"` // Primary key Token string `json:"word"` // Discord bot token (unique) Active bool `json:"active"` // Whether this config is active Prefix string `json:"prefix"` // Bot command prefix (e.g., "_") } ``` -------------------------------- ### Manage Bot Commands Source: https://context7.com/fweingartshofer/spongebot/llms.txt Endpoints to retrieve and create bot commands. Commands support regex matching and optional Starlark scripting. ```bash curl -X GET http://localhost:8080/api/commands \ -H "Authorization: Bearer " curl -X GET http://localhost:8080/api/commands/1 \ -H "Authorization: Bearer " ``` -------------------------------- ### Create Scripted Commands Source: https://context7.com/fweingartshofer/spongebot/llms.txt API requests to register dynamic commands that execute Starlark code to process user input. ```bash curl -X POST http://localhost:8080/api/commands/new -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"regex": "^echo\\s+.+", "description": "Echoes message in uppercase", "response": "s.Result = s.Message.replace(\"echo \", \"\").upper()", "script": true}' ``` -------------------------------- ### Manage User Accounts Source: https://context7.com/fweingartshofer/spongebot/llms.txt Administrative endpoints for creating, retrieving, and deleting user accounts. Requires a valid admin JWT token. ```bash curl -X POST http://localhost:8080/api/user/new \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "username": "newuser", "password": "securepassword", "admin": false }' curl -X GET http://localhost:8080/api/users \ -H "Authorization: Bearer " curl -X DELETE http://localhost:8080/api/users/2/delete \ -H "Authorization: Bearer " ``` -------------------------------- ### Commands API Source: https://context7.com/fweingartshofer/spongebot/llms.txt Endpoints for managing bot commands, including retrieval and creation. ```APIDOC ## GET /api/commands ### Description Retrieves all registered bot commands. ### Method GET ### Endpoint /api/commands ### Parameters #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - **Array of Command Objects**: Each object contains: - **id** (integer) - The command's ID. - **regex** (string) - The regular expression used to match messages. - **description** (string) - A description of the command. - **response** (string) - The response or script to execute. - **script** (boolean) - Indicates if the response is a script. #### Response Example ```json [ { "id": 1, "regex": "^ping", "description": "Will respond with pong.", "response": "pong", "script": false }, { "id": 2, "regex": "peng", "description": "This will make your message uppercase.", "response": "s.Result = s.Message.upper()", "script": true } ] ``` ## GET /api/commands/:id ### Description Retrieves a specific command by its ID. ### Method GET ### Endpoint /api/commands/:id ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the command to retrieve. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - **id** (integer) - The command's ID. - **regex** (string) - The regular expression used to match messages. - **description** (string) - A description of the command. - **response** (string) - The response or script to execute. - **script** (boolean) - Indicates if the response is a script. #### Response Example ```json { "id": 1, "regex": "^ping", "description": "Will respond with pong.", "response": "pong", "script": false } ``` #### Error Response (404 Not Found) - **message** (string) - "not found" ## POST /api/commands ### Description Creates a new bot command. Commands use regular expressions for matching messages. ### Method POST ### Endpoint /api/commands ### Parameters #### Request Body - **regex** (string) - Required - The regular expression to match messages. - **description** (string) - Optional - A description for the command. - **response** (string) - Required - The response or script to execute. - **script** (boolean) - Required - Whether the response is a script. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Request Example ```json { "regex": "^hello", "description": "Greets the user.", "response": "Hello there!", "script": false } ``` ### Response #### Success Response (201 Created) - **id** (integer) - The ID of the newly created command. - **regex** (string) - The regular expression used to match messages. - **description** (string) - A description of the command. - **response** (string) - The response or script to execute. - **script** (boolean) - Indicates if the response is a script. #### Response Example ```json { "id": 3, "regex": "^hello", "description": "Greets the user.", "response": "Hello there!", "script": false } ``` ``` -------------------------------- ### Authentication API Source: https://context7.com/fweingartshofer/spongebot/llms.txt Endpoints for user authentication, account creation, and password updates. ```APIDOC ## POST /api/user/login ### Description Authenticates a user and returns a JWT token for subsequent API calls. The token expires after 4 hours. ### Method POST ### Endpoint /api/user/login ### Parameters #### Request Body - **username** (string) - Required - The username for login. - **password** (string) - Required - The password for login. ### Request Example ```json { "username": "sponge", "password": "bot" } ``` ### Response #### Success Response (200 OK) - **id** (integer) - The user's ID. - **username** (string) - The username. - **admin** (boolean) - Indicates if the user is an administrator. - **token** (string) - The JWT token for authentication. #### Response Example ```json { "id": 1, "username": "sponge", "admin": true, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." } ``` #### Error Response (403 Forbidden) - **message** (string) - "Invalid login credentials. Please try again" ## POST /api/user/new ### Description Creates a new user account. Requires admin privileges. Password is automatically hashed with bcrypt. ### Method POST ### Endpoint /api/user/new ### Parameters #### Request Body - **username** (string) - Required - The username for the new account. - **password** (string) - Required - The password for the new account. - **admin** (boolean) - Optional - Whether the new user should have admin privileges. ### Request Example ```json { "username": "newuser", "password": "securepassword", "admin": false } ``` ### Response #### Success Response (201 Created) - **id** (integer) - The new user's ID. - **username** (string) - The username. - **admin** (boolean) - Indicates if the user is an administrator. #### Response Example ```json { "id": 2, "username": "newuser", "admin": false } ``` ## PUT /api/user/update ### Description Updates the password for the currently authenticated user. ### Method PUT ### Endpoint /api/user/update ### Parameters #### Request Body - **password** (string) - Required - The new password for the user. ### Request Example ```json { "password": "newpassword123" } ``` ### Response #### Success Response (204 No Content) No content is returned on successful update. ``` -------------------------------- ### Go Account Model Definition Source: https://context7.com/fweingartshofer/spongebot/llms.txt Defines the structure for user accounts in Spongebot, including ID, username, bcrypt-hashed password, admin privileges flag, and a JWT token for API authentication (returned only in responses). ```go type Account struct { Id int `json:"id,omitempty"` // Primary key Username string `json:"username,omitempty"` // Unique username Password string `json:"password,omitempty"` // Bcrypt hashed password Admin bool `json:"admin,omitempty"` // Admin privileges flag Token string `json:"token,omitempty"` // JWT token (response only) } ``` -------------------------------- ### Authenticate User via API Source: https://context7.com/fweingartshofer/spongebot/llms.txt Authenticates a user with credentials to receive a JWT token. The token is required for subsequent authorized API requests. ```bash curl -X POST http://localhost:8080/api/user/login \ -H "Content-Type: application/json" \ -d '{ "username": "sponge", "password": "bot" }' ``` -------------------------------- ### Manage Commands via REST API Source: https://context7.com/fweingartshofer/spongebot/llms.txt Operations to create, update, and delete bot commands. These endpoints require a Bearer token for authentication and accept JSON payloads. ```bash curl -X POST http://localhost:8080/api/commands/new -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"regex": "^hello", "description": "Greets the user", "response": "Hello there!", "script": false}' curl -X PUT http://localhost:8080/api/commands/1/update -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"regex": "^ping$", "description": "Will respond with pong.", "response": "pong!", "script": false}' curl -X DELETE http://localhost:8080/api/commands/3/delete -H "Authorization: Bearer " ``` -------------------------------- ### User Management API (Admin Only) Source: https://context7.com/fweingartshofer/spongebot/llms.txt Endpoints for managing user accounts, including retrieval and deletion. ```APIDOC ## GET /api/users ### Description Retrieves all user accounts. Requires admin privileges. ### Method GET ### Endpoint /api/users ### Parameters #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - **Array of User Objects**: Each object contains: - **id** (integer) - The user's ID. - **username** (string) - The username. - **admin** (boolean) - Indicates if the user is an administrator. #### Response Example ```json [ {"id": 1, "username": "sponge", "admin": true}, {"id": 2, "username": "moderator", "admin": false} ] ``` ## GET /api/users/username/:username ### Description Retrieves a specific user by their username. Requires admin privileges. ### Method GET ### Endpoint /api/users/username/:username ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user to retrieve. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - **id** (integer) - The user's ID. - **username** (string) - The username. - **admin** (boolean) - Indicates if the user is an administrator. #### Response Example ```json { "id": 1, "username": "sponge", "admin": true } ``` ## DELETE /api/users/:id/delete ### Description Deletes a user account by ID. Requires admin privileges. ### Method DELETE ### Endpoint /api/users/:id/delete ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the user to delete. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (204 No Content) No content is returned on successful deletion. ``` -------------------------------- ### PUT /api/commands/{id}/update Source: https://context7.com/fweingartshofer/spongebot/llms.txt Updates an existing command by its ID. ```APIDOC ## PUT /api/commands/{id}/update ### Description Updates the details of an existing command identified by its ID. ### Method PUT ### Endpoint /api/commands/{id}/update ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the command to update. ### Request Body - **regex** (string) - Optional - New regex pattern. - **description** (string) - Optional - New description. - **response** (string) - Optional - New response or script. - **script** (boolean) - Optional - Update script status. ### Response #### Success Response (204) - No content returned. ``` -------------------------------- ### Update Command Source: https://github.com/fweingartshofer/spongebot/blob/master/website/src/app/command-detail/command-detail.component.html Updates an existing command in Spongebot. Requires the command ID and new details. ```APIDOC ## PUT /fweingartshofer/spongebot/commands/{id} ### Description Updates an existing command identified by its ID. This endpoint allows modification of the command's regular expression, response, and description. ### Method PUT ### Endpoint /fweingartshofer/spongebot/commands/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the command to update. #### Request Body - **regularExpression** (string) - Required - The new regular expression for the command. - **response** (string) - Required - The new response for the command. - **description** (string) - Required - A new description for the command. ### Request Example ```json { "regularExpression": "^new pattern$", "response": "This is the updated response.", "description": "An updated description for the command." } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the command was updated successfully. #### Response Example ```json { "message": "Command updated successfully." } ``` #### Error Response (400) - **error** (string) - A message describing the error, e.g., "Invalid input data." #### Error Response Example ```json { "error": "Command ID not found." } ``` ``` -------------------------------- ### DELETE /api/commands/{id}/delete Source: https://context7.com/fweingartshofer/spongebot/llms.txt Deletes a command by its ID. ```APIDOC ## DELETE /api/commands/{id}/delete ### Description Removes a command from the system. ### Method DELETE ### Endpoint /api/commands/{id}/delete ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the command to delete. ### Response #### Success Response (204) - No content returned. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.