public bool ApplyJSON(JSONContainer json) { macros.Clear(); quotes.Clear(); if (json.TryGetField(JSON_QUOTEID, out QuoteId) && json.TryGetArrayField(JSON_MACROS, out JSONContainer macroList) && json.TryGetArrayField(JSON_QUOTES, out JSONContainer quoteList)) { foreach (JSONField macroField in macroList.Array) { if (macroField.IsObject) { Macro macro = new Macro(); if (macro.ApplyJSON(macroField.Container)) { macros[macro.Identifier] = macro; } } } foreach (JSONField quoteField in quoteList.Array) { if (quoteField.IsObject) { Quote quote = new Quote(); if (quote.ApplyJSON(quoteField.Container)) { quotes[quote.QuoteId] = quote; } } } return(true); } return(false); }
internal static void LoadSettings(ulong guildId, BotVar var) { if (var.IsGeneric) { JSONContainer json = var.Generic; if (json.TryGetField(JSON_ENABLEDEBUG, out JSONContainer debugSettings)) { if (debugSettings.IsArray) { for (int i = 0; i < debugSettings.Array.Count && i < debugLogging.Length; i++) { debugLogging[i] = debugSettings.Array[i].Boolean; } } } json.TryGetField(JSON_MODERATORROLE, out AdminRole); json.TryGetField(JSON_WELCOMINGMESSAGE, out welcomingMessage, welcomingMessage); json.TryGetField(JSON_MUTEROLE, out MuteRole); if (json.TryGetField(JSON_CHANNELINFOS, out JSONContainer guildChannelInfoContainer)) { GuildChannelHelper.FromJSON(guildChannelInfoContainer); } if (json.TryGetArrayField(JSON_AUTOASSIGNROLEIDS, out JSONContainer autoAssignRoles)) { foreach (JSONField idField in autoAssignRoles.Array) { if (idField.IsNumber && !idField.IsFloat && !idField.IsSigned) { EventLogger.AutoAssignRoleIds.Add(idField.Unsigned_Int64); } } } } }
public bool ApplyJSON(JSONContainer json) { if (json.TryGetField(JSON_ALLOWCMDS, out AllowCommands) && json.TryGetField(JSON_ALLOWSHITPOSTING, out AllowShitposting)) { if (json.TryGetArrayField(JSON_ALLOWEDCOLL, out JSONContainer collArray)) { foreach (JSONField field in collArray.Array) { if (field.IsString) { allowedCommandCollections.Add(field.String); } } } return(true); } return(false); }
public bool FromJSON(JSONContainer json) { if (json.TryGetField(JSON_CHANNELID, out ChannelId)) { if (json.TryGetArrayField(JSON_MODENTRIES, out JSONContainer jsonModEntries)) { foreach (JSONField field in jsonModEntries.Array) { if (field.IsObject) { ChannelModerationEntry entry = new ChannelModerationEntry(Parent.GuildId); if (entry.FromJSON(field.Container)) { moderationEntries.Add(entry); } } } } return(true); } return(false); }
private EmbedBuilder GetInaraCMDREmbed(JSONContainer json, string backupName) { EmbedBuilder result; if (json.TryGetArrayField("events", out JSONContainer arrayJSON)) { if (arrayJSON.Array.Count >= 1 && arrayJSON.Array[0].IsObject) { JSONContainer eventJSON = arrayJSON.Array[0].Container; if (eventJSON.TryGetField("eventStatus", out uint eventStatusId)) { eventJSON.TryGetField("eventStatusText", out string eventStatusText); if (eventStatusId == 204) { result = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Name = backupName }, Color = BotCore.ErrorColor, Description = eventStatusText }; } else if (eventJSON.TryGetObjectField("eventData", out JSONContainer cmdrJSON)) { if (cmdrJSON.TryGetField("userName", out string user_name)) { if (eventStatusId == 202 && !user_name.Equals(backupName, StringComparison.OrdinalIgnoreCase) && cmdrJSON.TryGetArrayField("otherNamesFound", out JSONContainer otherNamesArray)) { result = new EmbedBuilder() { Title = "Multiple Results found!", Description = $"{user_name}\n{otherNamesArray.Array.OperationJoinReadonly("\n", field => { return field.String; })}" }; } else { cmdrJSON.TryGetField("inaraURL", out string cmdr_url); result = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Name = $"{user_name}'s Inara Profile", Url = cmdr_url }, Color = BotCore.EmbedColor }; if (cmdrJSON.TryGetField("preferredGameRole", out string cmdr_gamerole)) { result.AddField("Game Role", cmdr_gamerole, true); } if (cmdrJSON.TryGetField("preferredAllegianceName", out string cmdr_allegiance)) { result.AddField("Allegiance", cmdr_allegiance, true); } if (cmdrJSON.TryGetObjectField("commanderSquadron", out JSONContainer squadronJSON)) { squadronJSON.TryGetField("squadronName", out string squadron_name); squadronJSON.TryGetField("squadronMemberRank", out string squadron_rank); squadronJSON.TryGetField("squadronMembersCount", out uint squadron_membercount); if (squadronJSON.TryGetField("inaraURL", out string squadron_link)) { result.AddField("Squadron", $"[{squadron_name}]({squadron_link}) ({squadron_membercount} Members): Rank `{squadron_rank}`", true); } else { result.AddField("Squadron", $"{squadron_name} ({squadron_membercount} Members): Rank `{squadron_rank}`", true); } } } } else { result = InaraErrorEmbed(backupName); } } else { result = InaraErrorEmbed(backupName); } } else { result = InaraErrorEmbed(backupName); } } else { result = InaraErrorEmbed(backupName); } } else { result = InaraErrorEmbed(backupName); } return(result); }
private EmbedBuilder GetSystemInfoEmbed(JSONContainer systemJSON, JSONContainer stationsJSON, JSONContainer trafficJSON, JSONContainer deathsJSON, out List <EmbedFieldBuilder> allStations) { EmbedBuilder systemembed = new EmbedBuilder(); allStations = new List <EmbedFieldBuilder>(); bool stationsFound = false; if (systemJSON.TryGetField("name", out string system_name, string.Empty) && systemJSON.TryGetField("id", out ulong system_id, 0)) { // Gathering Information // Gathering General System information string system_name_link = system_name.Replace(' ', '+'); string security = "Unknown"; if (systemJSON.TryGetObjectField("information", out JSONContainer system_information)) { system_information.TryGetField("security", out security, "Anarchy (Unpopulated)"); } string startype = "Not found"; if (systemJSON.TryGetObjectField("primaryStar", out JSONContainer primaryStar)) { primaryStar.TryGetField("type", out startype, startype); if (systemJSON.TryGetField("isScoopable", out bool scoopable)) { if (!scoopable) { startype += " **(Unscoopable)**"; } } } systemJSON.TryGetField("requirePermit", out bool system_requirepermit, false); systemJSON.TryGetField("permitName", out string system_permit, "Unknown Permit"); // Gathering information about stations StationInfo bestOrbitalLarge = null; StationInfo bestOrbitalMedium = null; StationInfo bestPlanetary = null; List <StationInfo> stationInfos = new List <StationInfo>(); if ((stationsJSON != null) && stationsJSON.TryGetArrayField("stations", out stationsJSON)) { stationsFound = true; foreach (JSONField station in stationsJSON.Array) { StationInfo info = new StationInfo(); if (info.FromJSON(station.Container)) { stationInfos.Add(info); if (info.HasLargePadOrbital) { if (bestOrbitalLarge == null) { bestOrbitalLarge = info; } else if (info.Distance < bestOrbitalLarge.Distance) { bestOrbitalLarge = info; } } if (info.HasMedPadOrbital) { if (bestOrbitalMedium == null) { bestOrbitalMedium = info; } else if (info.Distance < bestOrbitalMedium.Distance) { bestOrbitalMedium = info; } } if (info.IsPlanetary) { if (bestPlanetary == null) { bestPlanetary = info; } else if (info.Distance < bestPlanetary.Distance) { bestPlanetary = info; } } } } } // Getting Information about traffic int traffic_week = -1; int traffic_day = -1; if ((trafficJSON != null) && trafficJSON.TryGetObjectField("traffic", out trafficJSON)) { trafficJSON.TryGetField("week", out traffic_week, -1); trafficJSON.TryGetField("day", out traffic_day, -1); } // Getting Information about CMDR deaths int deaths_week = -1; int deaths_day = -1; if ((deathsJSON != null) && deathsJSON.TryGetObjectField("deaths", out deathsJSON)) { deathsJSON.TryGetField("week", out deaths_week, -1); deathsJSON.TryGetField("day", out deaths_day, -1); } // Constructing message systemembed.Color = BotCore.EmbedColor; systemembed.Title = $"__**System Info for {system_name}**__"; systemembed.Url = $"https://www.edsm.net/en/system/id/{system_id}/name/{system_name_link}"; systemembed.AddField("General Info", $"{(system_requirepermit ? string.Format("**Requires Permit**: {0}\n", system_permit) : string.Empty)}Star Type: {startype}\nSecurity: {security}"); bool provideInfoOnLarge = bestOrbitalLarge != null; bool provideInfoOnMedium = (!provideInfoOnLarge && bestOrbitalMedium != null) || (provideInfoOnLarge && bestOrbitalMedium != null && bestOrbitalLarge.Distance > bestOrbitalMedium.Distance); bool provideInfoOnPlanetary = (!provideInfoOnLarge && bestPlanetary != null) || (provideInfoOnLarge && bestPlanetary != null && bestOrbitalLarge.Distance > bestPlanetary.Distance); if (provideInfoOnLarge) { systemembed.AddField("Closest Orbital Large Pad", bestOrbitalLarge.ToString()); } if (provideInfoOnMedium) { systemembed.AddField("Closest Orbital Medium Pad", bestOrbitalMedium.ToString()); } if (provideInfoOnPlanetary) { systemembed.AddField("Closest Planetary Large Pad", bestPlanetary.ToString()); } if (!provideInfoOnLarge && !provideInfoOnMedium && !provideInfoOnPlanetary) { systemembed.AddField("No Stations in this System!", "- / -"); } if (traffic_day != -1 && traffic_week != -1) { systemembed.AddField("Traffic Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", traffic_week, traffic_day)); } else { systemembed.AddField("No Traffic Report Available", "- / -"); } if (deaths_day != -1 && deaths_week != -1) { systemembed.AddField("CMDR Deaths Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", deaths_week, deaths_day)); } else { systemembed.AddField("No CMDR Deaths Report Available", "- / -"); } if (stationsFound) { foreach (StationInfo stationInfo in stationInfos) { allStations.Add(Macros.EmbedField(stationInfo.Title_NoLink, stationInfo.Services_Link)); } } }
public bool FromJSON(JSONContainer json) { if (json.TryGetField(JSON_USERID, out ulong id)) { UserId = id; } else { return(false); } string timestamp_str; if (json.TryGetField(JSON_BANNEDUNTIL, out timestamp_str)) { if (DateTimeOffset.TryParseExact(timestamp_str, "u", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTimeOffset bannedUntil)) { BannedUntil = bannedUntil; } else { BannedUntil = DateTimeOffset.MaxValue; } } else { BannedUntil = null; } if (json.TryGetField(JSON_MUTEDUNTIL, out timestamp_str)) { if (DateTimeOffset.TryParseExact(timestamp_str, "u", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTimeOffset mutedUntil)) { MutedUntil = mutedUntil; } else { MutedUntil = DateTimeOffset.MaxValue; } if (json.TryGetField(JSON_ROLEIDS, out JSONContainer roleArray)) { rolesPreMute = new List <ulong>(); if (roleArray.IsArray && roleArray.Array != null) { foreach (JSONField arrayField in roleArray.Array) { if (arrayField.IsNumber && !arrayField.IsFloat) { rolesPreMute.Add(arrayField.Unsigned_Int64); } } } } } else { MutedUntil = null; } if (json.TryGetArrayField(JSON_MODENTRIES, out JSONContainer jsonModEntries)) { if (jsonModEntries.Array != null) { foreach (JSONField jsonModEntry in jsonModEntries.Array) { if (jsonModEntry.IsObject) { UserModerationEntry moderationEntry = new UserModerationEntry(Parent.GuildId); if (moderationEntry.FromJSON(jsonModEntry.Container)) { moderationEntries.Add(moderationEntry); } } } } } return(BannedUntil != null || MutedUntil != null || moderationEntries.Count > 0); }