public static bool FullyBooted() { if (hasBooted) { return(hasBooted); } if (serverID == 0 && discordClient.Guilds.Count == 1) { serverID = discordClient.Guilds.ElementAt(0).Id; serverName = Utility.GetServer().Name; BotConfiguration.SetSetting("Server.ID", serverID); BotConfiguration.SetSetting("Server.Name", serverName); BotConfiguration.SaveSettings(); } if (Utility.GetServer() != null) { if (Utility.GetServer().Channels.Count != 0) // Why this is neccesary is beyond me, but I'll take it. { hasBooted = true; Logging.Log(Logging.LogType.BOT, "Bot has fully booted."); } } return(hasBooted); }
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, "")); }