func (self *Connection) PrivmsgIrcHandler(conn *irc.Connection, msg *irc.Message) { serviceMsg := Message{} if !irc.IsChannel(msg.Params[0]) { serviceMsg.Target = msg.Nick } else { serviceMsg.Target = msg.Params[0] } serviceMsg.Command = msg.Command serviceMsg.Mask = msg.Host if irc.IsDirect(msg.Trail, conn.GetCurrentNick()) || !irc.IsChannel(msg.Params[0]) { serviceMsg.Direct = true } else { serviceMsg.Direct = false } serviceMsg.Nick = msg.Nick serviceMsg.Host = msg.Host serviceMsg.Full_message = msg.RawMsg serviceMsg.User = msg.Ident serviceMsg.From_channel = irc.IsChannel(msg.Params[0]) serviceMsg.Connection = conn.Name serviceMsg.Meta = &Meta{"Tenyks", version.TenyksVersion, nil, ""} if serviceMsg.Direct && serviceMsg.From_channel { serviceMsg.Payload = irc.StripNickOnDirect(msg.Trail, conn.GetCurrentNick()) } else { serviceMsg.Payload = msg.Trail } jsonBytes, err := json.Marshal(serviceMsg) if err != nil { log.Fatal(err) } self.Out <- string(jsonBytes[:]) }
func (self *Connection) HelpIrcHandler(conn *irc.Connection, msg *irc.Message) { var trail string if irc.IsDirect(msg.Trail, conn.GetCurrentNick()) { trail = irc.StripNickOnDirect(msg.Trail, conn.GetCurrentNick()) } else { trail = msg.Trail } if strings.HasPrefix(trail, "!help") { trail_pieces := strings.Fields(trail) if len(trail_pieces) > 1 { if self.engine.ServiceRg.IsService(trail_pieces[1]) { service := self.engine.ServiceRg.GetServiceByName(trail_pieces[1]) if service == nil { conn.Out <- msg.GetDMString( fmt.Sprintf("No such service `%s`", trail_pieces[1])) return } serviceMsg := &Message{ Target: msg.Nick, Nick: msg.Nick, Direct: true, From_channel: false, Command: "PRIVMSG", Connection: conn.Name, Payload: fmt.Sprintf("!help %s", service.UUID.String()), } jsonBytes, err := json.Marshal(serviceMsg) if err != nil { log.Error("Cannot marshal help message") return } self.Out <- string(jsonBytes[:]) } else { conn.Out <- msg.GetDMString( fmt.Sprintf("No such service `%s`", trail[1])) } } else { conn.Out <- msg.GetDMString( fmt.Sprintf("%s: !help - This help message", conn.GetCurrentNick())) conn.Out <- msg.GetDMString( fmt.Sprintf("%s: !services - List services", conn.GetCurrentNick())) conn.Out <- msg.GetDMString( fmt.Sprintf("%s: !help <servicename> - Get help for a service", conn.GetCurrentNick())) } } }
func (self *Connection) InfoIrcHandler(conn *irc.Connection, msg *irc.Message) { var trail string if irc.IsDirect(msg.Trail, conn.GetCurrentNick()) { trail = irc.StripNickOnDirect(msg.Trail, conn.GetCurrentNick()) } else { trail = msg.Trail } if strings.HasPrefix(trail, "!info") { var info string for _, info = range version.GetInfo() { conn.Out <- msg.GetDMString(info) } for _, info = range conn.GetInfo() { conn.Out <- msg.GetDMString(info) } } }