Ejemplo n.º 1
0
func (l *OperationLogger) Record(from string, _opTime time.Time, _r interface{}, status string) {
	opTime := _opTime.Format("2006-01-02 15:04:05")
	switch _r.(type) {
	case *DeletePostRequest:
		r := _r.(*DeletePostRequest)
		logs.Info(MakePrefix(nil, r.tid, r.pid, r.spid, r.uid), from, "删贴", r.reason, status)
		uid, tid, pid, spid := strconv.FormatUint(r.uid, 10), strconv.FormatUint(r.tid, 10),
			strconv.FormatUint(r.pid, 10), strconv.FormatUint(r.spid, 10)
		l.writer.Write([]string{"删贴", status, from, r.reason, opTime, r.postTime,
			r.author, uid, r.title, tid, pid, spid,
			string(replace([]rune(fmt.Sprint(r.content)), '\n', '\t')), r.remark})
	case *DeleteThreadRequest:
		r := _r.(*DeleteThreadRequest)
		logs.Info(MakePrefix(nil, r.tid, r.pid, 0, r.uid), from, "删主题", r.reason, status)
		uid, tid, pid := strconv.FormatUint(r.uid, 10), strconv.FormatUint(r.tid, 10),
			strconv.FormatUint(r.pid, 10)
		l.writer.Write([]string{"删主题", status, from, r.reason, opTime, r.postTime,
			r.author, uid, r.title, tid, pid, "0",
			string(replace([]rune(fmt.Sprint(r.content)), '\n', '\t')), r.remark})
	case *BanIDRequest:
		r := _r.(*BanIDRequest)
		logs.Info(MakePrefix(nil, r.tid, r.pid, r.spid, r.uid), from, "封禁", fmt.Sprintf("%s(%s)", r.loggedReason, r.givedReason), status)
		tid, pid, spid, uid := strconv.FormatUint(r.tid, 10),
			strconv.FormatUint(r.pid, 10), strconv.FormatUint(r.spid, 10), strconv.FormatUint(r.uid, 10)
		l.writer.Write([]string{"封禁", status, from, r.loggedReason, opTime, r.postTime,
			r.userName, uid, r.title, tid, pid, spid,
			string(replace([]rune(fmt.Sprint(r.content)), '\n', '\t')), r.remark + fmt.Sprintf("天数:%d, 给出原因:%s, ", r.day, r.givedReason)})
	}

	l.writer.Flush()
}
Ejemplo n.º 2
0
func keepUpdatingSettings() *Settings {
	var settings Settings
	var fileName string
	if len(os.Args) == 1 {
		fileName = "删贴机设置.json"
	} else {
		fileName = os.Args[1]
	}

	var lastModTime time.Time
	ticker := time.NewTicker(time.Second)
	var isFirstTime bool = true
	var firstTimeWaitChan = make(chan bool)
	go func() {
		for {

			info, err := os.Stat(fileName)
			if err != nil {
				if isFirstTime {
					panic(err)
				}
				continue
			}

			if modTime := info.ModTime(); modTime.After(lastModTime) {
				lastModTime = modTime
				_settings, err := LoadSettings(fileName)
				if err != nil {
					logs.Fatal("更新设置文件失败,将继续使用旧设置:", err)
				} else {
					logs.Info("更新设置文件成功(然而这并没有什么用(除了第一次之外)).")
					settings = *_settings
				}
			}

			if isFirstTime {
				firstTimeWaitChan <- true
				isFirstTime = false
			}

			<-ticker.C
		}

	}()

	<-firstTimeWaitChan
	close(firstTimeWaitChan)

	return &settings
}
Ejemplo n.º 3
0
func main() {
	var logDir = time.Now().Format("log/20060102-150405-post-deleter/")

	os.MkdirAll(logDir, 0644)

	logs.Info("删贴机启动", time.Now())

	var settings = keepUpdatingSettings()
	{
		var BDUSS = settings.BDUSS
		if BDUSS != "" {
			settings.BDUSS = "***"
		}
		logs.Info(settings)
		settings.BDUSS = BDUSS
	}

	if settings == nil {
		os.Exit(1)
	}

	if settings.BDUSS == "" {
		logs.Warn("未设置BDUSS.")
	}

	if settings.DebugPort != 0 {
		go func() {
			http.ListenAndServe(fmt.Sprintf("localhost:%d", settings.DebugPort), nil)
		}()
	}

	var accAndr = postbar.NewDefaultAndroidAccount("")
	var accWin8 = postbar.NewDefaultWindows8Account("")
	accWin8.BDUSS = settings.BDUSS
	accAndr.BDUSS = settings.BDUSS

	if settings.ForumID == 0 {
		logs.Info("设置中未提供ForumID,自动获取.")
		settings.ForumID = getFid(settings.ForumName)
		if settings.ForumID == 0 {
			logs.Fatal("未能获得到fid,退出.")
			os.Exit(1)
		}
	}

	//mrb := initMRuby(logs.DefaultLogger)

	if d, err := postdeleter.NewPostDeleter(
		postdeleter.PostDeleterBuildingParameters{
			AccWin8: accWin8,
			AccAndr: accAndr,

			ForumName: settings.ForumName,
			ForumID:   settings.ForumID,

			ConfgiFileName: postdeleter.ConfgiFileName{
				ContentRegexp:     settings.ContentRegexpFilePath,
				UserNameRegexp:    settings.UserNameRegexpFilePath,
				TidWhiteList:      settings.TidWhiteListFilePath,
				UserNameWhiteList: settings.UserNameWhiteListFilePath,
				BawuList:          settings.BawuListFilePath,
			},

			Debugging: settings.DebugPort != 0,
			LogDir:    logDir,
		}); err != nil {
		logs.Fatal("无法启动删贴机,退出.", err)
		os.Exit(1)
	} else {
		d.Run(time.Second)
	}

	<-make(chan struct{})

}