public void On <T>(EventEnum @event, Func <T, Task> func)
        {
            switch (@event)
            {
            case EventEnum.Scan:
                WechahtyEvent.Subscribe(func as Func <EventScanPayload, Task>);
                break;

            case EventEnum.Ready:
                WechahtyEvent.Subscribe(func as Func <EventReadyPayload, Task>);
                break;

            case EventEnum.Login:
                WechahtyEvent.Subscribe(func as Func <EventLoginPayload, Task>);
                break;

            case EventEnum.Heartbeat:
                WechahtyEvent.Subscribe(func as Func <EventHeartbeatPayload, Task>);
                break;

            case EventEnum.Dong:
                break;

            case EventEnum.Reset:
                break;

            case EventEnum.Message:
                WechahtyEvent.Subscribe(func as Func <EventMessagePayload, Task>);
                break;

            case EventEnum.Friendship:
                break;

            case EventEnum.RoomInvite:
                break;

            case EventEnum.RoomJoin:
                break;

            case EventEnum.RoomLeave:
                break;

            case EventEnum.RoomTopic:
                break;

            case EventEnum.Logout:
                break;

            case EventEnum.Error:
                break;

            default:
                break;
            }
        }
예제 #2
0
        public void DingDong()
        {
            WechahtyEvent.Subscribe <EventMessagePayload>(async(eventData) =>
            {
                var payload = await Message.Ready(eventData.MessageId);

                if (payload.Text.ToLower() == "ding")
                {
                    await Message.Say("dong");
                }
            });
        }
        public void QRCodeTerminalAsAscii()
        {
            WechahtyEvent.Subscribe <EventScanPayload>(async(eventData) =>
            {
                if (eventData.Status == ScanStatus.Waiting || eventData.Status == ScanStatus.Timeout)
                {
                    await Task.Run(() =>
                    {
                        string qrcodeImageUrl = GetWechatGithubQrCode(eventData.Qrcode);

                        Url generator  = new Url(qrcodeImageUrl);
                        string payload = generator.ToString();

                        QRCodeGenerator qrGenerator = new QRCodeGenerator();
                        QRCodeData qrCodeData       = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.L);

                        AsciiQRCode qrCodeAsi   = new AsciiQRCode(qrCodeData);
                        string qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1);
                        Console.WriteLine(qrCodeAsAsciiArt);
                    });
                }
            });
        }