-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(giveaway): Use message ID instead of timestamp for button CustomID
- Loading branch information
1 parent
7a7f7a3
commit 8cef92d
Showing
2 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Giveaway struct { | ||
MessageID string `bson:"message_id"` | ||
ChannelID string `bson:"channel_id"` | ||
EndTime time.Time `bson:"end_time"` | ||
WinnersCount int `bson:"winners_count"` | ||
Prize string `bson:"prize"` | ||
Participants []string `bson:"participants"` | ||
Winners []string `bson:"winners"` | ||
Ended bool `bson:"ended"` | ||
} | ||
|
||
func ParseDuration(durationStr string) (time.Duration, error) { | ||
value := durationStr[:len(durationStr)-1] | ||
unit := durationStr[len(durationStr)-1:] | ||
|
||
numeric, err := strconv.Atoi(value) | ||
if err != nil { | ||
return 0, fmt.Errorf("invalid duration format") | ||
} | ||
|
||
switch strings.ToLower(unit) { | ||
case "d": | ||
return time.Duration(numeric) * 24 * time.Hour, nil | ||
case "h": | ||
return time.Duration(numeric) * time.Hour, nil | ||
case "m": | ||
return time.Duration(numeric) * time.Minute, nil | ||
default: | ||
return 0, fmt.Errorf("invalid duration unit") | ||
} | ||
} |