示例#1
0
        private async Task HandleStaffRoleUpdate(SetUpRequest request, IUserMessage message)
        {
            await message.Channel.SendMessageAsync("Enter the staff role used for high level permissions");

            while (true)
            {
                var response = await _discordMessageService.WaitForNextMessageFromUser(request.Message.Author.Id, TimeSpan.FromSeconds(30));

                if (response is null)
                {
                    break;
                }

                var isValidUlong = ulong.TryParse(response.Content, out var roleId) ||
                                   MentionUtils.TryParseRole(response.Content, out roleId);

                if (isValidUlong)
                {
                    var isValidCategory = _discordGuildService.HasRole(roleId);

                    if (!isValidCategory)
                    {
                        await response.AddErrorEmote();

                        continue;
                    }

                    await _behaviourConfigurationService.SetStaffRole(roleId);

                    await response.AddSuccessEmote();

                    break;
                }

                var hasNamedRole = _discordGuildService.HasRole(response.Content);

                if (!hasNamedRole)
                {
                    await response.AddErrorEmote();

                    continue;
                }

                var namedRoleId = _discordGuildService.GetRoleId(response.Content);

                await _behaviourConfigurationService.SetStaffRole(namedRoleId);

                await response.AddSuccessEmote();

                break;
            }
        }