Permalink
Browse files

Simplify command parsing. Recovery fixes.

  • Loading branch information...
1 parent cdcdb73 commit 95eb2e29f26aee1a1bcf3634652f8c69bf656d20 @iopred committed Dec 28, 2016
@@ -146,6 +146,8 @@ func (p *comicPlugin) makeComic(bot *bruxism.Bot, service bruxism.Service, messa
// Message handler.
func (p *comicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
+ defer bruxism.MessageRecover()
+
if service.IsMe(message) {
return
}
View
@@ -57,16 +57,11 @@ func ParseCommandString(service Service, message string) (string, []string) {
if strings.HasPrefix(lowerMessage, lowerPrefix) {
message = message[len(lowerPrefix):]
}
- message = strings.TrimSpace(message)
+ rest := strings.Fields(message)
- parts := strings.Split(message, " ")
- if len(parts) > 1 {
- rest := parts[1:]
- query := strings.Join(rest, " ")
- for i, v := range rest {
- rest[i] = strings.TrimSpace(v)
- }
- return query, rest
+ if len(rest) > 1 {
+ rest = rest[1:]
+ return strings.Join(rest, " "), rest
}
return "", []string{}
}
@@ -153,6 +153,8 @@ func (p *ReminderPlugin) AddReminder(reminder *Reminder) error {
}
func (p *ReminderPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
+ defer bruxism.MessageRecover()
+
if !service.IsMe(message) {
if bruxism.MatchesCommand(service, "remind", message) || bruxism.MatchesCommand(service, "reminder", message) {
_, parts := bruxism.ParseCommand(service, message)
@@ -88,6 +88,7 @@ func (p *wormholePlugin) Help(bot *bruxism.Bot, service bruxism.Service, message
// Message handler.
func (p *wormholePlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
defer bruxism.MessageRecover()
+
if !service.IsMe(message) {
messageChannel := message.Channel()
@@ -110,6 +111,7 @@ func (p *wormholePlugin) Message(bot *bruxism.Bot, service bruxism.Service, mess
if len(parts) == 0 {
service.SendMessage(messageChannel, fmt.Sprintf("Incorrect command. eg: %s%swormhole send Hello!%s", ticks, service.CommandPrefix(), ticks))
+ return
}
isAuthorized := service.IsModerator(message)
@@ -27,6 +27,8 @@ func (p *YouTubeJoinPlugin) Help(bot *bruxism.Bot, service bruxism.Service, mess
// Message handler.
func (p *YouTubeJoinPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
+ defer bruxism.MessageRecover()
+
if (service.IsBotOwner(message) || service.IsChannelOwner(message)) && bruxism.MatchesCommand(service, "leave", message) {
video, ok := p.youtube.VideoIDForChatID(message.Channel())
if ok {

0 comments on commit 95eb2e2

Please sign in to comment.