Esempio n. 1
0
        public async Task SendMessage(string message, string steamId)
        {
            var user = await _repoServiceFactory.UserRepoService.FindAsync(steamId);

            var staffName = await _staffService.GetUserStaffName(steamId);

            var userStatusName = staffName ?? "User";
            var ignoreRules    = staffName != null;

            var reguset = new InsertMessageRequest
            {
                AntiSpamSeconds = 5,
                ChatMessage     = new ChatMessage
                {
                    Message  = message,
                    SteamId  = steamId,
                    Image    = user.ImageUrl,
                    Name     = user.Name,
                    UserType = userStatusName
                },
                IgnoreRules = ignoreRules
            };
            var res = await _chatServiceClient.InsertMessage(reguset);

            switch (res.DataCase)
            {
            case InsertMessageResponse.DataOneofCase.ChatMessage:
                await _chatHubConnections.MessageReceived(new ChatMessageModel
                {
                    Message   = message,
                    SteamId   = steamId,
                    ImageUrl  = user.ImageUrl,
                    Name      = user.Name,
                    TimeStamp = res.ChatMessage.Timestamp,
                    UserType  = res.ChatMessage.UserType
                });

                _discordService.ChatMessageAsync(user.Name, message);
                break;

            case InsertMessageResponse.DataOneofCase.None:
            case InsertMessageResponse.DataOneofCase.Error:
                await _chatHubConnections.SendError(res.Error.Message, steamId);

                break;

            default:
                await _chatHubConnections.SendError(res.Error.Message, steamId);

                break;
            }
        }
 public async Task <InsertMessageResponse> InsertMessage(InsertMessageRequest request)
 {
     return(await SendGrpcAction(async() => await _chatServiceClient.InsertMessageAsync(request, DefaultSettings.GetDefaultSettings(5))));
 }