[BUGFIX] do not crash on invalid input
This commit is contained in:
parent
1a129edd21
commit
2155f245b7
|
@ -34,10 +34,18 @@ func (b *Bot) addSend(answer func(string), from string, params []string) {
|
||||||
if h == nil {
|
if h == nil {
|
||||||
h = b.db.NewHost(host)
|
h = b.db.NewHost(host)
|
||||||
}
|
}
|
||||||
|
if h == nil {
|
||||||
|
answer(fmt.Sprintf("could not create host %s", host))
|
||||||
|
return
|
||||||
|
}
|
||||||
n, ok := b.db.NotifiesByAddress[to]
|
n, ok := b.db.NotifiesByAddress[to]
|
||||||
if !ok {
|
if !ok {
|
||||||
n = b.db.NewNotify(to)
|
n = b.db.NewNotify(to)
|
||||||
}
|
}
|
||||||
|
if n == nil {
|
||||||
|
answer(fmt.Sprintf("could not create notify %s in list of %s", to, host))
|
||||||
|
return
|
||||||
|
}
|
||||||
h.AddNotify(n)
|
h.AddNotify(n)
|
||||||
|
|
||||||
answer(fmt.Sprintf("added %s in list of %s", to, host))
|
answer(fmt.Sprintf("added %s in list of %s", to, host))
|
||||||
|
|
|
@ -86,6 +86,9 @@ func (db *DB) AddNotify(n *Notify) {
|
||||||
|
|
||||||
func (db *DB) NewNotify(to string) *Notify {
|
func (db *DB) NewNotify(to string) *Notify {
|
||||||
addr := strings.Split(to, ":")
|
addr := strings.Split(to, ":")
|
||||||
|
if len(addr) != 2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
n := &Notify{
|
n := &Notify{
|
||||||
Protocol: addr[0],
|
Protocol: addr[0],
|
||||||
To: addr[1],
|
To: addr[1],
|
||||||
|
|
Loading…
Reference in New Issue