public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); JSONContainer eventChannelsJSON = JSONContainer.NewObject(); foreach (var channel in EventLogChannels) { eventChannelsJSON.TryAddField(channel.Key.ToString(), channel.Value); } result.TryAddField("EventLogChannels", eventChannelsJSON); JSONContainer userModChannelsJSON = JSONContainer.NewObject(); foreach (var channel in UserModLogChannels) { userModChannelsJSON.TryAddField(channel.Key.ToString(), channel.Value); } result.TryAddField("UserModLogChannels", userModChannelsJSON); JSONContainer channelModChannelsJSON = JSONContainer.NewObject(); foreach (var channel in ChannelModLogChannels) { channelModChannelsJSON.TryAddField(channel.Key.ToString(), channel.Value); } result.TryAddField("ChannelModLogChannels", channelModChannelsJSON); return(result); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_QUOTEID, QuoteId); JSONContainer macroList = JSONContainer.NewArray(); foreach (Macro macro in macros.Values) { macroList.Add(macro.ToJSON()); } result.TryAddField(JSON_MACROS, macroList); JSONContainer quoteList = JSONContainer.NewArray(); foreach (Quote quote in quotes.Values) { quoteList.Add(quote.ToJSON()); } result.TryAddField(JSON_QUOTES, quoteList); return(result); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_USERID, UserId); if (BannedUntil.HasValue) { result.TryAddField(JSON_BANNEDUNTIL, BannedUntil.Value.ToString("u")); } if (MutedUntil.HasValue) { result.TryAddField(JSON_MUTEDUNTIL, MutedUntil.Value.ToString("u")); if ((rolesPreMute != null) && rolesPreMute.Count > 0) { JSONContainer rolespremute = JSONContainer.NewArray(); foreach (ulong roleId in rolesPreMute) { rolespremute.Add(roleId); } result.TryAddField(JSON_ROLEIDS, rolespremute); } } if (moderationEntries.Count > 0) { JSONContainer jsonModEntries = JSONContainer.NewArray(); foreach (UserModerationEntry entry in moderationEntries) { jsonModEntries.Add(entry.ToJSON()); } result.TryAddField(JSON_MODENTRIES, jsonModEntries); } return(result); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_GUILDID, GuildId); result.TryAddField(JSON_CHANNELID, ChannelId); return(result); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_RED, C.R); result.TryAddField(JSON_GREEN, C.G); result.TryAddField(JSON_BLUE, C.B); return(result); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_ID, Id); result.TryAddField(JSON_ALLOWCOMMANDS, AllowCommands); result.TryAddField(JSON_ALLOWSHITPOSTING, AllowShitposting); return(result); }
internal static JSONContainer Inara_Base_Request(string inara_appname, string inara_apikey) { JSONContainer result = JSONContainer.NewObject(); JSONContainer header = JSONContainer.NewObject(); header.TryAddField("appName", inara_appname); header.TryAddField("appVersion", new Version(1, 8).ToString()); header.TryAddField("isDeveloped", true); header.TryAddField("APIkey", inara_apikey); result.TryAddField("header", header); return(result); }
internal JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_ID, Identifier); result.TryAddField(JSON_TYPE, (int)Type); switch (Type) { case BotVarType.UInt64: result.TryAddField(JSON_VALUE, UInt64); break; case BotVarType.Int64: result.TryAddField(JSON_VALUE, Int64); break; case BotVarType.Float64: result.TryAddField(JSON_VALUE, Float64); break; case BotVarType.String: result.TryAddField(JSON_VALUE, String); break; case BotVarType.Bool: result.TryAddField(JSON_VALUE, Bool); break; case BotVarType.Generic: result.TryAddField(JSON_VALUE, Generic); break; } return(result); }
private static JSONContainer getFieldsJSON(IEmbed embed) { JSONContainer fieldsJSON = JSONContainer.NewArray(); foreach (Discord.EmbedField embedField in embed.Fields) { JSONContainer fieldJSON = JSONContainer.NewObject(); fieldJSON.TryAddField(NAME, embedField.Name); fieldJSON.TryAddField(VALUE, embedField.Value); fieldJSON.TryAddField(INLINE, embedField.Inline); fieldsJSON.Add(fieldJSON); } return(fieldsJSON); }
private static void checkAddStringField(string value, JSONContainer json, string identifier) { if (!string.IsNullOrEmpty(value)) { json.TryAddField(identifier, value); } }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_ID, QuoteId); result.TryAddField(JSON_MESSAGE_ID, MessageId); result.TryAddField(JSON_CHANNEL_NAME, ChannelName); result.TryAddField(JSON_CONTENT, MessageContent); result.TryAddField(JSON_IMAGE_URL, ImageURL); result.TryAddField(JSON_AUTHOR_ID, AuthorId); result.TryAddField(JSON_AUTHOR_NAME, AuthorName); result.TryAddField(JSON_TIMESTAMP, Timestamp.ToString("u")); result.TryAddField(JSON_CHANNEL_ID, ChannelId); result.TryAddField(JSON_GUILD_ID, GuildId); return(result); }
internal async Task SafePages(int listLocation = -1) { JSONContainer idSettings = JSONContainer.NewObject(); idSettings.TryAddField(JSON_ID, nextId); await ResourcesModel.WriteJSONObjectToFile(StorageDirectory + ID_SAFEFILE, idSettings); if (listLocation == -1) { foreach (string file in Directory.GetFiles(StorageDirectory)) { if (file.Contains("page-") && file.EndsWith(".json")) { File.Delete(file); } } int pages = (pageStorables.Count - 1) / PAGESIZE; for (int i = 0; i <= pages; i++) { await SafePage(i); } } else { int page = listLocation / PAGESIZE; await SafePage(page); } }
public JSONContainer ToJSON() { JSONContainer json = JSONContainer.NewObject(); json.TryAddField(JSON_CHANNELID, ChannelId); if (moderationEntries.Count > 0) { JSONContainer jsonModEntries = JSONContainer.NewArray(); foreach (ChannelModerationEntry entry in moderationEntries) { jsonModEntries.Add(entry.ToJSON()); } json.TryAddField(JSON_MODENTRIES, jsonModEntries); } return(json); }
public JSONContainer ToJSON() { JSONContainer json = JSONContainer.NewObject(); json.TryAddField(JSON_ALLOWCMDS, AllowCommands); json.TryAddField(JSON_ALLOWSHITPOSTING, AllowShitposting); if (allowedCommandCollections.Count > 0) { JSONContainer collArray = JSONContainer.NewArray(); foreach (string coll in allowedCommandCollections) { collArray.Add(coll); } json.TryAddField(JSON_ALLOWEDCOLL, collArray); } return(json); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_ACTIVE, Active); result.TryAddField(JSON_CHANNELIDS, ChannelId); result.TryAddField(JSON_ROLEID, RoleId); result.TryAddField(JSON_CAPTAINID, CaptainId); result.TryAddField(JSON_FOUNDINGTIMESTAMP, FoundingTimestamp.ToString("u")); JSONContainer memberIdList = JSONContainer.NewArray(); foreach (ulong id in MemberIds) { memberIdList.Add(id); } result.TryAddField(JSON_MEMBERIDS, memberIdList); JSONContainer mateIdList = JSONContainer.NewArray(); foreach (ulong id in MateIds) { mateIdList.Add(id); } result.TryAddField(JSON_MATEIDS, mateIdList); return(result); }
private static JSONContainer getAuthor(IEmbed embed) { EmbedAuthor author = embed.Author.Value; JSONContainer authorJSON = JSONContainer.NewObject(); if (!string.IsNullOrEmpty(author.Name)) { authorJSON.TryAddField(NAME, author.Name); } if (!string.IsNullOrEmpty(author.IconUrl)) { authorJSON.TryAddField(ICON_URL, author.IconUrl); } if (!string.IsNullOrEmpty(author.Url)) { authorJSON.TryAddField(URL, author.Url); } return(authorJSON); }
/// <summary> /// Saves all settings to appdata/locallow/Ciridium Wing Bot/Settings.json /// </summary> internal static void SaveSettings() { JSONContainer json = JSONContainer.NewObject(); JSONContainer debugSettings = JSONContainer.NewArray(); foreach (bool b in debugLogging) { debugSettings.Add(b); } json.TryAddField(JSON_MODERATORROLE, AdminRole); json.TryAddField(JSON_ENABLEDEBUG, debugSettings); json.TryAddField(JSON_WELCOMINGMESSAGE, welcomingMessage); json.TryAddField(JSON_MUTEROLE, MuteRole); json.TryAddField(JSON_CHANNELINFOS, GuildChannelHelper.ToJSON()); JSONContainer autoAssignRoleIds = JSONContainer.NewArray(); foreach (var roleId in EventLogger.AutoAssignRoleIds) { autoAssignRoleIds.Add(roleId); } json.TryAddField(JSON_AUTOASSIGNROLEIDS, autoAssignRoleIds); BotVarManager.GlobalBotVars.SetBotVar("YNBsettings", json); }
/// <summary> /// Constructs a <see cref="JSONContainer"/> from a content string and an embed /// </summary> /// <param name="messageContent">Message Content of the message</param> /// <param name="embed">Embed of the message</param> public static JSONContainer GetJSONFromMessageContentAndEmbed(string messageContent, IEmbed embed) { JSONContainer json = JSONContainer.NewObject(); checkAddStringField(messageContent, json, MESSAGECONTENT); if (embed != null) { JSONContainer embedJSON = getEmbedJSON(embed); json.TryAddField(EMBED, embedJSON); } return(json); }
internal static JSONContainer Inara_CMDR_Profile(string cmdrName) { if (inara_apikey == null || inara_appname == null) { return(null); } else { JSONContainer result = Inara_Base_Request(inara_appname, inara_apikey); JSONContainer singleevent = JSONContainer.NewObject(); singleevent.TryAddField("eventName", "getCommanderProfile"); singleevent.TryAddField("eventTimestamp", DateTime.UtcNow.ToString("s") + "Z"); JSONContainer eventdata = JSONContainer.NewObject(); eventdata.TryAddField("searchName", cmdrName); singleevent.TryAddField("eventData", eventdata); JSONContainer events = JSONContainer.NewArray(); events.Add(singleevent); result.TryAddField("events", events); return(result); } }
public JSONContainer ToJSON() { JSONContainer json = JSONContainer.NewObject(); json.TryAddField(JSON_MODTYPE, (uint)Type); json.TryAddField(JSON_CHANNELID, ChannelId); json.TryAddField(JSON_ACTORID, ActorId); json.TryAddField(JSON_TIMESTAMP, Timestamp.ToString("u")); json.TryAddField(JSON_CHANNELNAME, ChannelName); json.TryAddField(JSON_ACTORNAME, ActorName); if (!string.IsNullOrEmpty(Info)) { json.TryAddField(JSON_INFO, Info); } return(json); }
/// <summary> /// Converts currently stored configs and ids into a json data object /// </summary> /// <returns>json data</returns> public static JSONContainer ToJSON() { JSONContainer json = JSONContainer.NewObject(); json.TryAddField(JSON_DEBUGCHANNELID, DebugChannelId); json.TryAddField(JSON_WELCOMINGCHANNELID, WelcomingChannelId); json.TryAddField(JSON_ADMINCOMMANDUSAGELOGCHANNELID, AdminCommandUsageLogChannelId); json.TryAddField(JSON_ADMINNOTIFICATIONCHANNELID, AdminNotificationChannelId); json.TryAddField(JSON_INTERACTIVEMESSAGECHANNELID, InteractiveMessagesChannelId); json.TryAddField(JSON_GUILDCATEGORYID, GuildCategoryId); JSONContainer channelInfoArray = JSONContainer.NewArray(); foreach (GuildChannelConfiguration channelInfo in channelConfigs.Values) { channelInfoArray.Add(channelInfo.ToJSON()); } json.TryAddField(JSON_CHANNELINFOS, channelInfoArray); return(json); }
public JSONContainer ToJSON() { JSONContainer result = JSONContainer.NewObject(); result.TryAddField(JSON_TYPE, (int)Type); result.TryAddField(JSON_TIMESTAMP, Timestamp.ToString("u")); if (!string.IsNullOrEmpty(Reason)) { result.TryAddField(JSON_DESCR, Reason); } if (!string.IsNullOrEmpty(Info)) { result.TryAddField(JSON_INFO, Info); } result.TryAddField(JSON_ACTORID, ActorId); result.TryAddField(JSON_ACTORNAME, ActorName); return(result); }
public static void GetJSONFromMessageContentAndEmbed(string messageContent, IEmbed embed, out JSONContainer json) { json = JSONContainer.NewObject(); if (messageContent != null) { json.TryAddField(MESSAGECONTENT, messageContent); } if (embed != null) { JSONContainer embedJSON = JSONContainer.NewObject(); // Insert TITLE, DESCRIPTION, TITLE_URL, TIMESTAMP if (!string.IsNullOrEmpty(embed.Title)) { embedJSON.TryAddField(TITLE, embed.Title); } if (!string.IsNullOrEmpty(embed.Description)) { embedJSON.TryAddField(DESCRIPTION, embed.Description); } if (!string.IsNullOrEmpty(embed.Url)) { embedJSON.TryAddField(URL, embed.Url); } if (embed.Timestamp != null) { embedJSON.TryAddField(TIMESTAMP, embed.Timestamp?.ToString("u")); } // Insert AUTHOR if (embed.Author != null) { EmbedAuthor author = embed.Author.Value; JSONContainer authorJSON = JSONContainer.NewObject(); if (!string.IsNullOrEmpty(author.Name)) { authorJSON.TryAddField(NAME, author.Name); } if (!string.IsNullOrEmpty(author.IconUrl)) { authorJSON.TryAddField(ICON_URL, author.IconUrl); } if (!string.IsNullOrEmpty(author.Url)) { authorJSON.TryAddField(URL, author.Url); } embedJSON.TryAddField(AUTHOR, authorJSON); } // Insert THUMBNAIL, IMAGE if (embed.Thumbnail != null) { if (!string.IsNullOrEmpty(embed.Thumbnail.Value.Url)) { JSONContainer thumbnailJSON = JSONContainer.NewObject(); thumbnailJSON.TryAddField(URL, embed.Thumbnail.Value.Url); embedJSON.TryAddField(THUMBNAIL, thumbnailJSON); } } if (embed.Image != null) { if (!string.IsNullOrEmpty(embed.Image.Value.Url)) { JSONContainer imagJSON = JSONContainer.NewObject(); imagJSON.TryAddField(URL, embed.Image.Value.Url); embedJSON.TryAddField(IMAGE, imagJSON); } } // Insert Color if (embed.Color != null) { if (embed.Color.Value.RawValue != 0) { embedJSON.TryAddField(COLOR, embed.Color.Value.RawValue); } } // Insert Footer if (embed.Footer != null) { EmbedFooter footer = embed.Footer.Value; JSONContainer footerJSON = JSONContainer.NewObject(); if (!string.IsNullOrEmpty(footer.Text)) { footerJSON.TryAddField(TEXT, footer.Text); } if (!string.IsNullOrEmpty(footer.IconUrl)) { footerJSON.TryAddField(ICON_URL, footer.IconUrl); } embedJSON.TryAddField(FOOTER, footerJSON); } // Insert Fields if ((embed.Fields != null) && embed.Fields.Length > 0) { JSONContainer fieldsJSON = JSONContainer.NewArray(); foreach (Discord.EmbedField embedField in embed.Fields) { JSONContainer fieldJSON = JSONContainer.NewObject(); fieldJSON.TryAddField(NAME, embedField.Name); fieldJSON.TryAddField(VALUE, embedField.Value); fieldJSON.TryAddField(INLINE, embedField.Inline); fieldsJSON.Add(fieldJSON); } embedJSON.TryAddField(FIELDS, fieldsJSON); } json.TryAddField(EMBED, embedJSON); } }
public JSONContainer ToJSON() { JSON.TryAddField(JSON_ID, Identifier); return JSON; }
private static JSONContainer getEmbedJSON(IEmbed embed) { JSONContainer embedJSON = JSONContainer.NewObject(); // Insert TITLE, DESCRIPTION, TITLE_URL, TIMESTAMP checkAddStringField(embed.Title, embedJSON, TITLE); checkAddStringField(embed.Description, embedJSON, DESCRIPTION); checkAddStringField(embed.Url, embedJSON, URL); if (embed.Timestamp != null) { embedJSON.TryAddField(TIMESTAMP, embed.Timestamp?.ToString("u")); } // Insert AUTHOR if (embed.Author != null) { JSONContainer authorJSON = getAuthor(embed); embedJSON.TryAddField(AUTHOR, authorJSON); } // Insert THUMBNAIL, IMAGE if (embed.Thumbnail != null) { if (!string.IsNullOrEmpty(embed.Thumbnail.Value.Url)) { JSONContainer thumbnailJSON = JSONContainer.NewObject(); thumbnailJSON.TryAddField(URL, embed.Thumbnail.Value.Url); embedJSON.TryAddField(THUMBNAIL, thumbnailJSON); } } if (embed.Image != null) { if (!string.IsNullOrEmpty(embed.Image.Value.Url)) { JSONContainer imagJSON = JSONContainer.NewObject(); imagJSON.TryAddField(URL, embed.Image.Value.Url); embedJSON.TryAddField(IMAGE, imagJSON); } } // Insert Color if (embed.Color != null) { embedJSON.TryAddField(COLOR, embed.Color.Value.RawValue); } // Insert Footer if (embed.Footer != null) { JSONContainer footerJSON = getFooterJSON(embed); embedJSON.TryAddField(FOOTER, footerJSON); } // Insert Fields if ((embed.Fields != null) && embed.Fields.Length > 0) { JSONContainer fieldsJSON = getFieldsJSON(embed); embedJSON.TryAddField(FIELDS, fieldsJSON); } return(embedJSON); }