/// <summary> /// Removes the appropriate alias for the User in question /// </summary> /// <param name="UserID">UserID of the user who wants to remove an alias</param> /// <param name="Alias">The alias we want to remove.</param> /// <returns></returns> public RemoveSuccess RemoveAlias(ulong UserID, string Alias) { Aliases tempAliases = _aliases; var SuccessLevel = RemoveSuccess.Unknown; bool SuccessfulWrite = false; //Make sure the Alias we want actually exists. We can also check to make sure the user has even added any aliases previously if (UserAliases[UserID] != null) { if (UserAliases[UserID].Contains(Alias, StringComparer.InvariantCultureIgnoreCase)) { UserAliases[UserID].RemoveAt(UserAliases[UserID].FindIndex(n => n.Equals(Alias, StringComparison.InvariantCultureIgnoreCase))); SuccessLevel = RemoveSuccess.Success; } else { SuccessLevel = RemoveSuccess.NoSuchAlias; } } //Attempt to write changes to disk if (SuccessLevel != RemoveSuccess.NoSuchAlias) { SuccessfulWrite = WriteToDisk(); } //Return the outcome if (SuccessfulWrite || SuccessLevel == RemoveSuccess.NoSuchAlias) { return(SuccessLevel); } else { _aliases = tempAliases; return(RemoveSuccess.WriteFailure); } }
/// <summary> /// This is the Controller which modifies the aliases and then writes changes to disk /// </summary> /// <param name="jh">The JSonHelper that does the actual writing</param> public DataController(JsonHelper jh) { this.jh = jh; BotConfig = jh.ReadJsonFile <BotConfig>(@"..\..\BotConfig.json"); _aliases = jh.ReadJsonFile <Aliases>(@"..\..\UserAliases.json") ?? new Aliases(); }