mirror of
https://github.com/the-programmers-hangout/swiftspiracy-bot.git
synced 2026-09-04 09:16:01 +02:00
add logic to help resume bot from given indices
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user