Beispiel #1
0
        public async Task DealMessage(string groupNo, string account)
        {
            try
            {
                var key = CacheConst.GetGroupMsgListKey(groupNo);

                string cacheMsgInfo = await _database.ListLeftPopAsync(key);

                IMahuaApi mahuaApi = null;

                while (!string.IsNullOrWhiteSpace(cacheMsgInfo))
                {
                    mahuaApi = mahuaApi ?? MahuaRobotManager.Instance.CreateSession(account).MahuaApi;

                    GroupItemRes msg = JsonConvert.DeserializeObject <GroupItemRes>(cacheMsgInfo);

                    MahuaApiHelper.SendGroupMsg(mahuaApi, msg, groupNo, account);

                    cacheMsgInfo = await _database.ListLeftPopAsync(key);
                }
            }
            catch (Exception e)
            {
                var str = e.Message;
            }
        }
Beispiel #2
0
        public async Task DealMsg(JobConfig config)
        {
            Logger.Debug($"[自定义任务]开始执行-{config.Id}");

            var dbConfig = await _jobConfigService.GetAsync(config.Id);

            if (dbConfig == null || dbConfig.Enable == false) // 任务失效或被删除时 自动停止并移除任务
            {
                Logger.Debug($"[自定义任务]任务已失效-{config.Id}");
                RecurringJob.RemoveIfExists(GetId(config.Id));
                return;
            }

            if (!dbConfig.CronExpression.Equals(config.CronExpression))
            {
                await StartJob(dbConfig);

                Logger.Debug($"[自定义任务]任务配置Cron发生变化,重新执行任务-{config.Id}");
                return;
            }

            config = dbConfig;

            var mahuaApi = MahuaApiHelper.CreateApi(config.RobotAccount);

            if (mahuaApi == null)
            {
                Logger.Debug($"[自定义任务]机器人账号尚未登录-{config.Id}");
                RecurringJob.RemoveIfExists(GetId(config.Id));
                return;
            }

            if (config.ConfirmType == ConfirmTypes.FriendConfirm)
            {
                mahuaApi.SendPrivateMessage(config.Target, config.Template);
            }
            else if (config.ConfirmType == ConfirmTypes.GroupConfirm)
            {
                string message = (string.IsNullOrWhiteSpace(config.Target) ? "" : $"[@{config.Target}]") +
                                 config.Template;
                mahuaApi.SendGroupMessage(config.GroupNo, message);
            }
            else if (config.ConfirmType == ConfirmTypes.NoticeConfirm)
            {
                mahuaApi.SetNotice(config.GroupNo, config.Title, config.Template);
            }

            Logger.Debug($"[自定义任务]任务执行完毕-{config.Id}");
        }