Exemplo n.º 1
0
        public MeResponse GetMeResponse(string bearerToken)
        {
            string     meUri    = "https://discordapp.com/api/users/@me";
            MeResponse response = meUri.WithOAuthBearerToken(bearerToken)
                                  .GetJsonAsync <MeResponse>().Result;

            return(response);
        }
Exemplo n.º 2
0
        public async Task <MeResponse> GetMe()
        {
            Url url = new Url(BaseUrl).AppendPathSegment("me");
            HttpResponseMessage responseMessage = await Get(url);

            MeResponse response = GetObject <MeResponse>(await responseMessage.Content.ReadAsStringAsync());

            return(response);
        }
Exemplo n.º 3
0
        public async Task <List <VenmoUser> > GetAllFriends()
        {
            MeResponse me = await GetMe();

            int limit  = me.Data !.User.FriendsCount !.Value;
            int offset = 0;
            List <VenmoUser> friends = new List <VenmoUser>();
            FriendsResponse? friendsResponse;

            do
            {
                friendsResponse = await GetFriends(limit, offset);

                friends.AddRange(friendsResponse.Data !);
                limit   = friendsResponse.Data !.Count;
                offset += friendsResponse.Data.Count;
            }while (friendsResponse.Pagination != null && friendsResponse.Pagination.Next != null);
            return(friends);
        }
Exemplo n.º 4
0
        public async Task <FriendsResponse> GetFriends(int limit = 20, int offset = 0)
        {
            if (string.IsNullOrEmpty(UserId))
            {
                // If UserId hasn't been loaded yet then retrieve it
                MeResponse me = await GetMe();

                UserId = me.Data !.User.Id;
            }
            Url url = new Url(BaseUrl).AppendPathSegments("users", UserId, "friends")
                      .SetQueryParams(new {
                limit        = limit,
                offset       = offset,
                access_token = AccessToken
            });
            HttpResponseMessage responseMessage = await Get(url);

            FriendsResponse response = GetObject <FriendsResponse>(await responseMessage.Content.ReadAsStringAsync());

            return(response);
        }
Exemplo n.º 5
0
        public static List <MeResponse> GetNew(this MeRequest request, int currentTotal, int count = 10)
        {
            List <MeResponse> result = new List <MeResponse>();

            int old_offset = request.Offset;
            int old_count  = request.Count;

            request.Count = count;

            request.Offset = 1;

            MeResponse response = request.Execute();

            if (response != null)
            {
                int total  = response.Total;
                int numNew = total - currentTotal;

                for (request.Offset = 1; request.Offset + request.Count <= numNew; request.Offset += request.Count)
                {
                    response = request.Execute();
                    if (response != null)
                    {
                        result.Add(response);
                    }
                }

                request.Count = numNew - (request.Offset - 1);
                response      = request.Execute();
                if (response != null)
                {
                    result.Add(response);
                }
            }

            request.Offset = old_offset;
            request.Count  = old_count;

            return(result);
        }
Exemplo n.º 6
0
        public Signin(IDiscordService discordService, string code, IAuthenticationService authenticationService, string sessionId)
        {
            AccessTokenResponse           response        = discordService.GetAccessTokenWithCode(code);
            MeResponse                    discordUser     = discordService.GetMeResponse(response.access_token);
            GetReportUserByCookieResponse tryRetrieveUser = authenticationService.GetReportUserByWebCookie(sessionId);

            if (tryRetrieveUser.Success == true)
            {
                Message = "You were logged in already, this site has tried to associate your discord ID and report tool account (" + tryRetrieveUser.User.Username + ").";
                authenticationService.AssociateUserWithDiscordId(tryRetrieveUser.User.Id, discordUser.id);
                this.NewSessionCookie = authenticationService.CreateWebSessionFromDiscordId(discordUser.id);
            }
            else
            {
                Message = "You were not logged in to a report tool account before utilizing discord as a signin service.";
                this.NewSessionCookie = authenticationService.CreateWebSessionFromDiscordId(discordUser.id);
                if (this.NewSessionCookie == string.Empty)
                {
                    Message = "This site does not permit auto-creation of users. Seek out a tool administrator's assistance with registration.";
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Occurs when a message is received.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private Task OnMessageReceived(MqttApplicationMessageReceivedEventArgs e)
        {
            return(Task.Run(() =>
            {
                try
                {
                    if (!e.ApplicationMessage.Topic.StartsWith("emitter"))
                    {
                        var handlers = this.Trie.Match(e.ApplicationMessage.Topic);
                        // Invoke every handler matching the channel
                        foreach (MessageHandler handler in handlers)
                        {
                            handler(e.ApplicationMessage.Topic, e.ApplicationMessage.Payload);
                        }

                        if (handlers.Count == 0)
                        {
                            DefaultMessageHandler?.Invoke(e.ApplicationMessage.Topic, e.ApplicationMessage.Payload);
                        }
                        return;
                    }

                    // Did we receive a keygen response?
                    if (e.ApplicationMessage.Topic == "emitter/keygen/")
                    {
                        // Deserialize the response
                        var response = KeygenResponse.FromBinary(e.ApplicationMessage.Payload);
                        if (response == null || response.Status != 200)
                        {
                            this.InvokeError(response.Status);
                            return;
                        }

                        // Call the response handler we have registered previously
                        // TODO: get rid of the handler afterwards, or refac keygen
                        if (this.KeygenHandlers.ContainsKey(response.Channel))
                        {
                            ((KeygenHandler)this.KeygenHandlers[response.Channel])(response);
                        }
                        return;
                    }

                    if (e.ApplicationMessage.Topic == "emitter/presence/")
                    {
                        var presenceEvent = PresenceEvent.FromBinary(e.ApplicationMessage.Payload);

                        var handlers = this.PresenceTrie.Match(presenceEvent.Channel);
                        // Invoke every handler matching the channel
                        foreach (PresenceHandler handler in handlers)
                        {
                            handler(presenceEvent);
                        }

                        if (handlers.Count == 0)
                        {
                            DefaultPresenceHandler?.Invoke(presenceEvent);
                        }

                        return;
                    }

                    if (e.ApplicationMessage.Topic == "emitter/error/")
                    {
                        var errorEvent = ErrorEvent.FromBinary(e.ApplicationMessage.Payload);
                        var emitterException = new EmitterException((EmitterEventCode)errorEvent.Status, errorEvent.Message);

                        InvokeError(emitterException);
                        return;
                    }

                    if (e.ApplicationMessage.Topic == "emitter/me/")
                    {
                        var meResponse = MeResponse.FromBinary(e.ApplicationMessage.Payload);
                        Me?.Invoke(meResponse);

                        return;
                    }
                    return;
                }
                catch (Exception ex)
                {
                    this.InvokeError(ex);
                    return;
                }
            }));
        }
Exemplo n.º 8
0
        public async Task <MeResponse> Me()
        {
            var user = await repository.FindUser(User) ?? throw new ArgumentException();

            return(MeResponse.Create(user.RoomId, user.ToPresent()));
        }