Ejemplo n.º 1
0
        /// <summary></summary>
        protected async Task <CQResponse> HandleEvent(CQEvent e)
        {
            Log.Debug($"收到了完整的上报事件{e.postType}");
            switch (e)
            {
            case HeartbeatEvent heartbeat:
                if (heartbeat.status.online)
                {
                    alive = true;
                    alive_counter++;
                    var task = Task.Run(async() => {
                        await Task.Delay((int)heartbeat.interval);
                        if (alive_counter-- == 0)
                        {
                            alive = false;
                            cqhttp.Cyan.Log.Warn("Bot went offline");
                        }
                    });
                }
                else
                {
                    alive = false;
                }
                return(new EmptyResponse());

            case LifecycleEvent lifecycle:
                switch (lifecycle.sub_type)
                {
                case "enable": alive = true; break;

                case "disable": alive = false; break;
                }
                return(new EmptyResponse());

            case MessageEvent message:
                alive = true;
                if (message_table != null)
                {
                    message_table.Log(
                        message.message_id,
                        message.message
                        );
                }
                await ProcessMessageEvent(message);

                if (await DialoguePool.Handle(this, (e as MessageEvent)))
                {
                    return(new EmptyResponse());
                }
                break;
            }
            try {
                if (OnEventAsync != null)
                {
                    await OnEventAsync(this, e);
                }
                if (OnEvent != null)
                {
                    return(OnEvent(this, e));
                }
                else
                {
                    return(new EmptyResponse());
                }
            } catch (InvokeDialogueException d) {
                DialoguePool.Join((e as MessageEvent).GetEndpoint(), d.content);
                return(new EmptyResponse());
            }
        }
        /// <summary></summary>
        protected async Task <CQResponse> HandleEvent(CQEvent e)
        {
            Log.Debug($"收到了完整的上报事件{e.postType}");
            switch (e)
            {
            case HeartbeatEvent heartbeat:
                if (heartbeat.status.online)
                {
                    alive = true;
                    alive_counter++;
                    var task = Task.Run(() => {
                        System.Threading.Thread.Sleep(
                            (int)heartbeat.interval
                            );
                        if (alive_counter-- == 0)
                        {
                            alive = false;
                        }
                    });
                }
                else
                {
                    alive = false;
                }
                return(new EmptyResponse());

            case LifecycleEvent lifecycle:
                alive = lifecycle.enabled ? true : false;
                return(new EmptyResponse());

            case MessageEvent message:
                alive = true;
                if (message_table != null)
                {
                    message_table.Log(
                        message.message_id,
                        message.message
                        );
                }
                await ProcessMessageEvent(message);

                if (DialoguePool.Handle(this, (e as MessageEvent)))
                {
                    return(new EmptyResponse());
                }
                break;
            }
            try {
                if (OnEventAsync != null)
                {
                    await OnEventAsync(this, e);
                }
                if (OnEvent != null)
                {
                    return(OnEvent(this, e));
                }
                else
                {
                    return(new EmptyResponse());
                }
            } catch (InvokeDialogueException d) {
                DialoguePool.Join((e as MessageEvent).GetEndpoint(), d.content);
                return(new EmptyResponse());
            }
        }