├── LICENSE ├── README.MD ├── babel └── index.babel ├── css └── style.css ├── index.html ├── index.pug ├── js └── index.js ├── license.txt └── sass └── style.sass /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Cog-Creators 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | ![embed](http://i.imgur.com/GemcoBW.png) 2 | 3 | # discord-embed-sandbox 4 | 5 | > Web-based sandbox for Discord Embeds with code generation 6 | 7 | [Click here to open](https://cog-creators.github.io/discord-embed-sandbox/) 8 | 9 | This tool can help you get a grip on Discord Embeds (a topic some people are struggling with), it provides a simple ui to construct a message you want, as well as a realtime preview. 10 | 11 | You can also see the code needed to generate the same Embed inside your own cog in real time, so you can see how different fields and values affect the end result, which is pretty neat, if you ak me ;) 12 | 13 | Hope you like it! 14 | --- 15 | ## Under MIT License 16 | -------------------------------------------------------------------------------- /babel/index.babel: -------------------------------------------------------------------------------- 1 | $(document).ready(() => { 2 | let switches = { 3 | title: false, 4 | url: false, 5 | icon: false, 6 | }; 7 | 8 | let fields = 1; 9 | 10 | let source = ``; 11 | 12 | let embed = { 13 | title: 'Embed title (required)', 14 | author: { 15 | name: '', 16 | url: '', 17 | icon: '' 18 | }, 19 | description: '', 20 | url: '', 21 | thumb_url: '', 22 | color: '', 23 | fields: [{ 24 | } 25 | ], 26 | footer: '' 27 | }; 28 | 29 | function resetEmbed() { 30 | $('.embed-inner').html(''); 31 | $('.embed-footer').remove(); 32 | $('.embed-thumb').remove(); 33 | } 34 | 35 | function updateEmbed(embed) { 36 | resetEmbed(); 37 | 38 | // add basic embed generation to source 39 | source = `embed=discord.Embed(`; 40 | 41 | if (embed.url) { 42 | $('.embed-inner').append(`
${embed.title}
`); 43 | 44 | // update source 45 | source += `title="${embed.title}", url='${embed.url}'`; 46 | } else { 47 | $('.embed-inner').append(`
${embed.title}
`); 48 | 49 | // update source 50 | source += `title="${embed.title}"`; 51 | } 52 | 53 | if (embed.description) { 54 | $('.embed-inner').append(`
${embed.description}
`); 55 | 56 | // update source 57 | source += `, description="${embed.description}"`; 58 | } 59 | 60 | if (embed.color) { 61 | $('.side-colored').css('background-color', embed.color); 62 | 63 | // update source 64 | source += `, color=0x${embed.color.substr(1)}`; 65 | } 66 | 67 | // finished the basic setup 68 | source += `)\n`; 69 | 70 | if (embed.author.name) { 71 | // add author to source 72 | source += `embed.set_author(`; 73 | 74 | $('.embed-title').before(`
${embed.author.name}
`); 75 | 76 | // update source 77 | source += `name="${embed.author.name}"${embed.author.url && `, url='${embed.author.url}'`}`; 78 | if (embed.author.icon) { 79 | $('.embed-author-name').before(``); 80 | 81 | // update source 82 | source += `, icon_url='${embed.author.icon}'`; 83 | } 84 | 85 | // finish author 86 | source += `)\n`; 87 | } 88 | 89 | if (embed.thumb_url) { 90 | // add thumbnail 91 | source += `embed.set_thumbnail(` 92 | 93 | $('.card.embed .card-block').append(``); 94 | $('.embed-thumb').height($('.embed-thumb')[0].naturalHeight); 95 | 96 | // update source 97 | source += `url='${embed.thumb_url}'`; 98 | 99 | // finish thumbnail 100 | source += `)\n`; 101 | } 102 | 103 | if (embed.fields.length > 0) { 104 | $('.embed-inner').append(`
`); 105 | } 106 | 107 | for (let field of embed.fields) { 108 | $('.embed-inner .fields').append(` 109 |
110 |
${field.name}
111 |
${field.value}
112 |
113 | `); 114 | 115 | // add field 116 | source += `embed.add_field(name="${field.name}", value="${field.value}", inline=${(field.inline && 'True') || 'False'})\n`; 117 | } 118 | 119 | if (embed.footer) { 120 | $('.card.embed').append(``); 121 | 122 | // add footer 123 | source += `embed.set_footer(text="${embed.footer}")\n`; 124 | } 125 | 126 | // add send function 127 | source += `await self.bot.say(embed=embed)\n`; 128 | 129 | // code 130 | $('.source').text(source); 131 | hljs.highlightBlock($('.source')[0]); 132 | } 133 | 134 | // run once on startup 135 | updateEmbed(embed); 136 | 137 | function generateInputFields(fields) { 138 | // generate inputs for fields 139 | $('.input-fields').html(''); 140 | for (let i = 0; i < fields; i++) { 141 | $('.input-fields').append(`
142 |
143 | 144 |
145 |
146 | 147 |
148 |
149 |
150 | 153 |
154 |
155 |
156 | 157 |
158 |
`) 159 | $(`#field-${i}-name`).keyup(() => { 160 | updateFieldName(i, $(`#field-${i}-name`).val()) 161 | }); 162 | 163 | $(`#field-${i}-value`).keyup(() => { 164 | updateFieldValue(i, $(`#field-${i}-value`).val()) 165 | }); 166 | 167 | $(`#field-${i}-inline`).click(() => { 168 | updateFieldInline(i, $(`#field-${i}-inline`).is(':checked')); 169 | }) 170 | 171 | $(`#field-${i}-delete`).click((e) => { 172 | e.preventDefault(); 173 | deleteField(i); 174 | }); 175 | } 176 | $('.input-fields').append(``); 177 | $('#add-field').click((e) => { 178 | e.preventDefault(); 179 | addField(); 180 | }) 181 | } 182 | 183 | generateInputFields(fields); 184 | 185 | function updateFieldName(index, value) { 186 | embed.fields[index].name = value; 187 | updateEmbed(embed); 188 | } 189 | 190 | function updateFieldValue(index, value) { 191 | embed.fields[index].value = value; 192 | updateEmbed(embed); 193 | } 194 | 195 | function updateFieldInline(index, value) { 196 | embed.fields[index].inline = value; 197 | updateEmbed(embed); 198 | } 199 | 200 | function deleteField(index) { 201 | embed.fields.splice(index,1); 202 | updateEmbed(embed); 203 | fields -= 1; 204 | generateInputFields(fields); 205 | } 206 | 207 | function addField() { 208 | embed.fields.push({inline: true}); 209 | fields += 1; 210 | generateInputFields(fields); 211 | } 212 | 213 | function updateTitle(value) { 214 | embed.title = value || ''; 215 | updateEmbed(embed); 216 | } 217 | 218 | function updateUrl(value) { 219 | embed.url = value || ''; 220 | updateEmbed(embed); 221 | } 222 | 223 | function updateThumb(value) { 224 | embed.thumb_url = value || false; 225 | updateEmbed(embed); 226 | } 227 | 228 | function updateDescription(value) { 229 | embed.description = value || ''; 230 | updateEmbed(embed); 231 | } 232 | 233 | function updateColor(value) { 234 | embed.color = value || false; 235 | updateEmbed(embed); 236 | } 237 | 238 | function updateAuthorName(value) { 239 | embed.author.name = value || ''; 240 | updateEmbed(embed); 241 | } 242 | 243 | function updateAuthorUrl(value) { 244 | embed.author.url = value || ''; 245 | updateEmbed(embed); 246 | } 247 | 248 | function updateAuthorIcon(value) { 249 | embed.author.icon = value || ''; 250 | updateEmbed(embed); 251 | } 252 | 253 | function updateFooter(value) { 254 | embed.footer = value || ''; 255 | updateEmbed(embed); 256 | } 257 | 258 | $('#form').submit((e) => { 259 | e.preventDefault(); 260 | }); 261 | 262 | // checking helpers 263 | function addWarning(item, type, message) { 264 | item.addClass('form-control-warning'); 265 | item.removeClass('form-control-success'); 266 | item.parent().addClass('has-warning'); 267 | item.parent().removeClass('has-success'); 268 | if ($(`#${type}-feedback`).length === 0) { 269 | item.after(`
${message}
`); 270 | } 271 | } 272 | 273 | function addSuccess(item, type) { 274 | item.removeClass('form-control-warning'); 275 | item.addClass('form-control-success'); 276 | item.parent().addClass('has-success'); 277 | item.parent().removeClass('has-warning'); 278 | $(`#${type}-feedback`).remove(); 279 | } 280 | 281 | $('#title').keyup(() => { 282 | let item = $('#title'); 283 | let title = item.val(); 284 | 285 | // preform checks 286 | if (title.length === 0) { 287 | addWarning(item, 'title', 'title cannot be empty'); 288 | } else { 289 | addSuccess(item, 'title'); 290 | // update 291 | updateTitle(title); 292 | } 293 | 294 | }); 295 | 296 | $('#url').keyup(() => { 297 | let item = $('#url'); 298 | let url = item.val(); 299 | 300 | if (url.substr(0,4) !== 'http' && url.length !== 0) { 301 | addWarning(item, 'url', 'not a valid url'); 302 | } else { 303 | addSuccess(item, 'url'); 304 | // update 305 | updateUrl(url); 306 | } 307 | 308 | 309 | }); 310 | 311 | $('#icon').keyup(() => { 312 | let item = $('#icon'); 313 | let icon = item.val(); 314 | 315 | if (icon.substr(0,4) !== 'http' && icon.length !== 0) { 316 | addWarning(item, 'icon', 'not a valid url'); 317 | } else { 318 | addSuccess(item, 'icon'); 319 | // update 320 | updateThumb(icon); 321 | } 322 | }); 323 | 324 | $('#description').keyup(() => { 325 | let item = $('#description'); 326 | let description = item.val(); 327 | addSuccess(item, 'description'); 328 | // update 329 | updateDescription(description); 330 | }); 331 | 332 | $('#color').change(() => { 333 | updateColor($('#color').val()); 334 | }); 335 | 336 | $('#author_name').keyup(() => { 337 | let item = $('#author_name'); 338 | let author_name = item.val(); 339 | 340 | addSuccess(item, 'author_name'); 341 | // update 342 | updateAuthorName(author_name); 343 | }); 344 | 345 | $('#author_url').keyup(() => { 346 | let item = $('#author_url'); 347 | let author_url = item.val(); 348 | 349 | if (author_url.substr(0,4) !== 'http' && author_url.length !== 0) { 350 | addWarning(item, 'author_url', 'not a valid url'); 351 | } else { 352 | addSuccess(item, 'author_url'); 353 | // update 354 | updateAuthorUrl(author_url); 355 | } 356 | }); 357 | 358 | $('#author_icon').keyup(() => { 359 | let item = $('#author_icon'); 360 | let author_icon = item.val(); 361 | 362 | if (author_icon.substr(0,4) !== 'http' && author_icon.length !== 0) { 363 | addWarning(item, 'author_icon', 'not a valid url'); 364 | } else { 365 | addSuccess(item, 'author_icon'); 366 | // update 367 | updateAuthorIcon(author_icon); 368 | } 369 | }); 370 | 371 | $('#footer').keyup(() => { 372 | let item = $('#footer'); 373 | let footer = item.val(); 374 | 375 | addSuccess(item, 'footer'); 376 | // update 377 | updateFooter(footer); 378 | }); 379 | }) -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | a.patreon-link { 2 | display: -webkit-box; 3 | display: -ms-flexbox; 4 | display: flex; 5 | box-sizing: border-box; 6 | width: 100%; 7 | height: auto; 8 | z-index: 10; 9 | text-decoration: none; 10 | } 11 | 12 | .badge-container { 13 | width: 100%; 14 | display: -webkit-box; 15 | display: -ms-flexbox; 16 | display: flex; 17 | -webkit-box-orient: vertical; 18 | -webkit-box-direction: normal; 19 | -ms-flex-direction: column; 20 | flex-direction: column; 21 | padding: 5px 10px; 22 | background: rgba(0, 0, 0, 0.5); 23 | border: 1px solid rgba(255, 255, 255, 0.5); 24 | text-align: center; 25 | } 26 | .badge-container .badge-icon { 27 | background: url("https://s3.amazonaws.com/patreon_public_assets/toolbox/patreon_white.png") center center no-repeat; 28 | background-size: contain; 29 | width: 100%; 30 | height: 20px; 31 | } 32 | .badge-container .badge-text { 33 | font-family: "Lato", sans-serif; 34 | font-size: 12px; 35 | padding: 2px; 36 | color: #fff; 37 | } 38 | .badge-container .badge-text.badge-text-bottom { 39 | position: relative; 40 | top: -2px; 41 | } 42 | 43 | .preview { 44 | background: #36393e; 45 | display: -webkit-box; 46 | display: -ms-flexbox; 47 | display: flex; 48 | box-orient: vertical; 49 | -webkit-box-orient: vertical; 50 | -webkit-box-direction: normal; 51 | -ms-flex-direction: column; 52 | flex-direction: column; 53 | } 54 | 55 | .wrapper { 56 | display: -webkit-box; 57 | display: -ms-flexbox; 58 | display: flex; 59 | max-width: 520px; 60 | } 61 | 62 | .container { 63 | margin-top: 50px; 64 | } 65 | 66 | .side-colored { 67 | width: 4px; 68 | border-radius: 3px 0 0 3px; 69 | background: #4f545c; 70 | } 71 | 72 | .embed { 73 | border-radius: 0 3px 3px 0; 74 | background: rgba(46, 48, 54, 0.3); 75 | border-color: rgba(46, 48, 54, 0.6); 76 | display: -webkit-box; 77 | display: -ms-flexbox; 78 | display: flex; 79 | padding: 8px 10px; 80 | color: rgba(255, 255, 255, 0.6); 81 | font-size: 14px; 82 | } 83 | .embed .card-block { 84 | padding: 0; 85 | display: -webkit-box; 86 | display: -ms-flexbox; 87 | display: flex; 88 | margin-bottom: 10px; 89 | } 90 | .embed a { 91 | color: #0096cf; 92 | } 93 | .embed img.embed-thumb { 94 | max-height: 80px; 95 | max-width: 80px; 96 | border-radius: 3px; 97 | -ms-flex-negative: 0; 98 | flex-shrink: 0; 99 | width: auto; 100 | -o-object-fit: contain; 101 | object-fit: contain; 102 | margin-left: 20px; 103 | } 104 | .embed .embed-footer { 105 | font-size: 12px; 106 | } 107 | .embed .embed-footer span { 108 | color: rgba(255, 255, 255, 0.6); 109 | } 110 | .embed .embed-inner .embed-title { 111 | color: #fff; 112 | } 113 | .embed .embed-inner .embed-author { 114 | display: -webkit-box; 115 | display: -ms-flexbox; 116 | display: flex; 117 | -webkit-box-align: center; 118 | -ms-flex-align: center; 119 | align-items: center; 120 | margin-bottom: 5px; 121 | } 122 | .embed .embed-inner .embed-author img.embed-author-icon { 123 | margin-right: 9px; 124 | width: 20px; 125 | height: 20px; 126 | -o-object-fit: contain; 127 | object-fit: contain; 128 | border-radius: 50%; 129 | } 130 | .embed .embed-inner .embed-author .embed-author-name { 131 | display: inline-block; 132 | font-weight: 600; 133 | font-size: 14px; 134 | color: #fff !important; 135 | } 136 | .embed .embed-inner .fields { 137 | display: -webkit-box; 138 | display: -ms-flexbox; 139 | display: flex; 140 | -ms-flex-wrap: wrap; 141 | flex-wrap: wrap; 142 | -webkit-box-orient: horizontal; 143 | -webkit-box-direction: normal; 144 | -ms-flex-direction: row; 145 | flex-direction: row; 146 | box-lines: miltiple; 147 | margin-top: -10px; 148 | } 149 | .embed .embed-inner .fields .field { 150 | -webkit-box-flex: 0; 151 | -ms-flex: 0; 152 | flex: 0; 153 | box-flex: 1; 154 | padding-top: 10px; 155 | max-width: 506px; 156 | min-width: 100%; 157 | } 158 | .embed .embed-inner .fields .field.inline { 159 | box-flex: 1; 160 | -webkit-box-flex: 1; 161 | -ms-flex: 1; 162 | flex: 1; 163 | min-width: 150px; 164 | -ms-flex-preferred-size: auto; 165 | flex-basis: auto; 166 | } 167 | .embed .embed-inner .fields .field .field-name { 168 | color: #fff; 169 | font-size: 14px; 170 | margin-bottom: 4px; 171 | font-weight: 600; 172 | } 173 | .embed .embed-inner .fields .field .field-value { 174 | color: rgba(255, 255, 255, 0.7); 175 | font-size: 14px; 176 | font-weight: 500; 177 | line-height: 1.1em; 178 | white-space: pre-wrap; 179 | margin-top: 6px; 180 | word-wrap: break-word; 181 | } 182 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Discord Embed Generator 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
like what you see?
23 |
24 |
support me
25 |
26 |
27 |
28 |
29 |
30 |
Embed Editor
31 |
32 |
33 |
34 | 38 |
39 |
40 | 41 | 42 |
43 |
44 | 45 |
46 |
47 | 48 |
49 |
50 | 51 | 52 |
53 |
54 | 55 | 56 |
57 |
58 | 59 | 60 |
61 |
62 | 63 |
64 |
65 | 66 |
67 |
68 | 69 |
70 |
71 |
72 | 73 | 74 |
75 |
76 |
77 |
78 |
79 |

80 |
81 |
82 |
Embed Preview
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |

95 |
96 |
97 |
Python code
98 |
99 |
100 |
101 |
102 |
103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /index.pug: -------------------------------------------------------------------------------- 1 | link(href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet") 2 | a.patreon-link(href="https://patreon.com/orels1" target="_blank") 3 | .badge-container 4 | .badge-text like what you see? 5 | .badge-icon 6 | .badge-text.badge-text-bottom support me 7 | 8 | .container 9 | .col-md-10.offset-md-1 10 | .card-deck 11 | .card 12 | .card-header Embed Editor 13 | .card-block 14 | form#form 15 | .form-group 16 | label Basic settings 17 | input#title.form-control(type="text", placeholder="title") 18 | .form-group 19 | input#description.form-control(type="text", placeholder="description") 20 | .form-group 21 | input#url.form-control(type="text", placeholder="url") 22 | .form-group 23 | label Color 24 | input#color.form-control(type="color") 25 | .form-group 26 | label Thumbnail settings 27 | input#icon.form-control(type="text", placeholder="icon") 28 | .form-group 29 | label Author settings 30 | input#author_name.form-control(type="text", placeholder="author name") 31 | .form-group 32 | input#author_url.form-control(type="text", placeholder="author link") 33 | .form-group 34 | input#author_icon.form-control(type="text", placeholder="author icon") 35 | .form-group 36 | label Fields 37 | .input-fields 38 | .form-group 39 | label Footer settings 40 | input#footer.form-control(type="text", placeholder="footer text") 41 | br/ 42 | .col-md-8.offset-md-2 43 | .card 44 | .card-header Embed Preview 45 | .card-block.preview 46 | .wrapper 47 | .side-colored 48 | .card.embed 49 | .card-block 50 | .embed-inner 51 | br/ 52 | .col-md-10.offset-md-1 53 | .card 54 | .card-header Python code 55 | .card-block 56 | pre 57 | code.python.source 58 | -------------------------------------------------------------------------------- /js/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | $(document).ready(function () { 4 | var converter = new showdown.Converter(); 5 | 6 | var switches = { 7 | title: false, 8 | url: false, 9 | icon: false, 10 | useVars: false 11 | }; 12 | 13 | var fields = 1; 14 | 15 | var source = ''; 16 | 17 | var embed = { 18 | title: '', 19 | author: { 20 | name: '', 21 | url: '', 22 | icon: '' 23 | }, 24 | description: '', 25 | url: '', 26 | thumb_url: '', 27 | color: '', 28 | fields: [{}], 29 | footer: '' 30 | }; 31 | 32 | function resetEmbed() { 33 | $('.embed-inner').html(''); 34 | $('.embed-footer').remove(); 35 | $('.embed-thumb').remove(); 36 | } 37 | 38 | function updateEmbed(embed) { 39 | resetEmbed(); 40 | 41 | // add basic embed generation to source 42 | source = 'embed=discord.Embed('; 43 | 44 | if (embed.url) { 45 | $('.embed-inner').append('
' + embed.title + '
'); 46 | 47 | // update source 48 | if (switches.useVars) { 49 | source += 'title=' + embed.title + ', url=' + embed.url; 50 | } else { 51 | source += 'title="' + embed.title + '", url="' + embed.url + '"'; 52 | } 53 | } else if (embed.title.length === 0) { 54 | source += ""; 55 | } else { 56 | $('.embed-inner').append('
' + embed.title + '
'); 57 | 58 | // update source 59 | if (switches.useVars) { 60 | source += 'title=' + embed.title; 61 | } else { 62 | source += 'title="' + embed.title + '"'; 63 | } 64 | 65 | } 66 | 67 | if (embed.description) { 68 | $('.embed-inner').append('
' + converter.makeHtml(embed.description) + '
'); 69 | 70 | if (embed.title.length > 0 || embed.url.length > 0) { 71 | source += ', ' 72 | } 73 | 74 | // update source 75 | if (switches.useVars) { 76 | source += 'description=' + embed.description; 77 | } else { 78 | source += 'description="' + embed.description + '"'; 79 | } 80 | } 81 | 82 | if (embed.color) { 83 | $('.side-colored').css('background-color', embed.color); 84 | 85 | if (embed.title.length > 0 || embed.url.length > 0) { 86 | source += ', ' 87 | } 88 | 89 | // update source 90 | source += 'color=0x' + embed.color.substr(1); 91 | } 92 | 93 | // finished the basic setup 94 | source += ')\n'; 95 | 96 | if (embed.author.name) { 97 | // add author to source 98 | source += 'embed.set_author('; 99 | 100 | $('.embed-title').before('
' + embed.author.name + '
'); 101 | 102 | // update source 103 | if (switches.useVars) { 104 | source += 'name=' + embed.author.name; 105 | } else { 106 | source += 'name="' + embed.author.name + '"'; 107 | } 108 | 109 | if(embed.author.url) { 110 | source += ', '; 111 | 112 | if (switches.useVars) { 113 | source += 'url=' + embed.author.url; 114 | } else { 115 | source += 'url="' + embed.author.url + '"'; 116 | } 117 | } 118 | 119 | if (embed.author.icon) { 120 | $('.embed-author-name').before(''); 121 | 122 | source += ', '; 123 | 124 | // update source 125 | if (switches.useVars) { 126 | source += 'icon_url=' + embed.author.icon; 127 | } else { 128 | source += 'icon_url="' + embed.author.icon + '"'; 129 | } 130 | } 131 | 132 | // finish author 133 | source += ')\n'; 134 | } 135 | 136 | if (embed.thumb_url) { 137 | // add thumbnail 138 | source += 'embed.set_thumbnail('; 139 | 140 | $('.card.embed .card-block').append(''); 141 | $('.embed-thumb').height($('.embed-thumb')[0].naturalHeight); 142 | 143 | // update source 144 | if (switches.useVars) { 145 | source += 'url=' + embed.thumb_url; 146 | } else { 147 | source += 'url="' + embed.thumb_url + '"'; 148 | } 149 | 150 | // finish thumbnail 151 | source += ')\n'; 152 | } 153 | 154 | if (embed.fields.length > 0) { 155 | $('.embed-inner').append('
'); 156 | } 157 | 158 | for (var _iterator = embed.fields, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { 159 | var _ref; 160 | 161 | if (_isArray) { 162 | if (_i >= _iterator.length) break; 163 | _ref = _iterator[_i++]; 164 | } else { 165 | _i = _iterator.next(); 166 | if (_i.done) break; 167 | _ref = _i.value; 168 | } 169 | 170 | var field = _ref; 171 | 172 | $('.embed-inner .fields').append('\n
\n
' + field.name + '
\n
' + converter.makeHtml(field.value) + '
\n
\n '); 173 | 174 | // add field 175 | if (switches.useVars) { 176 | source += 'embed.add_field(name=' + field.name + ', value=' + field.value + ', inline=' + (field.inline && 'True' || 'False') + ')\n'; 177 | } else { 178 | source += 'embed.add_field(name="' + field.name + '", value="' + field.value + '", inline=' + (field.inline && 'True' || 'False') + ')\n'; 179 | } 180 | } 181 | 182 | if (embed.footer) { 183 | $('.card.embed').append(''); 184 | 185 | // add footer 186 | if (switches.useVars) { 187 | source += 'embed.set_footer(text=' + embed.footer + ')\n'; 188 | } else { 189 | source += 'embed.set_footer(text="' + embed.footer + '")\n'; 190 | } 191 | } 192 | 193 | // add send function 194 | source += 'await ctx.send(embed=embed)\n'; 195 | 196 | // code 197 | $('.source').text(source); 198 | hljs.highlightBlock($('.source')[0]); 199 | } 200 | 201 | // run once on startup 202 | updateEmbed(embed); 203 | 204 | function generateInputFields(fields) { 205 | // generate inputs for fields 206 | $('.input-fields').html(''); 207 | 208 | var _loop = function _loop(i) { 209 | $('.input-fields').append('
\n
\n \n
\n
\n \n
\n
\n
\n \n
\n
\n
\n \n
\n
'); 210 | $('#field-' + i + '-name').keyup(function () { 211 | updateFieldName(i, $('#field-' + i + '-name').val()); 212 | }); 213 | 214 | $('#field-' + i + '-value').keyup(function () { 215 | updateFieldValue(i, $('#field-' + i + '-value').val()); 216 | }); 217 | 218 | $('#field-' + i + '-inline').click(function () { 219 | updateFieldInline(i, $('#field-' + i + '-inline').is(':checked')); 220 | }); 221 | 222 | $('#field-' + i + '-delete').click(function (e) { 223 | e.preventDefault(); 224 | deleteField(i); 225 | }); 226 | }; 227 | 228 | for (var i = 0; i < fields; i++) { 229 | _loop(i); 230 | } 231 | $('.input-fields').append(''); 232 | $('#add-field').click(function (e) { 233 | e.preventDefault(); 234 | addField(); 235 | }); 236 | } 237 | 238 | generateInputFields(fields); 239 | 240 | function updateFieldName(index, value) { 241 | embed.fields[index].name = value; 242 | updateEmbed(embed); 243 | } 244 | 245 | function updateFieldValue(index, value) { 246 | embed.fields[index].value = value; 247 | updateEmbed(embed); 248 | } 249 | 250 | function updateFieldInline(index, value) { 251 | embed.fields[index].inline = value; 252 | updateEmbed(embed); 253 | } 254 | 255 | function deleteField(index) { 256 | embed.fields.splice(index, 1); 257 | updateEmbed(embed); 258 | fields -= 1; 259 | generateInputFields(fields); 260 | } 261 | 262 | function addField() { 263 | embed.fields.push({ inline: true }); 264 | fields += 1; 265 | generateInputFields(fields); 266 | } 267 | 268 | function updateTitle(value) { 269 | embed.title = value || ''; 270 | updateEmbed(embed); 271 | } 272 | 273 | function updateUrl(value) { 274 | embed.url = value || ''; 275 | updateEmbed(embed); 276 | } 277 | 278 | function updateThumb(value) { 279 | embed.thumb_url = value || false; 280 | updateEmbed(embed); 281 | } 282 | 283 | function updateDescription(value) { 284 | embed.description = value || ''; 285 | updateEmbed(embed); 286 | } 287 | 288 | function updateColor(value) { 289 | embed.color = value || false; 290 | updateEmbed(embed); 291 | } 292 | 293 | function updateAuthorName(value) { 294 | embed.author.name = value || ''; 295 | updateEmbed(embed); 296 | } 297 | 298 | function updateAuthorUrl(value) { 299 | embed.author.url = value || ''; 300 | updateEmbed(embed); 301 | } 302 | 303 | function updateAuthorIcon(value) { 304 | embed.author.icon = value || ''; 305 | updateEmbed(embed); 306 | } 307 | 308 | function updateFooter(value) { 309 | embed.footer = value || ''; 310 | updateEmbed(embed); 311 | } 312 | 313 | $('#form').submit(function (e) { 314 | e.preventDefault(); 315 | }); 316 | 317 | // checking helpers 318 | function addWarning(item, type, message) { 319 | item.addClass('form-control-warning'); 320 | item.removeClass('form-control-success'); 321 | item.parent().addClass('has-warning'); 322 | item.parent().removeClass('has-success'); 323 | if ($('#' + type + '-feedback').length === 0) { 324 | item.after('
' + message + '
'); 325 | } 326 | } 327 | 328 | function addSuccess(item, type) { 329 | item.removeClass('form-control-warning'); 330 | item.addClass('form-control-success'); 331 | item.parent().addClass('has-success'); 332 | item.parent().removeClass('has-warning'); 333 | $('#' + type + '-feedback').remove(); 334 | } 335 | 336 | $('#title').keyup(function () { 337 | var item = $('#title'); 338 | var title = item.val(); 339 | 340 | // update 341 | updateTitle(title); 342 | }); 343 | 344 | $('#url').keyup(function () { 345 | var item = $('#url'); 346 | var url = item.val(); 347 | 348 | if (url.substr(0, 4) !== 'http' && url.length !== 0 && !switches.useVars) { 349 | addWarning(item, 'url', 'not a valid url'); 350 | } else { 351 | addSuccess(item, 'url'); 352 | // update 353 | updateUrl(url); 354 | } 355 | }); 356 | 357 | $('#icon').keyup(function () { 358 | var item = $('#icon'); 359 | var icon = item.val(); 360 | 361 | if (icon.substr(0, 4) !== 'http' && icon.length !== 0 && !switches.useVars) { 362 | addWarning(item, 'icon', 'not a valid url'); 363 | } else { 364 | addSuccess(item, 'icon'); 365 | // update 366 | updateThumb(icon); 367 | } 368 | }); 369 | 370 | $('#description').keyup(function () { 371 | var item = $('#description'); 372 | var description = item.val(); 373 | addSuccess(item, 'description'); 374 | // update 375 | updateDescription(description); 376 | }); 377 | 378 | $('#color').change(function () { 379 | updateColor($('#color').val()); 380 | }); 381 | 382 | $('#author_name').keyup(function () { 383 | var item = $('#author_name'); 384 | var author_name = item.val(); 385 | 386 | addSuccess(item, 'author_name'); 387 | // update 388 | updateAuthorName(author_name); 389 | }); 390 | 391 | $('#author_url').keyup(function () { 392 | var item = $('#author_url'); 393 | var author_url = item.val(); 394 | 395 | if (author_url.substr(0, 4) !== 'http' && author_url.length !== 0 && !switches.useVars) { 396 | addWarning(item, 'author_url', 'not a valid url'); 397 | } else { 398 | addSuccess(item, 'author_url'); 399 | // update 400 | updateAuthorUrl(author_url); 401 | } 402 | }); 403 | 404 | $('#author_icon').keyup(function () { 405 | var item = $('#author_icon'); 406 | var author_icon = item.val(); 407 | 408 | if (author_icon.substr(0, 4) !== 'http' && author_icon.length !== 0 && !switches.useVars) { 409 | addWarning(item, 'author_icon', 'not a valid url'); 410 | } else { 411 | addSuccess(item, 'author_icon'); 412 | // update 413 | updateAuthorIcon(author_icon); 414 | } 415 | }); 416 | 417 | $('#footer').keyup(function () { 418 | var item = $('#footer'); 419 | var footer = item.val(); 420 | 421 | addSuccess(item, 'footer'); 422 | // update 423 | updateFooter(footer); 424 | }); 425 | 426 | $('#useVars').click(function () { 427 | switches.useVars = !switches.useVars; 428 | updateEmbed(embed); 429 | }); 430 | }); 431 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | 2 | 11 | -------------------------------------------------------------------------------- /sass/style.sass: -------------------------------------------------------------------------------- 1 | $width: 120px 2 | $top: 20px 3 | $left: 20px 4 | 5 | a.patreon-link 6 | display: flex 7 | box-sizing: border-box 8 | width: 100% 9 | height: auto 10 | z-index: 10 11 | text-decoration: none 12 | 13 | .badge-container 14 | width: 100% 15 | display: flex 16 | flex-direction: column 17 | padding: 5px 10px 18 | background: rgba(0,0,0,0.5) 19 | border: 1px solid rgba(255,255,255,0.5) 20 | text-align: center 21 | 22 | .badge-icon 23 | background: url('https://s3.amazonaws.com/patreon_public_assets/toolbox/patreon_white.png') center center no-repeat 24 | background-size: contain 25 | width: 100% 26 | height: 20px 27 | 28 | .badge-text 29 | font-family: 'Lato', sans-serif 30 | font-size: 12px 31 | padding: 2px 32 | color: #fff 33 | 34 | &.badge-text-bottom 35 | position: relative 36 | top: -2px 37 | 38 | 39 | 40 | .preview 41 | background: #36393e 42 | display: flex 43 | box-orient: vertical 44 | flex-direction: column 45 | 46 | .wrapper 47 | display: flex 48 | max-width: 520px 49 | 50 | .container 51 | margin-top: 50px 52 | 53 | .side-colored 54 | width: 4px 55 | border-radius: 3px 0 0 3px 56 | background: #4f545c 57 | 58 | .embed 59 | border-radius: 0 3px 3px 0 60 | background: rgba(46,48,54,.3) 61 | border-color: rgba(46,48,54,.6) 62 | display: flex 63 | padding: 8px 10px 64 | color: rgba(255,255,255,0.6) 65 | font-size: 14px 66 | 67 | .card-block 68 | padding: 0 69 | display: flex 70 | margin-bottom: 10px 71 | 72 | a 73 | color: #0096cf 74 | 75 | img.embed-thumb 76 | max-height: 80px 77 | max-width: 80px 78 | border-radius: 3px 79 | flex-shrink: 0 80 | width: auto 81 | object-fit: contain 82 | margin-left: 20px 83 | 84 | .embed-footer 85 | font-size: 12px 86 | span 87 | color: rgba(255,255,255,0.6) 88 | 89 | .embed-inner 90 | 91 | .embed-title 92 | color: #fff 93 | 94 | .embed-author 95 | display: flex 96 | align-items: center 97 | margin-bottom: 5px 98 | 99 | img.embed-author-icon 100 | margin-right: 9px 101 | width: 20px 102 | height: 20px 103 | object-fit: contain 104 | border-radius: 50% 105 | 106 | .embed-author-name 107 | display: inline-block 108 | font-weight: 600 109 | font-size: 14px 110 | color: #fff !important 111 | 112 | .fields 113 | display: flex 114 | flex-wrap: wrap 115 | flex-direction: row 116 | box-lines: miltiple 117 | margin-top: -10px 118 | 119 | .field 120 | flex: 0 121 | box-flex: 1 122 | padding-top: 10px 123 | max-width: 506px 124 | min-width: 100% 125 | 126 | &.inline 127 | box-flex: 1 128 | flex: 1 129 | min-width: 150px 130 | flex-basis: auto 131 | 132 | .field-name 133 | color: #fff 134 | font-size: 14px 135 | margin-bottom: 4px 136 | font-weight: 600 137 | 138 | .field-value 139 | color: rgba(255,255,255,0.7) 140 | font-size: 14px 141 | font-weight: 500 142 | line-height: 1.1em 143 | white-space: pre-wrap 144 | margin-top: 6px 145 | word-wrap: break-word 146 | 147 | 148 | --------------------------------------------------------------------------------