diff --git a/cron/mic_cron/on_mic.go b/cron/mic_cron/on_mic.go index 378fa42a3f9de37b840fde6b2fd7e60b1d29f4ca..5568d9a32299fbf7af4c68ed5344ea35532c5fa6 100644 --- a/cron/mic_cron/on_mic.go +++ b/cron/mic_cron/on_mic.go @@ -3,8 +3,8 @@ package mic_cron import ( "git.hilo.cn/hilo-common/domain" "github.com/robfig/cron" + "hilo-group/domain/event/mic_ev" "hilo-group/domain/model/group_m" - "hilo-group/domain/service/group_mic_s" ) func OnMicCheck() { @@ -27,11 +27,21 @@ func OnMicCheck() { model.Log.Errorf("cron micIn group_m.GetMicUser err:%v", err) } if micUser != nil { - if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(groupId, micUser.UserId, micUser.Timestamp); err != nil { - model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err) - } else { - model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", groupId, micUser.UserId) + if err := mic_ev.PublishOnMicEvent(model, &mic_ev.OnMicEvent{ + GroupUuid: micUser.GroupUuid, + I: micUser.I, + ExternalId: micUser.ExternalId, + UserId: micUser.UserId, + Forbid: micUser.Forbid, + Timestamp: micUser.Timestamp, + }); err != nil { + model.Log.Errorf("PublishOnMicEvent fail:%v", err) } + //if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(groupId, micUser.UserId, micUser.Timestamp); err != nil { + // model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err) + //} else { + // model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", groupId, micUser.UserId) + //} } } } diff --git a/domain/event/mic_ev/on_mic.go b/domain/event/mic_ev/on_mic.go new file mode 100644 index 0000000000000000000000000000000000000000..881a20c2c69e6582f03de1817760a23c1e8f8a40 --- /dev/null +++ b/domain/event/mic_ev/on_mic.go @@ -0,0 +1,29 @@ +package mic_ev + +import ( + "git.hilo.cn/hilo-common/domain" +) + +var onMicListen = new(domain.EventBase) + +// 在麦上事件 +type OnMicEvent struct { + GroupUuid string // 群组uuid + I int // 麦位 + ExternalId string // 麦中的人 + UserId uint64 // 麦中的人 + Forbid bool // 静音 true:静音,false:没有静音 + Timestamp int64 // 上麦的的时间戳 +} + +func AddOnMicEventSync(callback func(model *domain.Model, event interface{}) error) { + domain.AddEventSync(onMicListen, callback) +} + +func AddOnMicEventAsync(callback func(model *domain.Model, event interface{}) error) { + domain.AddEventAsync(onMicListen, callback) +} + +func PublishOnMicEvent(model *domain.Model, event interface{}) error { + return domain.PublishEvent(onMicListen, model, event) +} diff --git a/domain/service/event_s/event_init.go b/domain/service/event_s/event_init.go index f32652f3ab28bdf0aadf8a00faef5115a4e23456..b39502eb55c5f2136d37e6e764ba9d11a09135fa 100644 --- a/domain/service/event_s/event_init.go +++ b/domain/service/event_s/event_init.go @@ -13,12 +13,14 @@ import ( "hilo-group/domain/event/gift_ev" "hilo-group/domain/event/group_ev" "hilo-group/domain/event/group_power_ev" + "hilo-group/domain/event/mic_ev" "hilo-group/domain/model/diamond_m" "hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/group_m" "hilo-group/domain/model/msg_m" "hilo-group/domain/model/task_m" "hilo-group/domain/model/user_m" + "hilo-group/domain/service/group_mic_s" "hilo-group/myerr" "strconv" "time" @@ -30,7 +32,8 @@ func EventInit() { GroupEvents() GroupImMass() GroupTheme() - SendGift() + SendGift() // 送礼事件 + OnMic() // 在麦上事件 } func GroupSupportEvents() { @@ -451,3 +454,19 @@ func SendGift() { return nil }) } + +func OnMic() { + mic_ev.AddOnMicEventSync(func(model *domain.Model, e interface{}) error { + event, ok := e.(*mic_ev.OnMicEvent) + if !ok { + model.Log.Errorf("AddOnMicEventSync event type err") + return nil + } + if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(event.GroupUuid, event.UserId, event.Timestamp); err != nil { + model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err) + } else { + model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", event.GroupUuid, event.UserId) + } + return nil + }) +}