Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        public JSONContainer ToJSON()
        {
            JSONContainer result = JSONContainer.NewArray();

            foreach (ulong val in hashset)
            {
                result.Add(val);
            }
            return(result);
        }
Пример #6
0
        internal async Task SafePage(int page)
        {
            JSONContainer entryList = JSONContainer.NewArray();

            for (int i = page * PAGESIZE; i < pageStorables.Count && i < (page + 1) * PAGESIZE; i++)
            {
                entryList.Add(pageStorables[i].ToJSON());
            }
            await ResourcesModel.WriteJSONObjectToFile(string.Format("{0}page-{1}.json", StorageDirectory, page), entryList);
        }
Пример #7
0
        public static async Task SaveAll()
        {
            JSONContainer json = JSONContainer.NewArray();

            foreach (MinecraftGuild guild in guilds)
            {
                if (guild.NameAndColorFound)
                {
                    json.Add(guild.ToJSON());
                }
            }
            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.GuildsFilePath, json);
        }
        private JSONContainer ToJSON()
        {
            JSONContainer result = JSONContainer.NewArray();

            foreach (BotVar var in BotVars.Values)
            {
                if (var.Type != BotVarType.Undefined)
                {
                    result.Add(var.ToJSON());
                }
            }
            return(result);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        /// <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);
        }
        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);
            }
        }
Пример #14
0
        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);
            }
        }