コード例 #1
0
        // Buttons & Similar

        public async void LoadServers(object sender, RoutedEventArgs e)
        {
            // if list is empty and you hover over it, then load it, otherwise dont trigger loading
            if (sender is ComboBox && GuildsComboBox.Count != 0)
            {
                return;
            }
            if (_refreshServerList.IsEnabled == false)
            {
                return;
            }
            if (_username.Text == "")
            {
                return;
            }

            this._refreshServerList.IsEnabled = false;

            // read file into a string and deserialize JSON to a type
            config = JsonConvert.DeserializeObject <ConfigData>(File.ReadAllText("config.json"));

            DiscordAPI d      = new DiscordAPI();
            var        guilds = d.GetUserGuildsAsync(config.Token); // this._token.Text

            GuildsComboBox.Clear();
            this._channelComboBox.Items.Clear();
            this._addFolder.IsEnabled = false;

            try
            {
                await foreach (var guild in guilds)
                {
                    ViewGuild itp = new ViewGuild
                    {
                        Image        = new BitmapImage(new Uri(guild.IconUrl)),
                        ImageUrl     = guild.IconUrl,
                        Name         = guild.Name.Length > 20 ? guild.Name.Substring(0, 20) + "..." : guild.Name,
                        FullName     = guild.Name,
                        Id           = guild.Id,
                        IsSelectable = true
                    };

                    GuildsComboBox.Add(itp);
                    GuildsComboBox = OrderViewGuild(GuildsComboBox);

                    // not needed, but visualizing looks cool
                    // await Task.Delay(1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            await Task.Delay(3000); // dont spam this button

            this._refreshServerList.IsEnabled = true;
        }
コード例 #2
0
 public ControlerSender(Telegram.Bot.TelegramBotClient bot)
 {
     modelPerson = new ModelPerson();
     modelGuild  = new ModelGuild();
     modelTavern = new ModelTavern();
     view        = new AView();
     viewTown    = new ViewTown();
     viewGuild   = new ViewGuild();
     this.bot    = bot;
 }
コード例 #3
0
        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
                                {
                                    // ...
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        public void AddFolder(object sender, RoutedEventArgs e)
        {
            //ListBoxItem channelItem = _channelList.SelectedItem as ListBoxItem;
            //string channelID = channelItem.GetValue(idProperty).ToString();

            ViewGuild    serverItem  = _guildComboBox.SelectedItem as ViewGuild;
            ComboBoxItem channelItem = _channelComboBox.SelectedItem as ComboBoxItem;

            string path        = ((Button)sender).CommandParameter.ToString();
            string channelID   = channelItem.GetValue(idProperty).ToString();
            string channelName = channelItem.Content.ToString();

            //chConfig = JsonConvert.DeserializeObject<ChannelConfig>(File.ReadAllText("channels.json"));

            Random r = new Random();
            Color  c = Color.FromRgb((Byte)r.Next(0, 256), (Byte)r.Next(0, 256), (Byte)r.Next(0, 256));


            string color = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");

            if (!chConfig.list.ContainsKey(channelID))
            {
                chConfig.list.Add(channelID, new ChannelConfig.Values()
                {
                    IconUrl        = serverItem.ImageUrl,
                    GuildName      = serverItem.Name,
                    ChannelName    = channelName,
                    GuildId        = serverItem.Id,
                    ChannelId      = channelID,
                    LastMsgChecked = null,
                    SavePath       = path,
                    ImagesSaved    = 0,
                    Color          = color
                });
            }
            else
            {
                MessageBoxImage mbi  = new MessageBoxImage();
                string          desc = $"This action will overwrite channel's save path, however the program will still download new images from where it left off.\nDo you wish to continue?";

                // should be custom messagebox... but meh
                MessageBoxResult result = MessageBox.Show(desc, "This channel already has a folder set-up", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes);

                if (result == MessageBoxResult.No)
                {
                    return;
                }

                config.ChConfig = chConfig;

                chConfig.list[channelID] = new ChannelConfig.Values()
                {
                    IconUrl        = serverItem.ImageUrl,
                    GuildName      = serverItem.Name,
                    ChannelName    = channelName,
                    GuildId        = serverItem.Id,
                    ChannelId      = channelID,
                    LastMsgChecked = chConfig.list[channelID].LastMsgChecked,
                    SavePath       = path,
                    ImagesSaved    = chConfig.list[channelID].ImagesSaved,
                    Color          = color
                };
            }

            config.ChConfig = chConfig;

            UpdateFolderGrid(true);
            RefreshDropboxList();
            myTray.UpdateTrayFolders();

            string json = JsonConvert.SerializeObject(config, Formatting.Indented);

            byte[] fileContent = Encoding.UTF8.GetBytes(json);

            Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup");
        }