Interaction logic for MainWindow.xaml
Inheritance: System.Windows.Window
Ejemplo n.º 1
0
        public WindowViewerChat(MainWindow window, Viewer viewer)
        {
            // Set fields
            this.window = window;
            this.viewer = viewer;

            // Init Window and set datacontext to this
            // for databinding to the attached Viewer
            InitializeComponent();
            DataContext = this;

            // Init IrcMessage collection and enable sync between threads
            colViewerMessages = new ObservableCollection<IrcMessage>();
            BindingOperations.EnableCollectionSynchronization(colViewerMessages, colLock);

            // Rather than copying all messages just collect the selected viewers
            // messages to save system resources in case of huge global chat history.
            var viewerMessages = MainWindow.colChatMessages.Where(
                TwitchChatMessage => TwitchChatMessage.Author == viewer.UserName);
            foreach (IrcMessage message in viewerMessages)
            {
                colViewerMessages.Add(message);
            }

            // Set item source for the listView and apply filter
            listViewChat.ItemsSource = colViewerMessages;

            // TODO quick and dirty isFollowing / isSub test
            cbFollowing.IsChecked = viewer.isFollowing();
            cbSubscribed.IsChecked = viewer.isSubscribed();
            using (WebClient wc = new WebClient())
            {
                BitmapImage logo = new BitmapImage();
                logo.BeginInit();
                logo.StreamSource = wc.OpenRead(Utils.GetClient().GetMyChannel().Logo);
                logo.CacheOption = BitmapCacheOption.OnLoad;
                logo.EndInit();
                image.Source = logo;
            }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            discord = new DiscordClient(x =>
            {
                x.AppName = "OakBot";
                x.AppUrl = "http://github.com/ocgineer/OakBot";
                x.AppVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
                x.UsePermissionsCache = false;
            });


            // Initialize instance
            instance = this;

            this.DataContext = this;

            if (!Directory.Exists(Config.AppDataPath)) Directory.CreateDirectory(Config.AppDataPath);
            if (!Directory.Exists(Config.AppDataPath + "\\Webserver")) Directory.CreateDirectory(Config.AppDataPath + "\\Webserver");

            // Initialize config
            Config.GetConfigFromDb();
            LoadConfigToUI();
            DatabaseUtils.LoadAllViewers();
            DatabaseUtils.LoadAllQuotes();

            // Enable sync between threads
            BindingOperations.EnableCollectionSynchronization(colChatMessages, _lockChat);
            BindingOperations.EnableCollectionSynchronization(colViewers, _lockViewers);
            BindingOperations.EnableCollectionSynchronization(colDatabase, _lockDatabase);
            BindingOperations.EnableCollectionSynchronization(colSongs, _lockSongs);
            BindingOperations.EnableCollectionSynchronization(colGiveaways, _lockGiveaways);

            // Create Event for collection changed
            colChatMessages.CollectionChanged += colChatMessages_Changed;

            // Link listViews with collections
            //listViewChat.ItemsSource = colChatMessages;
            listViewViewers.ItemsSource = colViewers;

            // Database listView with filter
            lvViewerDatabase.ItemsSource = colDatabase;
            databaseView = CollectionViewSource.GetDefaultView(lvViewerDatabase.ItemsSource);
            databaseView.Filter = DatabaseFilter;
            lblFilterCnt.Content = databaseView.Cast<Viewer>().Count();

            lvCommands.ItemsSource = colBotCommands;
            lvQuotes.ItemsSource = colQuotes;

            lvSongs.ItemsSource = colSongs;

            lvGiveaways.ItemsSource = colGiveaways;

            // Testing Commands
            colBotCommands.Add(new UserCommand("!test", "Test received!", 30, 0, true));
            colBotCommands.Add(new UserCommand(":yatb", "Yet Another Twitch Bot.", 30, 60, true));
            colBotCommands.Add(new UserCommand("!who", "You are @user@", 0, 0, true));
            colBotCommands.Add(new UserCommand("!block", "@block@ Hello thur!", 0, 0, true));
            colBotCommands.Add(new UserCommand("!followdate", "@user@, you are following since @followdate@.", 0, 0, true));
            colBotCommands.Add(new UserCommand("!followdatetime", "@user@, you are following since @followdatetime@", 0, 0, true));
            colBotCommands.Add(new UserCommand("!vartest", "@var1@ m8", 0, 0, true));
            colBotCommands.Add(new UserCommand("!song", "Currently playing: @song@!", 0, 0, true));
            colBotCommands.Add(new UserCommand("Giveaway", "Just stop...", 0, 0, true, true));
            colBotCommands.Add(new UserCommand("!slap", "@user@ slaps @target@ so hard, he bursts into pieces!", 0, 0, true));

            colSongs.Add(new Song("https://www.youtube.com/watch?v=VEAy700YGuU"));
            colSongs.Add(new Song("https://soundcloud.com/aivisura/steven-universe-strong-in-the-real-way-rebecca-sugar"));

            string message = "Hello and welcome to the first OakBot Alpha ever to be released! I know it took some time, but I also have a private life, you know? ;)\n\n" +
                             "Anyways, this version has not many functions yet, but the ones that are listed here, are fully working.\n\n" +
                             "WORKING:\n" +
                             "- Twitch Chat\n" +
                             "- Commands\n" +
                             "  - Song Requests (the controls are only working for YouTube at the moment)\n" +
                             "  - Quotes\n" +
                             "  - Follow Date\n" +
                             "- Discord Integration (user unspecific commands work without problems, while the user specific ones are yet to be handled)\n" +
                             "- Import from Ankhbot\n" +
                             "- Dashboard and Viewer related stuff\n\n" +
                             "IMPLEMENTED, BUT NOT FULLY WORKING:\n" +
                             "- Giveaways\n" +
                             "- Stream Currency Gain\n" +
                             "- The UI itself\n\n" +
                             "I know, there's much to do, but bear with me. I'm working as hard as I can c:";
            MessageBox.Show(message, "OakBot Alpha 1");

            // BackgroundTask Thread
            BackgroundTasks bg = new BackgroundTasks(60, 120);
            new Thread(new ThreadStart(bg.Run)) { IsBackground = true }.Start();

            // Auto connect
            if (Config.AutoConnectBot)
            {
                ConnectBot();

                // Can only connect if Bot is connected
                if (Config.AutoConnectStreamer)
                {
                    ConnectStreamer();
                }
            }
        }