Beispiel #1
0
        public Task <Result> Execute(SocketUserMessage e, string expression, object input)
        {
            List <BotConfiguration.Entry> toModify = BotConfiguration.RegexSearchEntries(expression);
            IEnumerable <string>          names    = toModify.Select(x => x.name);

            Program.messageControl.SendMessage(e.Channel, names.ToArray().Singlify(), false, "```");
            int succesful = 0;

            Program.messageControl.AskQuestion(e.Channel.Id, "Confirm edit of these configuration entries?", delegate() {
                foreach (string entry in names)
                {
                    object current      = BotConfiguration.GetSetting(entry, null, default(object));
                    object possibleJSON = null;
                    try {
                        possibleJSON = JsonConvert.DeserializeObject(current.ToString());
                    } catch { }

                    object newObject = null;
                    try {
                        newObject = Convert.ChangeType(input, current.GetType());
                        BotConfiguration.SetSetting(entry, newObject, false);
                        succesful++;
                    } catch (Exception exception) {
                        Logging.Log(exception);
                    }
                }

                BotConfiguration.SaveSettings();
                Program.messageControl.SendMessage(e, $"Succesfully edited {succesful} out of {toModify.Count} entries.", false);

                List <BotConfiguration.Entry> reloaded = new List <BotConfiguration.Entry> ();
                foreach (var entry in toModify)
                {
                    if (!reloaded.Contains(entry))
                    {
                        entry.ReloadConfigurables();
                        reloaded.Add(entry);
                    }
                }
            });

            return(TaskResult(null, ""));
        }