Last active
September 20, 2020 08:40
-
-
Save MulverineX/ebc269cf572930cb602a9e4b24e4d907 to your computer and use it in GitHub Desktop.
CSS Snippets Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"guild_id": "466792645767987210", | |
"snippets": [ | |
{ | |
"title": "Animate profile badges on hover", | |
"content": "**Animate profile badges on hover**\nby someone else", | |
"preview_images": [ | |
"https://i.imgur.com/gPUobGW.gif" | |
], | |
"styles": [ | |
".header-QKLPzZ .headerInfo-30uryT .flex-1xMQg5 div {\n transition: 0.2s;\n}\n\n.header-QKLPzZ .headerInfo-30uryT .flex-1xMQg5 div:hover {\n transition: 0.2s;\n transform: translateY(-0.75px);\n}" | |
], | |
"meta_styles": [], | |
"message_id": "757138632334246000", | |
"author": { | |
"id": "178551656714076161", | |
"display": "MulverineX#0001" | |
} | |
}, | |
{ | |
"title": "Better Feedback Emojis", | |
"content": "**Better Feedback Emojis**\n\n**Previews:**", | |
"preview_images": [ | |
"https://i.imgur.com/PxjTBbd.png", | |
"https://i.imgur.com/l0a2i7g.png" | |
], | |
"styles": [ | |
".emojiHappy-1hbF93 {\n background-image: url(\"/assets/da3651e59d6006dfa5fa07ec3102d1f3.svg\");\n}\n\n.emojiNeutral-14asfM {\n background-image: url(\"/assets/fa9b378aed10bba1aea54ca34e76fe4b.svg\");\n}\n\n.emojiSad-1GqgAQ {\n background-image: url(\"/assets/9dc0c15c9e35f7ba86150ae12e895d29.svg\");\n}" | |
], | |
"meta_styles": [], | |
"message_id": "757030934590521404", | |
"author": { | |
"id": "178551656714076161", | |
"display": "MulverineX#0001" | |
} | |
}, | |
{ | |
"title": "Denitrofy Discord", | |
"content": "", | |
"preview_images": [], | |
"styles": [ | |
"[href=\"/store\"],\n.buttons-3JBrkn > .button-38aScr.noFocus-2C7BQj {\n display: none;\n}" | |
], | |
"meta_styles": [], | |
"message_id": "757030906987937914", | |
"author": { | |
"id": "178551656714076161", | |
"display": "MulverineX#0001" | |
} | |
}, | |
{ | |
"title": "Larger Emoji Preview", | |
"content": "", | |
"preview_images": [ | |
"https://i.imgur.com/Z3WPuID.png", | |
"https://i.imgur.com/vysPe9D.png" | |
], | |
"styles": [ | |
".emojiSection-3Fb9ix > .noWrap-3jynv6,\n.emojiSection-3Fb9ix {\n flex-wrap: wrap;\n}\n\n.emojiSection-3Fb9ix img ~ div {\n margin-left: 0 !important;\n margin-top: 10px !important;\n}\n\n.emojiSection-3Fb9ix img {\n margin: auto;\n min-width: 100%;\n height: auto !important;\n}" | |
], | |
"meta_styles": [], | |
"message_id": "757030853451972648", | |
"author": { | |
"id": "178551656714076161", | |
"display": "MulverineX#0001" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require('discord.js') | |
const css = require('css') | |
const client = new Discord.Client() | |
client.on('ready', async () => { | |
let snippets = [] | |
const target_guild = client.guilds.cache.get('538759280057122817') | |
const snippets_channel = target_guild.channels.cache.get('755005803303403570') | |
const meta_test = new RegExp(['charset','custom-media','document','font-face','host','import'].join("|")); | |
await snippets_channel.messages.fetch({ limit: 100 }) | |
for (const snippet_message of snippets_channel.messages.cache.values()) { | |
if (snippet_message.content.includes('```css')) { | |
const author = snippet_message.author | |
let meta_styles = [] | |
let styles = Array.from(snippet_message.content.matchAll(/((```css)((.|\n)*?)```)/gi)) | |
let new_styles = [] | |
styles.forEach((m) => { | |
let meta = [] | |
let style_objects = css.parse(m[3].replace(/^\s+|\s+$/g, '')).stylesheet.rules | |
style_objects = style_objects.filter((s) => { | |
const is_meta = meta_test.test(s.type) | |
if (is_meta) meta.push(s) | |
return (s.type !== 'comment' && !is_meta) | |
}) | |
if (meta.length !== 0) | |
meta_styles.push(css.stringify({ type: "stylesheet", stylesheet: { rules: meta } })) | |
new_styles.push(css.stringify({ type: "stylesheet", stylesheet: { rules: style_objects } })) | |
}) | |
let images = [] | |
if (snippet_message.embeds.length != 0) snippet_message.embeds.forEach((embed) => { | |
if (new RegExp(['image','gifv','gif'].join("|")).test(embed.type)) images.push(embed.thumbnail.url) | |
}) | |
let trimmed_content = snippet_message.content | |
styles.forEach((style) => { trimmed_content = trimmed_content.replace(style[0],'') }) | |
let title = trimmed_content.split('\n')[0] | |
if (title.slice(0,2) === '**') title = title.split('**')[1] | |
trimmed_content = trimmed_content.split('\n') | |
trimmed_content = trimmed_content.filter((line, i) => !(new RegExp(images.join("|")).test(line))) | |
snippets.push({ | |
title: title, | |
content: trimmed_content.join('\n').replace('\n\n\n', '\n\n').replace(/^\s+|\s+$/g, ''), | |
preview_images: images, | |
styles: new_styles, | |
meta_styles: meta_styles, | |
message_id: snippet_message.id, | |
author: { | |
id: author.id, | |
display: `${author.username}#${author.discriminator}` | |
} | |
}) | |
} | |
} | |
// This is just an example output, would probably be switched to some DB integration or fs output. | |
console.log(JSON.stringify({ | |
guild_id: target_guild.id, | |
snippets: snippets | |
})); | |
client.destroy() | |
}) | |
client.login("token_goes_here") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import the discord.js module | |
const Discord = require('discord.js') | |
const css = require('css') | |
const client = new Discord.Client() | |
client.on('ready', async () => { | |
console.log('hello') | |
}) | |
client.on('message', async msg => { | |
if (msg.channel.id == '755005803303403570' && msg.content.includes('```css')) { | |
const snippet_message = msg | |
const author = snippet_message.author | |
const meta_test = new RegExp(['charset','custom-media','document','font-face','host','import'].join("|")); | |
let meta_styles = [] | |
let styles = Array.from(snippet_message.content.matchAll(/((```css)((.|\n)*?)```)/gi)) | |
let new_styles = [] | |
styles.forEach((m) => { | |
let meta = [] | |
let style_objects = css.parse(m[3].replace(/^\s+|\s+$/g, '')).stylesheet.rules | |
style_objects = style_objects.filter((s) => { | |
const is_meta = meta_test.test(s.type) | |
if (is_meta) meta.push(s) | |
return (s.type !== 'comment' && !is_meta) | |
}) | |
if (meta.length !== 0) | |
meta_styles.push(css.stringify({ type: "stylesheet", stylesheet: { rules: meta } })) | |
new_styles.push(css.stringify({ type: "stylesheet", stylesheet: { rules: style_objects } })) | |
}) | |
let images = [] | |
if (snippet_message.embeds.length != 0) snippet_message.embeds.forEach((embed) => { | |
if (new RegExp(['image','gifv','gif'].join("|")).test(embed.type)) images.push(embed.thumbnail.url) | |
}) | |
let trimmed_content = snippet_message.content | |
styles.forEach((style) => { trimmed_content = trimmed_content.replace(style[0],'') }) | |
let title = trimmed_content.split('\n')[0] | |
if (title.slice(0,2) === '**') title = title.split('**')[1] | |
trimmed_content = trimmed_content.split('\n') | |
trimmed_content = trimmed_content.filter((line, i) => !(new RegExp(images.join("|")).test(line))) | |
// This is just an example output, would probably be switched to some DB integration or fs output. | |
console.log(JSON.stringify({ | |
title: title, | |
content: trimmed_content.join('\n').replace('\n\n\n', '\n\n').replace(/^\s+|\s+$/g, ''), | |
preview_images: images, | |
styles: new_styles, | |
meta_styles: meta_styles, | |
message_id: snippet_message.id, | |
author: { | |
id: author.id, | |
display: `${author.username}#${author.discriminator}` | |
} | |
})) | |
} | |
}) | |
client.login("token_goes_here") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment