Ejemplo n.º 1
0
func PrivacyFilterIrcmsg(message *irc.Message) *irc.Message {
	if message == nil {
		return nil
	}
	if message.Command == irc.PRIVMSG || message.Command == irc.NOTICE {
		message.Trailing = "<privacy filtered>"
	}
	if message.Command == irc.PASS {
		message.Params = []string{"<privacy filtered>"}
		message.Trailing = ""
	}
	return message
}
Ejemplo n.º 2
0
// CmdPing is a handler for the /PING command.
func CmdPing(s Server, u *User, msg *irc.Message) error {
	if len(msg.Params) > 0 {
		msg.Trailing = msg.Params[0]
	}
	s.EncodeMessage(u, irc.PONG, []string{s.Name()}, msg.Trailing)
	return nil
}
Ejemplo n.º 3
0
// CmdPrivMsg is a handler for the /PRIVMSG command.
func CmdPrivMsg(s Server, u *User, msg *irc.Message) error {
	var err error
	if len(msg.Params) > 1 {
		tr := strings.Join(msg.Params[1:], " ")
		msg.Trailing = msg.Trailing + tr
	}
	// empty message
	if msg.Trailing == "" {
		return nil
	}
	query := msg.Params[0]
	if ch, exists := s.HasChannel(query); exists {
		//p := strings.Replace(query, "#", "", -1)
		msg.Trailing = strings.Replace(msg.Trailing, "\r", "", -1)
		// fix non-rfc clients
		if !strings.HasPrefix(msg.Trailing, ":") {
			if len(msg.Params) == 2 {
				msg.Trailing = msg.Params[1]
			}
		}
		// CTCP ACTION (/me)
		if strings.HasPrefix(msg.Trailing, "\x01ACTION ") {
			msg.Trailing = strings.Replace(msg.Trailing, "\x01ACTION ", "", -1)
			msg.Trailing = "*" + msg.Trailing + "*"
		}
		msg.Trailing += " ​"
		post := &model.Post{ChannelId: ch.ID(), Message: msg.Trailing}
		_, err := u.mc.Client.CreatePost(post)
		if err != nil {
			u.MsgSpoofUser("mattermost", "msg: "+msg.Trailing+" could not be send: "+err.Error())
		}
	} else if toUser, exists := s.HasUser(query); exists {
		if query == "mattermost" {
			go u.handleMMServiceBot(toUser, msg.Trailing)
			return nil
		}
		if toUser.MmGhostUser {
			u.mc.SendDirectMessage(toUser.User, msg.Trailing)
			return nil
		}
		err = s.EncodeMessage(u, irc.PRIVMSG, []string{toUser.Nick}, msg.Trailing)
	} else {
		err = s.EncodeMessage(u, irc.ERR_NOSUCHNICK, msg.Params, "No such nick/channel")
	}
	return err
}
Ejemplo n.º 4
0
func (h *HandlerFuncs) HandlePirvMsg(m *irc.Message) (err error) {

	// Print Private messagess
	log.Printf("%s: %s %s %s\n", h.Name, m.Command, m.Prefix.Name, m.Trailing)

	// Check for portal reference
	if val, ok := responses.Portal[m.Trailing]; ok {

		err = h.ClientConn.PrivMsg(m.Params[0], val)
		if err != nil {

			log.Printf("ircutil.PrivMsg(): %s\n", err)
			return
		}

		return
	}

	// Check for DDG query
	if strings.HasPrefix(m.Trailing, "!ddg") {

		m.Trailing = strings.TrimPrefix(m.Trailing, "!ddg")
		if m.Trailing == "" {

			err = h.ClientConn.PrivMsg(m.Params[0], fmt.Sprintf("%s: %s", m.Prefix.Name, "No Query Specified"))
			if err != nil {

				log.Printf("ircutil.PrivMsg(): %s\n", err)
				return err
			}
			return
		}

		q := &ddg.Client{

			Dial:   h.Dial,
			NoHTML: true,
		}
		_, text, err := q.FeelingLucky(m.Trailing)
		if err != nil {

			log.Printf("ddg.FeelingLucky(): %s\n", err)
		}
		if len(text) < 1 {

			text = "No Results"
		}

		err = h.ClientConn.PrivMsg(m.Params[0], fmt.Sprintf("%s: %s", m.Prefix.Name, text))
		if err != nil {

			log.Printf("ircutil.PrivMsg(): %s\n", err)
			return err
		}
	}

	// Check if message contains URL
	if crawler.IsURL(m.Trailing) {

		if strings.HasPrefix(m.Trailing, "dontcrawl") {

			return
		}

		c := &crawler.Client{
			Dial: h.Dial,
		}
		r, err := c.Crawl(crawler.ExtractUrl(m.Trailing))
		if err != nil {

			log.Printf("crawler.GetTitle(): %s\n", err)
			return nil
		}
		if len(r.Title) > 1 {

			err = h.ClientConn.PrivMsg(m.Params[0], fmt.Sprintf("^ %s", r.Title))
			if err != nil {

				log.Printf("ircutil.PrivMsg(): %s\n", err)
				return err
			}
		}
	}

	return
}