Convert to lowercase when checking prefix
Return flat modifier in dice roll Use log.Print instead of log.Fatal where makes sense
This commit is contained in:
parent
8776953b54
commit
5cf90653bf
@ -33,7 +33,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
messageContent := strings.Split(m.Content, " ")
|
||||
if !strings.HasPrefix(messageContent[0], prefix) {
|
||||
if !strings.HasPrefix(strings.ToLower(messageContent[0]), prefix) {
|
||||
return
|
||||
}
|
||||
messageContent[0] = messageContent[0][len(prefix):]
|
||||
@ -49,7 +49,7 @@ func init() {
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Error sending message: %v", err)
|
||||
log.Printf("Error sending message: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ var (
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Error responding to interaction: %s\n", err)
|
||||
log.Printf("Error responding to interaction: %s\n", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -67,7 +67,7 @@ func roll(opts optionMap) string {
|
||||
if err != nil {
|
||||
return "Error rolling dice: " + err.Error()
|
||||
}
|
||||
roll, err := d.Roll()
|
||||
roll, flat, err := d.Roll()
|
||||
if err != nil {
|
||||
ret := fmt.Sprintf("Error rolling dice: %s", err)
|
||||
fmt.Println(ret)
|
||||
@ -78,7 +78,7 @@ func roll(opts optionMap) string {
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Error rolling dice: %s", err)
|
||||
}
|
||||
total := d.Add
|
||||
total := flat
|
||||
for i, die := range roll {
|
||||
_, err = fmt.Fprintf(&ret, "%v", die.Result)
|
||||
if err != nil {
|
||||
|
||||
10
dice/dice.go
10
dice/dice.go
@ -22,14 +22,14 @@ type DieResult struct {
|
||||
Result int
|
||||
}
|
||||
|
||||
func (d DieExp) Roll() ([]DieResult, error) {
|
||||
func (d DieExp) Roll() ([]DieResult, int, error) {
|
||||
results := make([]DieResult, 0)
|
||||
var err error
|
||||
|
||||
for i := 0; i < d.Count; i++ {
|
||||
results, err = addDice(d, results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (d DieExp) Roll() ([]DieResult, error) {
|
||||
}
|
||||
|
||||
if d.KeepLow > len(results) {
|
||||
return results, errors.New("keep low higher than remaining results")
|
||||
return nil, 0, errors.New("keep low higher than remaining results")
|
||||
}
|
||||
|
||||
if d.KeepLow != 0 {
|
||||
@ -84,7 +84,7 @@ func (d DieExp) Roll() ([]DieResult, error) {
|
||||
alreadyRolled := len(results)
|
||||
results, err = addDice(d, results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
for _, result := range results[alreadyRolled:] {
|
||||
if result.Result == result.Size {
|
||||
@ -93,7 +93,7 @@ func (d DieExp) Roll() ([]DieResult, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
return results, d.Add, nil
|
||||
}
|
||||
|
||||
func CreateFromExp(exp string) (DieExp, error) {
|
||||
|
||||
@ -78,7 +78,7 @@ func TestDieExp_roll(t *testing.T) {
|
||||
KeepLow: tt.fields.KeepLow,
|
||||
Explode: tt.fields.Explode,
|
||||
}
|
||||
got, err := d.Roll()
|
||||
got, _, err := d.Roll()
|
||||
total := 0
|
||||
for _, v := range got {
|
||||
total += v.Result
|
||||
@ -102,7 +102,7 @@ func TestDieExp_roll_keep_high(t *testing.T) {
|
||||
KeepLow: 0,
|
||||
Explode: false,
|
||||
}
|
||||
got, err := d.Roll()
|
||||
got, _, err := d.Roll()
|
||||
if err != nil {
|
||||
t.Errorf("roll() error = %v", err)
|
||||
return
|
||||
@ -120,7 +120,7 @@ func TestDieExp_roll_keep_low(t *testing.T) {
|
||||
KeepLow: 2,
|
||||
Explode: false,
|
||||
}
|
||||
got, err := d.Roll()
|
||||
got, _, err := d.Roll()
|
||||
if err != nil {
|
||||
t.Errorf("roll() error = %v", err)
|
||||
return
|
||||
@ -138,7 +138,7 @@ func TestDieExp_roll_keep_high_low(t *testing.T) {
|
||||
KeepLow: 2,
|
||||
Explode: false,
|
||||
}
|
||||
got, err := d.Roll()
|
||||
got, _, err := d.Roll()
|
||||
if err != nil {
|
||||
t.Errorf("roll() error = %v", err)
|
||||
return
|
||||
@ -156,7 +156,7 @@ func TestDieExp_roll_keep_low_too_high(t *testing.T) {
|
||||
KeepLow: 5,
|
||||
Explode: false,
|
||||
}
|
||||
_, err := d.Roll()
|
||||
_, _, err := d.Roll()
|
||||
if err == nil {
|
||||
t.Errorf("expected roll error, got nil")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user