Beispiel #1
0
        public static async Task Login(string email, string password)
        {
            DiscordApiConfiguration config = new DiscordApiConfiguration
            {
                BaseUrl = "https://discordapp.com/api"
            };
            BasicRestFactory basicRestFactory = new BasicRestFactory(config);

            ILoginService loginService = basicRestFactory.GetLoginService();

            LoginRequest.Email    = email;
            LoginRequest.Password = password;

            Loginresult = await loginService.Login(LoginRequest);

            Token = Loginresult.Token;
            IAuthenticator authenticator = new DiscordAuthenticator(Token);

            AuthenticatedRestFactory = new AuthenticatedRestFactory(config, authenticator);
            IGatewayConfigService gatewayService = basicRestFactory.GetGatewayConfigService();

            SharedModels.GatewayConfig gateconfig = await gatewayService.GetGatewayConfig();

            Gateway = new Gateway.Gateway(gateconfig, authenticator);
        }
Beispiel #2
0
        public static async Task AutoLogin()
        {
            config = new DiscordApiConfiguration
            {
                BaseUrl = "https://discordapp.com/api"
            };

            Token = Storage.Token;
            BasicRestFactory basicRestFactory = new BasicRestFactory(config);
            IAuthenticator   authenticator    = new DiscordAuthenticator(Token);

            AuthenticatedRestFactory = new AuthenticatedRestFactory(config, authenticator);
            IGatewayConfigService gatewayService = basicRestFactory.GetGatewayConfigService();

            SharedModels.GatewayConfig gateconfig = await gatewayService.GetGatewayConfig();

            Gateway = new Gateway.Gateway(gateconfig, authenticator);
        }
Beispiel #3
0
        private Task <bool> Login()
        {
            Messenger.Default.Send(new ConnectionStatusMessage(ConnectionStatus.Connecting));

            IAuthenticator           authenticator            = new DiscordAuthenticator(_accessToken);
            AuthenticatedRestFactory authenticatedRestFactory = new AuthenticatedRestFactory(new DiscordApiConfiguration()
            {
                BaseUrl = "https://discordapp.com/api"
            }, authenticator);

            ActivitesService   = authenticatedRestFactory.GetActivitesService();
            ChannelService     = authenticatedRestFactory.GetChannelService();
            ConnectionsService = authenticatedRestFactory.GetConnectionService();
            GameService        = authenticatedRestFactory.GetGameService();
            GuildService       = authenticatedRestFactory.GetGuildService();
            InviteService      = authenticatedRestFactory.GetInviteService();
            MiscService        = authenticatedRestFactory.GetMiscService();
            UserService        = authenticatedRestFactory.GetUserService();
            VoiceService       = authenticatedRestFactory.GetVoiceService();

            return(_gatewayService.InitializeGateway(_accessToken));
        }
Beispiel #4
0
        /// <inheritdoc/>
        public async Task <bool> InitializeGateway([NotNull] string accessToken)
        {
            BasicRestFactory      restFactory    = new BasicRestFactory();
            IGatewayConfigService gatewayService = restFactory.GetGatewayConfigService();

            try
            {
                GatewayConfig gatewayConfig = await gatewayService.GetGatewayConfig();

                IAuthenticator authenticator = new DiscordAuthenticator(accessToken);
                Gateway = new DiscordAPI.Gateway.Gateway(_serviceProvider, gatewayConfig, authenticator);
            }
            catch
            {
                Messenger.Default.Send(new ConnectionStatusMessage(ConnectionStatus.Failed));
                return(false);
            }

            Gateway.Ready             += Gateway_Ready;
            Gateway.GuildMembersChunk += GatewayGuildMembersChunk;
            Gateway.GuildSynced       += Gateway_GuildSynced;

            Gateway.GuildCreated += Gateway_GuildCreated;
            Gateway.GuildDeleted += Gateway_GuildDeleted;
            Gateway.GuildUpdated += Gateway_GuildUpdated;

            Gateway.MessageCreated += Gateway_MessageCreated;
            Gateway.MessageDeleted += Gateway_MessageDeleted;
            Gateway.MessageUpdated += Gateway_MessageUpdated;
            Gateway.MessageAck     += Gateway_MessageAck;

            Gateway.MessageReactionAdded      += Gateway_MessageReactionAdded;
            Gateway.MessageReactionRemoved    += Gateway_MessageReactionRemoved;
            Gateway.MessageReactionRemovedAll += Gateway_MessageReactionRemovedAll;

            Gateway.GuildMemberListUpdated += Gateway_GuildMemberListUpdated;

            Gateway.ChannelCreated      += Gateway_ChannelCreated;
            Gateway.ChannelDeleted      += Gateway_ChannelDeleted;
            Gateway.GuildChannelUpdated += Gateway_GuildChannelUpdated;

            Gateway.TypingStarted += Gateway_TypingStarted;

            Gateway.PresenceUpdated          += Gateway_PresenceUpdated;
            Gateway.UserNoteUpdated          += Gateway_UserNoteUpdated;
            Gateway.UserGuildSettingsUpdated += Gateway_UserGuildSettingsUpdated;
            Gateway.UserSettingsUpdated      += Gateway_UserSettingsUpdated;

            Gateway.VoiceServerUpdated += Gateway_VoiceServerUpdated;
            Gateway.VoiceStateUpdated  += Gateway_VoiceStateUpdated;

            Gateway.RelationShipAdded   += Gateway_RelationShipAdded;
            Gateway.RelationShipRemoved += Gateway_RelationShipRemoved;
            Gateway.RelationShipUpdated += Gateway_RelationShipUpdated;

            Gateway.SessionReplaced += Gateway_SessionReplaced;
            Gateway.InvalidSession  += Gateway_InvalidSession;
            Gateway.GatewayClosed   += Gateway_GatewayClosed;

            if (await ConnectWithRetryAsync(3))
            {
                _analyticsService.Log(Constants.Analytics.Events.Connected);
                Messenger.Default.Send(new ConnectionStatusMessage(ConnectionStatus.Connected));
                Messenger.Default.Register <ChannelNavigateMessage>(this, async m =>
                {
                    if (!m.Guild.IsDM)
                    {
                        await Gateway.SubscribeToGuildLazy(
                            m.Channel.GuildId,
                            new Dictionary <string, IEnumerable <int[]> >
                        {
                            {
                                m.Channel.Model.Id,
                                new List <int[]>
                                {
                                    new[] { 0, 99 },
                                }
                            },
                        });
                    }
                });
                Messenger.Default.Register <GuildNavigateMessage>(this, async m =>
                {
                    if (!m.Guild.IsDM)
                    {
                        if (previousGuildId != null)
                        {
                            await Gateway.SubscribeToGuildLazy(
                                previousGuildId,
                                new Dictionary <string, IEnumerable <int[]> > {
                            });
                        }

                        previousGuildId = m.Guild.Model.Id;
                    }
                    else
                    {
                        previousGuildId = null;
                    }
                });
                Messenger.Default.Register <GatewayRequestGuildMembersMessage>(this, async m =>
                {
                    await Gateway.RequestGuildMembers(m.GuildIds, m.Query, m.Limit, m.Presences, m.UserIds);
                });
                Messenger.Default.Register <GatewayUpdateGuildSubscriptionsMessage>(this, async m =>
                {
                    await Gateway.SubscribeToGuildLazy(m.GuildId, m.Channels, m.Members);
                });
            }

            return(true);
        }
Beispiel #5
0
 public AuthController(DiscordAuthenticator discordAuth, TokenManager tokenManager, IDatabase database)
 {
     _database     = database;
     _discord      = discordAuth;
     _tokenManager = tokenManager;
 }