Пример #1
0
        /// <summary>
        /// Add a Command to the Database
        /// </summary>
        /// <param name="AddModel"></param>
        public async void AddCommandAsync(Models.Commands.AddModel AddModel)
        {
            using (var context = new Core.Storage.StorageEntities()) {
                var commandEntry = context.Commands.SingleOrDefault(c => String.Compare(c.Command, AddModel.Command, true) == 0);

                // Command doesnt exist, create new
                if (commandEntry == null)
                {
                    commandEntry = new Core.Storage.Commands {
                        Command        = AddModel.Command,
                        CreatedAt      = DateTime.Now,
                        ModifiedAt     = DateTime.Now,
                        ExecutionRight = (int)AddModel.SelectedUserRight,
                        Text           = AddModel.Text,
                        Cooldown       = AddModel.Cooldown,
                        Count          = 0,
                    };

                    context.Commands.Add(commandEntry);
                }
                else
                {
                    // Command exists; update
                    commandEntry.ExecutionRight = (int)AddModel.SelectedUserRight;
                    commandEntry.ModifiedAt     = DateTime.Now;
                    commandEntry.Text           = AddModel.Text;
                    commandEntry.Cooldown       = AddModel.Cooldown;
                }

                await context.SaveChangesAsync();
            }

            // Load new CommandList
            LoadCommandList();
        }
Пример #2
0
        /// <summary>
        /// Replace all values
        /// </summary>
        /// <param name="command"></param>
        /// <param name="args"></param>
        private void ExecuteCommand(Core.Storage.Commands command, OnChatCommandReceivedArgs args)
        {
            /*
             * User
             * Stack (Count)
             * Channel
             * Time
             * Twitch Info for user
             * Userlevel
             * currency from user
             * */

            // user
            var stringToSend = command.Text.Replace("%user%", args.Command.ChatMessage.Username);

            // currency
            if (stringToSend.Contains("%currency%"))
            {
                var currency = Core.Database.Currency.GetCurrencyFromUser(args.Command.ChatMessage.UserId);
                if (!currency.HasValue)
                {
                    return; // return if this is a currency command and we dont have a currency value
                }
                else
                {
                    stringToSend = stringToSend.Replace("%currency%", currency.Value.ToString());
                }
            }

            // stack
            if (stringToSend.Contains("%stack%"))
            {
                stringToSend = stringToSend.Replace("%stack%", (command.Count + 1).ToString());
                Task.Run(() => Core.Database.Commands.IncreaseCommandCount(command.Command));
            }

            // time
            if (stringToSend.Contains("%time%"))
            {
                stringToSend.Replace("%time%", DateTime.Now.ToString());
            }

            // Twitch related Details
            stringToSend = ReplaceTwitchInformation(stringToSend, args);

            // channel
            if (stringToSend.Contains("%channel%"))
            {
                stringToSend = stringToSend.Replace("%channel%", Core.AivaClient.Instance.Channel);
            }

            // botname
            if (stringToSend.Contains("%botname%"))
            {
                stringToSend = stringToSend.Replace("%botname%", Core.AivaClient.Instance.Username);
            }


            Core.AivaClient.Instance.AivaTwitchClient.SendMessage(stringToSend);
        }