Пример #1
0
        private async Task <string> GetAvatarAsync(CmInGameAppJoinRequestParams joinRequest)
        {
            try {
                if (_avatarUserId != joinRequest.UserId && joinRequest.AvatarUrl != null)
                {
                    _avatarUserId = joinRequest.UserId;
                    using (var wc = new WebClient()) {
                        var avatarBytes = await wc.DownloadDataTaskAsync(joinRequest.AvatarUrl).ConfigureAwait(false);

                        foreach (var filename in GetAvatarFilename().Where(x => Directory.Exists(Path.GetDirectoryName(x))))
                        {
                            await FileUtils.WriteAllBytesAsync(filename, avatarBytes).ConfigureAwait(false);
                        }
                    }

                    return(AvatarId);
                }
            } catch (WebException e) {
                Logging.Error(e.Message);
            } catch (Exception e) {
                Logging.Warning(e);
            }

            return(AvatarDefaultId);
        }
Пример #2
0
        private async Task UpdateDiscordAsync(CmInGameAppJoinRequestParams joinRequest)
        {
            if (!await EnsureConnectedAsync(true).ConfigureAwait(false))
            {
                return;
            }
            var avatar = await GetAvatarAsync(joinRequest).ConfigureAwait(false);

            var response = await SendRequestAsync(joinRequest.UserName, avatar,
                                                  (joinRequest.YesProgress * 255).ClampToByte(), (joinRequest.NoProgress * 255).ClampToByte()).ConfigureAwait(false);

            switch (response)
            {
            case AppResponse.Yes:
                joinRequest.ChoiseCallback?.Invoke(true);
                break;

            case AppResponse.No:
                joinRequest.ChoiseCallback?.Invoke(false);
                break;

            case AppResponse.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }