A few updates, cleanup updated weather module.
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
| #!/usr/bin/env bash | ||||
| [ -f functions.sh ] && source functions.sh | ||||
|  | ||||
| roll_dice() { | ||||
| @@ -30,8 +31,32 @@ roll_dice() { | ||||
| } | ||||
|  | ||||
| rollString="${3##* }" | ||||
| if ! [[ "$rollString" =~ ^[1-9][0-9]*[dD][1-9][0-9]*$ ]]; then | ||||
|     msg "$2" "${1}: Usage is roll #d# where # is greater than 0." | ||||
|     else | ||||
|     msg "$2" "$(roll_dice ${rollString})" | ||||
|  | ||||
| # Validate roll string is provided | ||||
| if [[ -z "$rollString" ]]; then | ||||
|     msg "$2" "${1}: Usage is roll #d# (e.g., 2d6, 1d20)" | ||||
|     exit 0 | ||||
| fi | ||||
|  | ||||
| # Validate roll string format | ||||
| if ! [[ "$rollString" =~ ^[1-9][0-9]*[dD][1-9][0-9]*$ ]]; then | ||||
|     msg "$2" "${1}: Invalid format. Usage: roll #d# where # is greater than 0 (e.g., 2d6, 1d20)" | ||||
|     exit 0 | ||||
| fi | ||||
|  | ||||
| # Extract count and sides for validation | ||||
| count=${rollString%[dD]*} | ||||
| sides=${rollString#*[dD]} | ||||
|  | ||||
| # Validate reasonable limits to prevent abuse | ||||
| if [[ $count -gt 1000 ]]; then | ||||
|     msg "$2" "${1}: Maximum 1000 dice per roll." | ||||
|     exit 0 | ||||
| fi | ||||
|  | ||||
| if [[ $sides -gt 1000 ]]; then | ||||
|     msg "$2" "${1}: Maximum 1000 sides per die." | ||||
|     exit 0 | ||||
| fi | ||||
|  | ||||
| msg "$2" "$(roll_dice ${rollString})" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user