Example #1
0
        /// <summary>
        /// Remove the selected command command from list and database
        /// </summary>
        public static void RemoveTimer(Storage.Timers timer)
        {
            using (var context = new Core.Storage.StorageEntities()) {
                context.Timers.Remove(timer);

                context.SaveChanges();
            }
        }
Example #2
0
        /// <summary>
        /// Remove the selected command command from list and database
        /// </summary>
        public void RemoveCommand()
        {
            using (var context = new Core.Storage.StorageEntities()) {
                context.Commands.Remove(SelectedCommand);

                context.SaveChanges();
            }

            LoadCommandList();
        }
Example #3
0
        /// <summary>
        /// Increate the stack from the command
        /// </summary>
        /// <param name="commandName"></param>
        public static void IncreaseCommandCount(string commandName)
        {
            using (var context = new Core.Storage.StorageEntities()) {
                var command = context.Commands.SingleOrDefault(c => String.Compare(commandName, c.Command, true) == 0);

                if (command != null)
                {
                    command.Count++;

                    context.SaveChanges();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Store Message in Database
        /// </summary>
        /// <param name="AddModel"></param>
        private static void StoreIndatabase(Models.Chat.Messages AddModel)
        {
            using (var context = new Core.Storage.StorageEntities()) {
                context.Chat.Add(
                    new Core.Storage.Chat {
                    TwitchID    = AddModel.TwitchID,
                    ChatMessage = AddModel.Message,
                    Timestamp   = AddModel.TimeStamp,
                });

                context.SaveChanges();
            }
        }
Example #5
0
        /// <summary>
        /// Fires when a chat command is received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            using (var context = new Core.Storage.StorageEntities()) {
                var command = context.Commands.SingleOrDefault(c => String.Compare(e.Command.Command, c.Command, true) == 0);

                if (command != null)
                {
                    // can user execute command?
                    if (CanUserExecuteCommand(e.Command.ChatMessage.UserType, command.ExecutionRight))
                    {
                        // check if cooldown is over 0
                        if (command.Cooldown.HasValue && command.Cooldown > 0)
                        {
                            if (command.LastExecution.HasValue)
                            {
                                // last execution is not empty
                                var nextTime = command.LastExecution.Value.AddMinutes(command.Cooldown.Value);

                                // if next execution time <= now
                                if (nextTime <= DateTime.Now)
                                {
                                    ExecuteCommand(command, e);
                                    command.LastExecution = DateTime.Now;

                                    context.SaveChanges();
                                }
                            }
                            else
                            {
                                // last execution is empty - start command
                                ExecuteCommand(command, e);
                                command.LastExecution = DateTime.Now;
                            }
                        }
                        else
                        {
                            // cooldown has no value or is < 0
                            ExecuteCommand(command, e);
                            command.LastExecution = DateTime.Now;
                        }
                    }
                }
            }
        }