add logic to help resume bot from given indices

This commit is contained in:
Khinshan Khan
2025-04-01 10:24:30 -04:00
parent af937d3e6d
commit d15c9e3491
3 changed files with 28 additions and 0 deletions
+4
View File
@@ -12,3 +12,7 @@ DELETE_CONSPIRACY_DELAY=3s
# Probability of sending a conspiracy message (0.0 to 1.0)
CONSPIRACY_PROBABILITY=0.4
# Optional indices for resuming bot
PRAISE_INDEX=5
CONSPIRACY_INDEX=5
+5
View File
@@ -38,6 +38,11 @@ Create a `.env` file in the root of your project with the following keys:
- `CONSPIRACY_PROBABILITY`: Probability (from 0.0 to 1.0) that a conspiracy message is sent after a praise. Eg, 0.4 =
40% chance.
Optional:
- `PRAISE_INDEX`: Index of the [praises.json](./cmd/bot/praises.json) to start from, useful when resuming bot.
- `CONSPIRACY_INDEX`: Index of the [conspiracies.json](./cmd/bot/conspiracies.json) to start from, useful when resuming
bot.
You can view the [.env-sample](./.env-sample) as an example completed template.
### Install + Run
+19
View File
@@ -154,6 +154,25 @@ func loadEnvConfig() error {
return fmt.Errorf("CONSPIRACY_PROBABILITY: %w", err)
}
// Get values in case of resuming at an index
praiseIndex = 0
if valStr := os.Getenv("PRAISE_INDEX"); valStr != "" {
praiseIndex, err = strconv.Atoi(valStr)
if err != nil {
log.Printf("[!] Warning: %s is not a valid int, using default %d", "PRAISE_INDEX", 0)
praiseIndex = 0
}
}
conspiracyIndex = 0
if valStr := os.Getenv("CONSPIRACY_INDEX"); valStr != "" {
conspiracyIndex, err = strconv.Atoi(valStr)
if err != nil {
log.Printf("[!] Warning: %s is not a valid int, using default %d", "CONSPIRACY_INDEX", 0)
conspiracyIndex = 0
}
}
return nil
}