/// <inheritdoc/> public async Task <bool> Login([NotNull] string email, [NotNull] string password) { BasicRestFactory restFactory = new BasicRestFactory(); LoginService = restFactory.GetLoginService(); LoginResult result; try { result = await LoginService.Login(new LoginRequest() { Email = email, Password = password }); } catch { return(false); } _accessToken = result.Token; await _cacheService.Persistent.Roaming.SetValueAsync(Constants.Cache.Keys.AccessToken, (object)_accessToken); return(await Login()); }
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); }
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); }
/// <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); }