Пример #1
0
func (self *Brain) registerDefaultAbilities() {
	self.Respond("ping", func(msg *TextMessage) {
		msg.Send("Pong!")
	})

	self.Respond("(image|img) (.*)", func(msg *TextMessage) {
		result, err := google.ImageSearch(msg.Matches()[3])

		if err != nil {
			log.Print(err)
			return
		}

		if result == "" {
			msg.Send("I didn't find anything.")
			return
		}

		msg.Send(result)
	})

	self.Respond("(list|show) users", func(msg *TextMessage) {
		list := ""
		for _, user := range self.users {
			list += user.Name + "\n"
		}

		msg.Paste(list)
	})
}
Пример #2
0
func (self *Robot) registerDefaultAbilities() {
	self.Respond("ping", func(msg *TextMessage) {
		msg.Send("Pong!")
	})

	self.Respond("(image|img) (.*)", func(msg *TextMessage) {
		result, err := google.ImageSearch(msg.Matches()[3])

		if err != nil {
			log.Print(err)
			return
		}

		if result == "" {
			msg.Send("I didn't find anything.")
			return
		}

		msg.Send(result)
	})
}