private async void Button_Click(object sender, RoutedEventArgs e) { if (RedIcon.Opacity == 1) { return; } if (GreenIcon.Opacity == 1) { App.NavigateToGuild(DisplayedInvite.Guild.Id); } if (JoinIcon.Opacity == 1) { GreenIcon.Opacity = 0; RedIcon.Opacity = 0; JoinIcon.Opacity = 0; ChannelName.Opacity = 0; GuildName.Opacity = 0; Loading.Opacity = 1; //DisplayedInvite = await RESTCalls.AcceptInvite(InviteCode); I guess this doesn't work or something... await RESTCalls.AcceptInvite(InviteCode); DisplayedInvite = await RESTCalls.GetInvite(InviteCode); DisplayedInvite.Uses++; LoadInvite(true); } }
/// <summary> /// When the invite is clicked /// </summary> private async void Button_Click(object sender, RoutedEventArgs e) { // Move to already joined server if (Status == InviteStatus.AlreadyJoined) { App.SelectGuildChannel(DisplayedInvite.Guild.Id, DisplayedInvite.Channel.Id); } // Accept invite and rerender else if (Status == InviteStatus.Canjoin) { Loading.Fade(1, 200).Start(); GuildImage.Fade(0.4f).Start(); await RESTCalls.AcceptInvite(InviteCode); DisplayedInvite = await RESTCalls.GetInvite(InviteCode); LoadInvite(true); } // Draft a message mentioning the Inviter else if (Status == InviteStatus.Invalid && ChannelName.Visibility == Visibility.Visible) { App.SelectGuildChannel(App.CurrentGuildId, App.CurrentChannelId, "@" + DisplayedInvite.Inviter.Username + "#" + DisplayedInvite.Inviter.Discriminator); } }
private async void LoadInvite(bool ForceJoin) { InviteCode = InviteCode.Replace(">\n", ""); InviteCode = InviteCode.Replace("http://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.gg/", ""); InviteCode = InviteCode.Replace("http://discord.gg/", ""); InviteCode = InviteCode.Replace("https://discordapp.com/invite/", ""); InviteCode = InviteCode.Replace("http://discordapp.com/invite/", ""); GreenIcon.Opacity = 0; RedIcon.Opacity = 0; JoinIcon.Opacity = 0; ChannelName.Opacity = 0; GuildName.Opacity = 0; Loading.Opacity = 1; try { DisplayedInvite = await RESTCalls.GetInvite(InviteCode); Loading.Fade(0, 200).Start(); GuildName.Visibility = Visibility.Visible; TimeSpan timeDiff = TimeSpan.FromSeconds(1); if (DisplayedInvite.CreatedAt != null && DisplayedInvite.MaxAge != 0) { var creationTime = DateTime.Parse(DisplayedInvite.CreatedAt); timeDiff = TimeSpan.FromSeconds(DisplayedInvite.MaxAge - DateTime.Now.Subtract(creationTime).TotalSeconds); } GuildName.Text = DisplayedInvite.Guild.Name; GuildName.Fade(1, 350).Start(); ChannelName.Fade(1, 200).Start(); if (LocalState.Guilds.ContainsKey(DisplayedInvite.Guild.Id) || ForceJoin) { GreenIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteJoined") + " " + DisplayedInvite.Channel.Name; return; } if (DisplayedInvite.MaxUses != 0 && DisplayedInvite.MaxUses <= DisplayedInvite.Uses) { ChannelName.Text = App.GetString("/Controls/InviteMaxUses"); RedIcon.Fade(1, 200).Start(); return; } if (timeDiff.TotalSeconds > 0) { JoinIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteJoin") + " " + DisplayedInvite.Channel.Name; } else { RedIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteExpired"); } } catch { Loading.Fade(0, 200).Start(); GuildName.Fade(1, 350).Start(); ChannelName.Fade(1, 200).Start(); RedIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteInvalid"); GuildName.Visibility = Visibility.Collapsed; } }
/// <summary> /// /// </summary> /// <param name="Join">False if just rendering the embed</param> private async void LoadInvite(bool Join) { GuildName.Foreground = (SolidColorBrush)Application.Current.Resources["InvertedBG"]; // Trim link prefix InviteCode = InviteCode.Replace(">\n", ""); InviteCode = InviteCode.Replace("http://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.gg/", ""); InviteCode = InviteCode.Replace("http://discord.gg/", ""); InviteCode = InviteCode.Replace("https://discordapp.com/invite/", ""); InviteCode = InviteCode.Replace("http://discordapp.com/invite/", ""); // Show loading GuildName.Opacity = 0; Loading.Opacity = 1; try { // Get invite DisplayedInvite = await RESTCalls.GetInvite(InviteCode); if (DisplayedInvite == null) { InvalidInvite(InvalidReason.Default); return; } // Show invite Loading.Fade(0, 200).Start(); GuildName.Visibility = Visibility.Visible; // Get expiration time TimeSpan timeDiff = TimeSpan.FromSeconds(1); if (DisplayedInvite.CreatedAt != null && DisplayedInvite.MaxAge != 0) { var creationTime = DateTime.Parse(DisplayedInvite.CreatedAt); timeDiff = TimeSpan.FromSeconds(DisplayedInvite.MaxAge - DateTime.Now.Subtract(creationTime).TotalSeconds); } // Return an error if the guild is null if (DisplayedInvite.Guild == null) { InvalidInvite(InvalidReason.Default); return; } // Display the guild image if (DisplayedInvite.Guild?.Icon != null) { GuildImage.Visibility = Visibility.Visible; GuildImageBrush.ImageSource = new BitmapImage(new Uri("https://cdn.discordapp.com/icons/" + DisplayedInvite.Guild.Id + "/" + DisplayedInvite.Guild.Icon + ".png")); } else { GuildImage.Visibility = Visibility.Collapsed; } // Setup channel details (invites are technically to a channel) ChannelName.Text = "#" + DisplayedInvite.Channel.Name; ChannelName.Fade(0.6f, 200).Start(); // Guild details visibility GuildName.Fade(1, 100).Start(); GuildImage.Fade(1, 300).Start(); // Member values MemberCounters.Visibility = Visibility.Visible; MemberCounters.Fade(1, 400).Start(); onlineCounter.Text = DisplayedInvite.OnlineCount + " online"; offlineCounter.Text = DisplayedInvite.MemberCount + " members"; // Return error if the user has already joined if (LocalState.Guilds.ContainsKey(DisplayedInvite.Guild.Id) || Join) { GuildName.Text = App.GetString("/Controls/InviteJoined") + " " + DisplayedInvite.Guild.Name; Status = InviteStatus.AlreadyJoined; return; } // Return error if the invite uses has already been maxed if (DisplayedInvite.MaxUses != 0 && DisplayedInvite.MaxUses <= DisplayedInvite.Uses) { InvalidInvite(InvalidReason.MaxUses); return; } // Return error if the invite has timed out if (timeDiff.TotalSeconds > 0) { GuildName.Text = App.GetString("/Controls/InviteJoin") + " " + DisplayedInvite.Guild.Name; Status = InviteStatus.Canjoin; } else { InvalidInvite(InvalidReason.Default); } } catch { // Something went wrong, return an error InvalidInvite(InvalidReason.Default); } }