Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c04dc6
commit 2e5dac7
Showing
10 changed files
with
105 additions
and
115 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
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ type Levels struct { | |
Find int | ||
Get int | ||
Search int | ||
External int | ||
} | ||
|
||
var ( | ||
|
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
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,41 +1,34 @@ | ||
package command | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
log "github.com/sirupsen/logrus" | ||
"regexp" | ||
|
||
"github.com/ssalvatori/zbot-telegram-go/db" | ||
"github.com/ssalvatori/zbot-telegram-go/user" | ||
"regexp" | ||
) | ||
|
||
// ForgetCommand definition | ||
type ForgetCommand struct { | ||
Next HandlerCommand | ||
Db db.ZbotDatabase | ||
Levels Levels | ||
Db db.ZbotDatabase | ||
} | ||
|
||
func (handler *ForgetCommand) ProcessText(text string, user user.User) string { | ||
// ProcessText run command | ||
func (handler *ForgetCommand) ProcessText(text string, user user.User) (string, error) { | ||
|
||
commandPattern := regexp.MustCompile(`^!forget\s(\S*)$`) | ||
result := "" | ||
|
||
if commandPattern.MatchString(text) { | ||
if user.IsAllow(handler.Levels.Forget) { | ||
term := commandPattern.FindStringSubmatch(text) | ||
def := db.DefinitionItem{ | ||
Term: term[1], | ||
} | ||
err := handler.Db.Forget(def) | ||
if err != nil { | ||
log.Error(err) | ||
} | ||
return fmt.Sprintf("[%s] deleted", def.Term) | ||
term := commandPattern.FindStringSubmatch(text) | ||
def := db.DefinitionItem{ | ||
Term: term[1], | ||
} | ||
} else { | ||
if handler.Next != nil { | ||
result = handler.Next.ProcessText(text, user) | ||
err := handler.Db.Forget(def) | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("[%s] deleted", def.Term), nil | ||
} | ||
|
||
return result | ||
return "", errors.New("text doesn't match") | ||
} |
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
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