// Misc. public async void TryToken() { try { DiscordAPI d = new DiscordAPI(); JToken res = await d.GetSelfAsync(config.Token); _pfp.Source = new BitmapImage(GetAvatarUri(res)); _preUsername.Text = "Logged in as:"; _username.Text = res["username"].ToString(); this._refreshServerList.IsEnabled = true; } catch { _accountComboBox.IsDropDownOpen = true; //_username.Text = "[Invalid token!]"; } }
private async void OnServerSelected(object sender, RoutedEventArgs e) { if (!(_guildComboBox.SelectedItem is ViewGuild vg)) { return; } this._addFolder.IsEnabled = false; IReadOnlyList <Channel> channels; try { string guildID = ((ViewGuild)_guildComboBox.SelectedItem).Id; DiscordAPI d = new DiscordAPI(); channels = await d.GetGuildChannelsAsync(config.Token, guildID); // this._token.Text } catch { MessageBox.Show("Something went wrong (token?)"); return; } ComboBox combobox = this._channelComboBox; combobox.Items.Clear(); // order by .ParentId, aka by category List <Channel> channelList = channels.ToList().OrderBy(x => x.ParentId).ToList(); foreach (var ch in channelList) { if (ch.Type != ChannelType.GuildTextChat) { // skip, we list only text channels continue; } ComboBoxItem item = new ComboBoxItem(); ChannelConfig.Values _chCnf; chConfig.list.TryGetValue(ch.Id, out _chCnf); if (_chCnf.ChannelId == ch.Id) { Color color = (Color)ColorConverter.ConvertFromString(_chCnf.Color); item.BorderBrush = new SolidColorBrush(color); item.Foreground = new SolidColorBrush(color); //item.Background = new SolidColorBrush(color); //item.IsEnabled = false; } item.BorderThickness = new Thickness(5, 0, 0, 0); string prefix = ch.ParentId != null?channelList.Find(x => x.Id == ch.ParentId).Name + " > " : ""; item.Content = $"{prefix}{ch.Name}"; item.Selected += OnChannelSelected; item.SetValue(idProperty, ch.Id); combobox.Items.Add(item); } }
public async void DetectTokens(object sender, RoutedEventArgs e) { // if list is empty and you hover over it, then load it, otherwise dont trigger loading if (sender is ComboBox && AccountsComboBox.Count != 0) { return; } AccountsComboBox.Clear(); try { DiscordAPI d = new DiscordAPI(); JToken res = await d.GetSelfAsync(config.Token); ViewGuild itp = new ViewGuild { Image = new BitmapImage(GetAvatarUri(res)), Name = res["username"].ToString(), Id = config.Token, IsSelectable = true }; AccountsComboBox.Add(itp); } catch { ViewGuild itp = new ViewGuild { Image = new BitmapImage(new Uri(@"pack://*****:*****@"[A-Za-z0-9_\./\\-]*")) { foreach (Capture capture in match.Captures) { // theoretically it should be (capture.Value.Length == 88 || capture.Value.Length == 59) // but I don't trust it with the whole 2FA etc, so we will take more chances, doesnt matter for the user if (capture.Value.Length < 95 && capture.Value.Length > 50) { // don't attempt to use this token if its already in the config if (AccountsComboBox.Where(cb => cb.Id == capture.Value).Count() > 0) { continue; } try { DiscordAPI d = new DiscordAPI(); JToken res = await d.GetSelfAsync(capture.Value); ViewGuild itp = new ViewGuild { Image = new BitmapImage(GetAvatarUri(res)), Name = res["username"].ToString(), Id = capture.Value, IsSelectable = true }; AccountsComboBox.Add(itp); } catch { // ... } } } } } } }