hid: add support for customized replies
This commit is contained in:
		
							
								
								
									
										46
									
								
								hid/main.go
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								hid/main.go
									
									
									
									
									
								
							@@ -1081,8 +1081,10 @@ func (c *client) setPingTimer() {
 | 
			
		||||
 | 
			
		||||
func (c *client) makeReply(id int, ap ...interface{}) string {
 | 
			
		||||
	s := fmt.Sprintf(":%s %03d %s ", serverName, id, c.nicknameOrStar())
 | 
			
		||||
	a := fmt.Sprintf(defaultReplies[id], ap...)
 | 
			
		||||
	return s + a
 | 
			
		||||
	if reply, ok := catalog[id]; ok {
 | 
			
		||||
		return s + fmt.Sprintf(reply, ap...)
 | 
			
		||||
	}
 | 
			
		||||
	return s + fmt.Sprintf(defaultReplies[id], ap...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// XXX: This way simple static analysis cannot typecheck the arguments, so we
 | 
			
		||||
@@ -3150,9 +3152,43 @@ func ircInitializeTLS() error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ircInitializeCatalog() error {
 | 
			
		||||
	// TODO: Not going to use catgets but a simple text file with basic
 | 
			
		||||
	// checking whether the index is used by this daemon at all should do.
 | 
			
		||||
	return nil
 | 
			
		||||
	configCatalog := config["catalog"]
 | 
			
		||||
	if configCatalog == "" {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	path := resolveFilename(configCatalog, resolveRelativeConfigFilename)
 | 
			
		||||
	if path == "" {
 | 
			
		||||
		return fmt.Errorf("cannot find file: %s", configCatalog)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	f, err := os.Open(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed reading the MOTD file: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
	defer f.Close()
 | 
			
		||||
 | 
			
		||||
	scanner := bufio.NewScanner(f)
 | 
			
		||||
	catalog = make(map[int]string)
 | 
			
		||||
	for lineNo := 1; scanner.Scan(); lineNo++ {
 | 
			
		||||
		line := strings.TrimLeft(scanner.Text(), " \t")
 | 
			
		||||
		if line == "" || strings.HasPrefix(line, "#") {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		delim := strings.IndexAny(line, " \t")
 | 
			
		||||
		if delim < 0 {
 | 
			
		||||
			return fmt.Errorf("%s:%d: malformed line", path, lineNo)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		id, err := strconv.ParseUint(line[:delim], 10, 16)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("%s:%d: %s", path, lineNo, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		catalog[int(id)] = line[delim+1:]
 | 
			
		||||
	}
 | 
			
		||||
	return scanner.Err()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ircInitializeMOTD() error {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user