optimize: 在查找到Server对象后移除ServerID标识符
This commit is contained in:
		
							parent
							
								
									f6a5362a97
								
							
						
					
					
						commit
						b5b521e8cf
					
				@ -84,7 +84,7 @@ func CronTrigger(cr model.Cron) func() {
 | 
				
			|||||||
					Type: model.TaskTypeCommand,
 | 
										Type: model.TaskTypeCommand,
 | 
				
			||||||
				})
 | 
									})
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				SendNotification(cr.NotificationTag, fmt.Sprintf("[任务失败] %s,服务器 %s 离线,无法执行。", cr.Name, s.Name), false)
 | 
									SendNotification(cr.NotificationTag, fmt.Sprintf("$%d$[任务失败] %s,服务器 %s 离线,无法执行。", s.ID, cr.Name, s.Name), false)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -145,7 +146,7 @@ func SendNotification(notificationTag string, desc string, mutable bool) {
 | 
				
			|||||||
		log.Println("尝试通知", n.Name)
 | 
							log.Println("尝试通知", n.Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, n := range NotificationList[notificationTag] {
 | 
						for _, n := range NotificationList[notificationTag] {
 | 
				
			||||||
		server := findServerInMsg(desc)
 | 
							desc, server := findServerInMsg(desc)
 | 
				
			||||||
		ns := model.NotificationServerBundle{
 | 
							ns := model.NotificationServerBundle{
 | 
				
			||||||
			Notification: n,
 | 
								Notification: n,
 | 
				
			||||||
			Server:       server,
 | 
								Server:       server,
 | 
				
			||||||
@ -158,11 +159,15 @@ func SendNotification(notificationTag string, desc string, mutable bool) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// findServerInMsg 通过msg字符串中的$ServerID$ 返回Server对象 未找到会返回nil
 | 
					// findServerInMsg 通过msg字符串中的$ServerID$ 返回修改后的字符串与Server对象
 | 
				
			||||||
func findServerInMsg(msg string) *model.Server {
 | 
					func findServerInMsg(msg string) (string, *model.Server) {
 | 
				
			||||||
	reg1 := regexp.MustCompile(`^\$\d+`)
 | 
						reg1 := regexp.MustCompile(`^\$\d+`)
 | 
				
			||||||
	reg2 := regexp.MustCompile(`[^$]+`)
 | 
						reg2 := regexp.MustCompile(`[^$]+`)
 | 
				
			||||||
	ServerIDStr := reg2.FindString(reg1.FindString(msg))
 | 
						ServerIDStr := reg2.FindString(reg1.FindString(msg))
 | 
				
			||||||
	ServerID, _ := strconv.ParseUint(ServerIDStr, 10, 64)
 | 
						ServerID, _ := strconv.ParseUint(ServerIDStr, 10, 64)
 | 
				
			||||||
	return ServerList[ServerID]
 | 
						// 将原字符串的ServerID标识去除
 | 
				
			||||||
 | 
						if ServerIDStr != "" {
 | 
				
			||||||
 | 
							msg = strings.Replace(msg, "$"+ServerIDStr+"$", "", 1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return msg, ServerList[ServerID]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user