Exemplo n.º 1
0
        public async Task CommandCollectionGameUnban()
        {
            Func <Task> c1    = null;
            var         title = "Collecting Game Unban";

            c1 = () => AskAsync($"*{title} - Step 1 of 1*\nWhat's the attendees _registration number (including the letter at the end)_ on the badge?",
                                async regNoAsString =>
            {
                await ClearLastAskResponseOptions();

                int regNo           = 0;
                var regNoWithLetter = regNoAsString.Trim().ToUpper();
                if (!BadgeChecksum.TryParse(regNoWithLetter, out regNo))
                {
                    await ReplyAsync($"_{regNoWithLetter} is not a valid badge number - checksum letter is missing or wrong._");
                    await c1();
                    return;
                }

                var result = await _collectingGameService.UnbanPlayerAsync(
                    $"RegSys:{_conventionSettings.ConventionNumber}:{regNo}");

                if (result.IsSuccessful)
                {
                    await ReplyAsync($"*{title}* - Success - {regNo} unbanned.");
                }
                else
                {
                    await ReplyAsync($"*{title}* - Error\n\n{result.ErrorMessage} ({result.ErrorCode})");
                }
            }, "Cancel=/cancel");
            await c1();
        }
Exemplo n.º 2
0
        public async Task <RegSysAlternativePinResponse> RequestAlternativePinAsync(RegSysAlternativePinRequest request, string requesterUid)
        {
            int regNo = 0;

            if (!BadgeChecksum.TryParse(request.RegNoOnBadge, out regNo))
            {
                return(null);
            }

            var alternativePin =
                (await _regSysAlternativePinRepository.FindAllAsync(a => a.RegNo == regNo))
                .SingleOrDefault();

            bool existingRecord = true;

            if (alternativePin == null)
            {
                existingRecord = false;
                alternativePin = new RegSysAlternativePinRecord()
                {
                    RegNo = regNo,
                };
                alternativePin.NewId();
            }

            alternativePin.IssuedByUid       = requesterUid;
            alternativePin.IssuedDateTimeUtc = DateTime.UtcNow;
            alternativePin.Pin         = GeneratePin();
            alternativePin.NameOnBadge = request.NameOnBadge;
            alternativePin.IssueLog.Add(new RegSysAlternativePinRecord.IssueRecord()
            {
                RequestDateTimeUtc = DateTime.UtcNow,
                NameOnBadge        = request.NameOnBadge,
                RequesterUid       = requesterUid
            });

            alternativePin.Touch();

            if (existingRecord)
            {
                await _regSysAlternativePinRepository.ReplaceOneAsync(alternativePin);
            }
            else
            {
                await _regSysAlternativePinRepository.InsertOneAsync(alternativePin);
            }

            return(new RegSysAlternativePinResponse()
            {
                NameOnBadge = alternativePin.NameOnBadge,
                Pin = alternativePin.Pin,
                RegNo = alternativePin.RegNo
            });
        }
Exemplo n.º 3
0
        private async Task CommandPinInfo()
        {
            Func <Task> c1    = null;
            var         title = "PIN Info";

            c1 = () => AskAsync($"*{title} - Step 1 of 1*\nWhat's the attendees _registration number (including the letter at the end)_ on the badge?",
                                async c1a =>
            {
                await ClearLastAskResponseOptions();

                int regNo           = 0;
                var regNoWithLetter = c1a.Trim().ToUpper();
                if (!BadgeChecksum.TryParse(regNoWithLetter, out regNo))
                {
                    await ReplyAsync($"_{regNoWithLetter} is not a valid badge number - checksum letter is missing or wrong._");
                    await c1();
                    return;
                }

                var record = await _regSysAlternativePinAuthenticationProvider.GetAlternativePinAsync(regNo);

                if (record == null)
                {
                    await ReplyAsync($"Sorry, there is no pin record for RegNo {regNo}.");
                    return;
                }

                var response = new StringBuilder();
                response.AppendLine($"RegNo: *{record.RegNo}*");
                response.AppendLine($"NameOnBadge: *{record.NameOnBadge.EscapeMarkdown()}*");
                response.AppendLine($"Pin: *{record.Pin}*");
                response.AppendLine("\n```\nAll times are UTC.\n");
                response.AppendLine($"Issued on {record.IssuedDateTimeUtc} by {record.IssuedByUid}");
                response.AppendLine("");
                response.AppendLine("Issue Log:");
                response.AppendLine(string.Join("\n",
                                                record.IssueLog.Select(a => $"- {a.RequestDateTimeUtc} {a.RequesterUid}")));

                response.AppendLine("\nUsed for login at:");
                response.AppendLine(string.Join("\n", record.PinConsumptionDatesUtc.Select(a => $"- {a}")));

                response.AppendLine("```");

                await ReplyAsync(response.ToString());
            }, "Cancel=/cancel");
            await c1();
        }
Exemplo n.º 4
0
        public async Task CommandLocate()
        {
            Func <Task> c1    = null;
            var         title = "Locate User";

            c1 = () => AskAsync($"*{title} - Step 1 of 1*\nWhat's the attendees _registration number (including the letter at the end)_ on the badge?",
                                async c1a =>
            {
                await ClearLastAskResponseOptions();

                int regNo           = 0;
                var regNoWithLetter = c1a.Trim().ToUpper();
                if (!BadgeChecksum.TryParse(regNoWithLetter, out regNo))
                {
                    await ReplyAsync($"_{regNoWithLetter} is not a valid badge number - checksum letter is missing or wrong._");
                    await c1();
                    return;
                }

                var records =
                    (await _pushNotificationChannelRepository.FindAllAsync(a => a.Uid.StartsWith("RegSys:") && a.Uid.EndsWith($":{regNo}")))
                    .ToList();

                if (records.Count == 0)
                {
                    await ReplyAsync($"*{title} - Result*\nRegNo {regNo} is not logged in on any known device.");
                    return;
                }

                var response = new StringBuilder();
                response.AppendLine($"*{title} - Result*");
                response.AppendLine($"RegNo *{regNo}* is logged in on *{records.Count}* devices:");
                foreach (var record in records)
                {
                    response.AppendLine(
                        $"`{record.Platform} {string.Join(",", record.Topics)} ({record.LastChangeDateTimeUtc})`");
                }


                await ReplyAsync(response.ToString());
            }, "Cancel=/cancel");
            await c1();
        }
Exemplo n.º 5
0
        public async Task CommandBadgeChecksum()
        {
            Func <Task> c1    = null;
            var         title = "Badge Checksum";

            c1 = () => AskAsync($"*{title} - Step 1 of 1*\nWhat's the _registration number_?",
                                async regNoAsString =>
            {
                await ClearLastAskResponseOptions();

                int regNo = 0;
                if (!int.TryParse(regNoAsString, out regNo))
                {
                    await ReplyAsync($"_{regNoAsString} is not a number._");
                    await c1();
                    return;
                }

                var checksumLetter = BadgeChecksum.CalculateChecksum(regNo);

                await ReplyAsync($"*{title} - Result*\nBadge will show *{regNoAsString}{checksumLetter}*.");
            }, "Cancel=/cancel");
            await c1();
        }
Exemplo n.º 6
0
        private async Task CommandPinRequest()
        {
            Func <Task> c1 = null, c2 = null, c3 = null;

            var title        = "PIN Creation";
            var requesterUid = $"Telegram:@{_user.Username}";

            c1 = () => AskAsync($"*{title} - Step 1 of 3*\nWhat's the attendees _registration number (including the letter at the end)_ on the badge?",
                                async c1a =>
            {
                await ClearLastAskResponseOptions();

                int regNo           = 0;
                var regNoWithLetter = c1a.Trim().ToUpper();
                if (!BadgeChecksum.TryParse(regNoWithLetter, out regNo))
                {
                    await ReplyAsync($"_{regNoWithLetter} is not a valid badge number - checksum letter is missing or wrong._");
                    await c1();
                    return;
                }

                c2 = () => AskAsync($"*{title} - Step 2 of 3*\nOn badge no {regNo}, what is the _nickname_ printed on the badge (not the real name)?",
                                    async c2a =>
                {
                    await ClearLastAskResponseOptions();

                    var nameOnBadge = c2a.Trim();

                    c3 = () => AskAsync(
                        $"*{title} - Step 3 of 3*\nPlease confirm:\n\nThe badge no. is *{regNoWithLetter}*\n\nThe nickname on the badge is *{nameOnBadge.EscapeMarkdown()}*" +
                        "\n\n*You have verified the identity of the attendee by matching their real name on badge against a legal form of identification.*",
                        async c3a =>
                    {
                        if (c3a.Equals("*restart", StringComparison.CurrentCultureIgnoreCase))
                        {
                            await c1();
                            return;
                        }

                        if (!c3a.Equals("*confirm", StringComparison.CurrentCultureIgnoreCase))
                        {
                            await c3();
                            return;
                        }

                        var result = await _regSysAlternativePinAuthenticationProvider.RequestAlternativePinAsync(
                            new RegSysAlternativePinRequest()
                        {
                            NameOnBadge  = nameOnBadge,
                            RegNoOnBadge = regNoWithLetter,
                        }, requesterUid: requesterUid);

                        var response = new StringBuilder();

                        response.AppendLine($"*{title} - Completed*");
                        response.AppendLine($"Registration Number: *{result.RegNo}*");
                        response.AppendLine($"Name on Badge: *{result.NameOnBadge.EscapeMarkdown()}*");
                        response.AppendLine($"PIN: *{result.Pin}*");
                        response.AppendLine();
                        response.AppendLine($"User can login to the Eurofurence Apps (mobile devices and web) with their registration number (*{result.RegNo}*) and PIN (*{result.Pin}*) as their password. They can type in any username, it does not matter.");
                        response.AppendLine($"\n_Generation/Access of this PIN by {requesterUid.EscapeMarkdown()} has been recorded._");

                        _logger.LogInformation("@{username} created PIN for {regNo} {nameOnBadge}", _user.Username, result.RegNo, result.NameOnBadge);

                        await ReplyAsync(response.ToString());
                    }, "Confirm=*confirm", "Restart=*restart", "Cancel=/cancel");
                    await c3();
                }, "Cancel=/cancel");
                await c2();
            }, "Cancel=/cancel");
            await c1();
        }
Exemplo n.º 7
0
        public async Task CommandSendMessage()
        {
            Func <Task> c1 = null, c2 = null, c3 = null, c4 = null;
            var         title = "Send Message";

            c1 = () => AskAsync($"*{title} - Step 1 of 1*\nWhat's the attendees _registration number (including the letter at the end)_ on the badge?",
                                async c1a =>
            {
                await ClearLastAskResponseOptions();

                int regNo           = 0;
                var regNoWithLetter = c1a.Trim().ToUpper();
                if (!BadgeChecksum.TryParse(regNoWithLetter, out regNo))
                {
                    await ReplyAsync($"_{regNoWithLetter} is not a valid badge number - checksum letter is missing or wrong._");
                    await c1();
                    return;
                }

                var records =
                    (await _pushNotificationChannelRepository.FindAllAsync(a => a.Uid.StartsWith("RegSys:") && a.Uid.EndsWith($":{regNo}")))
                    .ToList();

                if (records.Count == 0)
                {
                    await ReplyAsync($"*WARNING: RegNo {regNo} is not logged in on any known device - they will receive the message when they login.*");
                }

                c2 = () => AskAsync($"*{title} - Step 2 of 3*\nPlease specify the subject of the message.", async subject =>
                {
                    await ClearLastAskResponseOptions();
                    c3 = () => AskAsync($"*{title} - Step 3 of 3*\nPlease specify the body of the message.", async body =>
                    {
                        await ClearLastAskResponseOptions();
                        var from = $"{_user.FirstName} {_user.LastName}";

                        c4 = () => AskAsync(

                            $"*{title} - Review*\n\nFrom: *{from.EscapeMarkdown()}*\nTo: *{regNo}*\nSubject: *{subject.EscapeMarkdown()}*\n\nMessage:\n*{body.EscapeMarkdown()}*\n\n_Message will be placed in the users inbox and directly pushed to _*{records.Count}*_ devices._",
                            async c4a =>
                        {
                            if (c4a != "*send")
                            {
                                await c3();
                                return;
                            }

                            await _privateMessageService.SendPrivateMessageAsync(new SendPrivateMessageRequest()
                            {
                                AuthorName   = $"{from}",
                                RecipientUid = $"RegSys:23:{regNo}",
                                Message      = body,
                                Subject      = subject,
                                ToastTitle   = "You received a new personal message",
                                ToastMessage = "Open the Eurofurence App to read it."
                            });

                            await ReplyAsync("Message sent.");
                        }, "Send=*send", "Cancel=/cancel");
                        await c4();
                    }, "Cancel=/cancel");
                    await c3();
                }, "Cancel=/cancel");

                await c2();
            }, "Cancel=/cancel");
            await c1();
        }