Example #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IChatConnectionService ccs, IWebSocketEventService wse,
                             ITwitchPubSubService pss)
        {
            //Title = "OakBot - YATB";
            Title = "Kelex";

            // Set dependency injection references
            _ccs = ccs;
            _wse = wse;
            _pss = pss;

            // Register for chat connection service events
            _ccs.Authenticated += _ccs_Authenticated;
            _ccs.Disconnected  += _ccs_Disconnected;

            // Load settings
            var loaded = BinaryFile.ReadEncryptedBinFile("LoginSettings");

            if (loaded != null && loaded is MainSettings)
            {
                // Success, set last saved settings
                _mainSettings = (MainSettings)loaded;

                // Set loaded settings values through properties for UI
                ChannelName    = _mainSettings.Channel;
                BotUsername    = _mainSettings.BotUsername;
                CasterUsername = _mainSettings.CasterUsername;
                IsUsingSSL     = _mainSettings.UseSecureConnection;

                // Set bot credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.BotOauthKey))
                {
                    IsBotOauthSet   = true;
                    _botCredentials = new TwitchCredentials(
                        _mainSettings.BotUsername, _mainSettings.BotOauthKey, false);
                }

                // Set caster credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.CasterOauthKey))
                {
                    IsCasterOauthSet   = true;
                    _casterCredentials = new TwitchCredentials(
                        _mainSettings.CasterUsername, _mainSettings.CasterOauthKey, true);

                    // Try connection PubSub
                    _pss.Connect(_casterCredentials);
                }
            }
            else
            {
                // Failure, load defaults
                _mainSettings = new MainSettings();
            }

            // Start WebSocket Event Service
            _wse.StartService(1337, "oakbotapitest");
        }
Example #2
0
        public AutoCastModel(IChatConnectionService chat)
        {
            // Register to the shutdown notification
            Messenger.Default.Register <NotificationMessage>(this, "shutdown", (msg) => { _vm_OnShutdown(); });

            // Set references to services
            _chat = chat; // Twitch chat service

            // Register to events
            _chat.RawMessageReceived += _chat_RawMessageReceived;
        }
Example #3
0
        public BDayModel(IChatConnectionService chat)
        {
            // Register to the shutdown notification
            Messenger.Default.Register <NotificationMessage>(this, "shutdown", (msg) => { _vm_OnShutdown(); });

            // Set references to services
            this.chat = chat; // Twitch chat service

            // Register to events
            this.chat.RawMessageReceived += _chat_RawMessageReceived;

            //Create Svc and open Connection to DB
            svc = new DBService.BDayService(DBFILE);
        }
        public ChatterDatabaseService(IChatConnectionService chatService)
        {
            // This service depends on chat connection service to expand functionality.
            // Also it lets this service opperate independently without any control needed.
            _chatService = chatService;
            _chatService.ChannelJoined       += _chatService_ChannelJoined;
            _chatService.Disconnected        += _chatService_Disconnected;
            _chatService.ChatMessageReceived += _chatService_ChatMessageReceived;

            // Initialize chatters list
            _chatters         = new List <ChatterAPI>();
            _lockChattersList = new object();

            // Initialize timer to refresh chatters list from API
            _timerRefreshChatters          = new System.Timers.Timer(60000);
            _timerRefreshChatters.Elapsed += _timerRefreshChatters_Elapsed;
        }
Example #5
0
        public GiveawaysViewModel(IChatConnectionService chatService, IWebSocketEventService wsEventService)
        {
            // Store references to services
            _chatService    = chatService;
            _wsEventService = wsEventService;

            // Subscribe to system messages
            Messenger.Default.Register <bool>(this, "SystemChatConnectionChanged", (status) => SystemChatConnectionChanged(status));

            // Use one seeded pseudo-random generator for all giveaway modules
            _rnd = new Random();

            // Set giveaway modules
            _modules = new ObservableCollection <GiveawayViewModel>
            {
                new GiveawayViewModel(1, _rnd, _chatService, _wsEventService),
                new GiveawayViewModel(2, _rnd, _chatService, _wsEventService),
                new GiveawayViewModel(3, _rnd, _chatService, _wsEventService)
            };
        }
Example #6
0
        public ConsoleViewModel(IChatConnectionService chatService, IChatterDatabaseService databaseService)
        {
            // Dependancy Injection
            _chatService     = chatService;
            _databaseService = databaseService;

            // Initialize collections
            _chatMessages = new LimitedObservableCollection <TwitchChatMessage>(500);
            _chatters     = new ObservableCollection <ChatterAPI>();
            _chatAccounts = new ObservableCollection <ITwitchAccount>();

            _lockChatters = new object();

            // Register for chatService event
            _chatService.Connected           += _chatService_Connected;
            _chatService.Authenticated       += _chatService_Authenticated;
            _chatService.Disconnected        += _chatService_Disconnected;
            _chatService.ChatMessageReceived += _chatService_ChatMessageReceived;

            // Register for databaseService event
            _databaseService.ChattersListUpdated += _databaseService_ChattersListUpdated;
        }
Example #7
0
        public SubWelcomeModel(IChatConnectionService chat)
        {
            // Register to the shutdown notification
            Messenger.Default.Register <NotificationMessage>(this, "shutdown", (msg) => { _vm_OnShutdown(); });

            // Set references to services
            this.chat = chat; // Twitch chat service



            // Register to events
            this.chat.RawMessageReceived += _chat_RawMessageReceived;


            // Initialize Timers
            trainWarn.Elapsed += TrainWarnElapsedAction;
            trainEnd.Elapsed  += TrainEndElapsedAction;

            raid.Elapsed += RaidElapsedAction;


            //Create Svc and open Connection to DB
            svc = new DBService.SubService(DBFILE);

            if (!Directory.Exists(TRAINFILE))
            {
                Directory.CreateDirectory(TRAINFILE);
                File.WriteAllText(TRAINFILE + "\\HighestTrain.txt", trainHigh.ToString());
            }

            // Load in Saved Highest Sub Train
            var tr = new StreamReader(TRAINFILE + "\\HighestTrain.txt");

            trainHigh = Convert.ToInt32(tr.ReadLine());
            tr.Close();
        }
Example #8
0
        /// <summary>
        /// Initializes a new Giveaway module, seperate from other modules.
        /// </summary>
        /// <param name="id">Id of the module, must be unique and can't be lower than 1.</param>
        /// <param name="rndGen">A preseeded pseudo random generator to be used in the module.</param>
        /// <param name="ccs">Chat Service to receive and send messages.</param>
        /// <param name="wes">WebSocket Event Service to push out giveaway events to websocket.</param>
        public GiveawayViewModel(int id, Random rndGen, IChatConnectionService ccs, IWebSocketEventService wes)
        {
            // Store references
            _moduleId       = id;
            _rndGen         = rndGen;
            _chatService    = ccs;
            _wsEventService = wes;

            // Initialize collections and lists
            _listEntries        = new ObservableCollection <GiveawayEntry>();
            _listWinners        = new ObservableCollection <GiveawayEntry>();
            _listMessagesWinner = new ObservableCollection <TwitchChatMessage>();

            // Initialize MediaPlayer
            _mediaPlayer = new MediaPlayer();

            // Set initial timestamps and spans
            _timestampOpened       = new DateTime(0);
            _timestampClosed       = new DateTime(0);
            _timestampDraw         = new DateTime(0);
            _elapsedOpenTime       = new TimeSpan(0);
            _elapsedNoResponseTime = new TimeSpan(0);
            _elapsedInterval       = new TimeSpan(0, 0, 1);

            // Initialize timers
            _timerOpen = new Timer()
            {
                AutoReset = false
            };
            _timerOpen.Elapsed += _TimerOpen_Elapsed;
            _timerResponse      = new Timer()
            {
                AutoReset = false
            };
            _timerResponse.Elapsed += _TimerResponse_Elapsed;
            _timerElapsed           = new Timer(_elapsedInterval.TotalMilliseconds);
            _timerElapsed.Elapsed  += _TimerElapsed_Elapsed;
            _timerElapsed.Start();

            // Set a 'winner' to display
            _selectedWinner = new GiveawayEntry {
                DisplayName = "WINNER"
            };
            _WinnerHasReplied = true;

            // Load in previous saved settings else use new default settings
            var loaded = BinaryFile.ReadBinFile($"GivewawayModule{ID}");

            if (loaded != null && loaded is GiveawayModuleSettings)
            {
                // Success, set last saved settings and set previous winners
                _moduleSettings = (GiveawayModuleSettings)loaded;
                if (_moduleSettings.SavedWinnersList?.Count > 0)
                {
                    _listWinners = new ObservableCollection <GiveawayEntry>(_moduleSettings.SavedWinnersList);
                }
            }
            else
            {
                // Failure, load defaults
                _moduleSettings = new GiveawayModuleSettings();
            }

            // Transmit WS event
            _wsEventService.SendRegisteredEvent("GIVEAWAY_DONE",
                                                new GiveawayWebsocketEventBase(_moduleId));

            // Register to service events and system broadcast messages
            _chatService.ChatMessageReceived += _chatService_ChatMessageReceived;
        }