├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── package.json └── src ├── API ├── EmojiAPI.coffee └── EmojiCache.coffee ├── Methods ├── Emotes │ ├── All.coffee │ ├── Author.coffee │ ├── Category.coffee │ ├── ID.coffee │ ├── License.coffee │ ├── Random.coffee │ ├── Slug.coffee │ └── Title.coffee ├── Packs │ └── Search.coffee └── Website │ └── Statistics.coffee └── index.coffee /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: Jinzulen 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | *.js 3 | lib/ 4 | Cache/ 5 | test.js 6 | .npmignore 7 | node_modules/ 8 | package-lock.json -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # DEmojiJS 4 | ### DiscordEmoji's number one API client for Node-based applications. 5 | 6 | ![CodeFactor](https://www.codefactor.io/repository/github/jinzulen/demojijs/badge/master?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/demojijs?style=for-the-badge) ![NPM Weekly Downloads](https://img.shields.io/npm/dw/demojijs.svg?style=for-the-badge) 7 | 8 | ## 1. Installation 9 | DEmojiJS is trusted by hundreds of users from all over to power their interactions with the DiscordEmoji API. Why? It's **faster** thanks to its caching features, its wide array of **versatile search** functionalities and overall **stable** performance. Not convinced? 10 | 11 | See for yourself: 12 | 13 | *If you are running a version older than **v1.3.4**, please update as soon as possible.* 14 | ``` 15 | npm i demojijs@latest 16 | ``` 17 | 18 | ## 1.2 Nodemon 19 | It is possible for Nodemon users to encounter problems when adding DEmojiJS to their project, this is due to the wrapper's caching mechanism, which initializes a JSON cache store on startup, this act causes a never-ending loop where Nodemon keeps detecting a ".json" change, thereby restarting the app, which in turn causes the cache handler to yet again initialize the store, etc... 20 | 21 | This can be easily avoided by checking that you are running the latest DEmojiJS version *(look at the NPM version badge above)* and then simply adding `DiscordEmoji.json` to the list of ignored files in the Nodemon config, like so: 22 | ```json 23 | "ignore": "DiscordEmoji.json" 24 | ``` 25 | 26 | Please refer yourself to [this section](https://github.com/remy/nodemon#config-files) of the public Nodemon repository if you don't know how to configure Nodemon. 27 | 28 | ## 2. Usage Examples 29 | > Often times, you won't be able to fetch a recently uploaded emote, this is not a fault of DEmojiJS; the data provided by DiscordEmoji themselves through their API is often outdated by a month or two, give or take. Most of the time, entire chunks of emotes are missing given the API doesn't serve **every** emote in DiscordEmoji's database. 30 | 31 | Firstly, require DEmojiJS: 32 | ```js 33 | const Emoji = require("demojijs"); 34 | ``` 35 | 36 | ### 2.1 Packs 37 | - Grabbing all packs. 38 | ```js 39 | Emoji.Packs().then(Packs => { 40 | console.log(`Found ${Packs.length} packs.`); 41 | 42 | Packs.forEach(function(Pack) { 43 | console.log(`- #${Pack.id} ${Pack.name} has ${Pack.amount} emotes and can be downloaded here: ${Pack.download}`); 44 | }); 45 | }).catch(console.error); 46 | // Found 8 packs. 47 | // - #9 Pensive Emojis has 8 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/pensive-pack.zip 48 | // - #8 Original Remixes #1 has 12 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/original-remixes-1.zip 49 | // - #7 Blob Pack #1 has 16 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/blob-pack-1.zip 50 | // - #6 100 Remixes has 12 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/100-remixes.zip- #5 PUBG Pack has 10 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/pubg-pack.zip 51 | // - #4 Minecraft Pack has 16 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/minecraft-pack.zip 52 | // - #3 Pepe Pack #1 has 16 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/pepe-pack-1.zip 53 | // - #2 Anime Pack #1 has 16 emotes and can be downloaded here: https://discordemoji.com/assets/packs/download/anime-pack-1.zip 54 | ``` 55 | 56 | - Grabbing a pack by ID, title or slug. 57 | > Input is not case-sensitive. 58 | ```js 59 | Emoji.Packs(4).then(console.log).catch(console.error); 60 | Emoji.Packs("minecraft pack").then(console.log).catch(console.error); 61 | Emoji.Packs("minecraft-pack").then(console.log).catch(console.error); 62 | ``` 63 | 64 | ### 2.2 Emotes & Stats 65 | - Grabbing DiscordEmoji's statistics. 66 | ```js 67 | // Grab all statistics. 68 | Emoji.Statistics().then(Data => { 69 | console.log(`DiscordEmoji has ${Data.emoji} emojis, ${Data.users} users, ${Data.faves} favorited emojis and ${Data.pending_approvals} emojis pending approval.`); 70 | }).catch(console.error); 71 | // DiscordEmoji has 15660 emojis, 126446 users, 103646 favorited emojis and 17 emojis pending approval. 72 | 73 | // Grab individual statistics. 74 | // For reference on the currently available search parameters, visit: https://discordemoji.com/api/?request=stats 75 | // If you only want one parameter, make sure to keep it as an array rather than a string: Statistics(["users"]) not Statistics("users") 76 | Emoji.Statistics(["users", "faves"]).then(console.log).catch(console.error); 77 | // { users: 126468, faves: 103702 } 78 | ``` 79 | 80 | - Grabbing a random emote. 81 | ```js 82 | // Grab a random emote. 83 | Emoji.randomEmoji().then(console.log).catch(console.error); 84 | 85 | // Grab a random animated (GIF) emote by simply setting "true" as the sole argument. 86 | Emoji.randomEmoji(true).then(console.log).catch(console.error); 87 | 88 | // Grab a random emote from a specific category by simply setting the name of the category as the sole argument. 89 | Emoji.randomEmoji("anime").then(console.log).catch(console.error); 90 | ``` 91 | 92 | - Grabbing all emotes. 93 | > Keep in mind that this will return an array if you choose to return GIFs only. 94 | ```js 95 | // Grab everything. 96 | Emoji.allEmoji().then(console.log).catch(console.error); 97 | 98 | // Grab only animated (GIF) emotes by simply setting "true" as the sole argument. 99 | Emoji.allEmoji(true).then(Emotes => console.log(`${Emotes.length} animated emotes found.`)).catch(console.error); 100 | ``` 101 | 102 | - Grabbing an emote by ID. 103 | ```js 104 | Emoji.emojiByID(1).then(console.log).catch(console.error); 105 | ``` 106 | 107 | - Grabbing an emote by title. 108 | > Emote title is not case sensitive. 109 | ```js 110 | Emoji.emojiByName("kappayugi").then(console.log).catch(console.error); 111 | ``` 112 | 113 | - Grabbing an emote by category. 114 | > Keep in mind that this will return an array and that the input is not case-sensitive. 115 | 116 | > For reference on all the available categories, visit: https://discordemoji.com/api/?request=categories 117 | ```js 118 | Emoji.emojiByCategory("anime").then(Emotes => console.log(`Found ${Emotes.length} emotes in this category.`)).catch(console.error); 119 | // Found 1090 emotes in this category. 120 | ``` 121 | 122 | - Grabbing an emote by its slug. 123 | ```js 124 | Emoji.emojiBySlug("5263_flashthink").then(Emote => { 125 | console.log(`${Emote.title}, uploaded by ${Emote.submitted_by}. => ${Emote.image}`) 126 | }).catch(console.error); 127 | // flashthink, uploaded by Jin. => https://discordemoji.com/assets/emoji/5263_flashthink.png 128 | ``` 129 | 130 | - Grabbing emotes by author. 131 | > Keep in mind that this will return an array; also, the uploader name is not case sensitive. 132 | 1. Grab all of the user's emotes. 133 | ```js 134 | Emoji.emojiByAuthor("Jin").then(Emotes => { 135 | console.log(`This user has uploaded ${Emotes.length} emotes; here are a couple of them:`); 136 | 137 | Emotes.slice(-2).forEach(function(Emote) { 138 | console.log(`${Emote.title} => ${Emote.image}`); 139 | }); 140 | }).catch(console.error); 141 | // This user has uploaded 90 emotes; here are a couple of them: 142 | // linkdab => https://discordemoji.com/assets/emoji/4955_linkdab.png 143 | // KappaYugi => https://discordemoji.com/assets/emoji/KappaYugi.png 144 | ``` 145 | 146 | 2. Grab all of the user's animated (GIF) emotes. 147 | ```js 148 | // Simply set "true" as the second argument. 149 | Emoji.emojiByAuthor("Jin", true).then(Emotes => { 150 | console.log(`This user has uploaded ${Emotes.length} animated emotes; for example:`); 151 | 152 | Emotes.slice(-2).forEach(function(Emote) { 153 | console.log(`${Emote.title} => ${Emote.image}`); 154 | }); 155 | }).catch(console.error); 156 | // This user has uploaded 7 animated emotes; for example: 157 | // linkwut => https://discordemoji.com/assets/emoji/5523_linkwut.gif 158 | // linklurk => https://discordemoji.com/assets/emoji/9136_linklurk.gif 159 | ``` 160 | 161 | - Grabbing emotes by license. 162 | > Keep in mind that this will return an array and that the input is not case-sensitive. 163 | ```js 164 | Emoji.emojiByLicense("basic").then(Emotes => console.log(`Found ${Emotes.length} emotes.`)).catch(console.error); 165 | Emoji.emojiByLicense("wtfpl").then(Emotes => console.log(`Found ${Emotes.length} emotes.`)).catch(console.error); 166 | Emoji.emojiByLicense("cc by 4.0").then(Emotes => console.log(`Found ${Emotes.length} emotes.`)).catch(console.error); 167 | // Found 5108 emotes. 168 | // Found 83 emotes. 169 | // Found 254 emotes. 170 | 171 | // Grab animted (GIF) emotes under a certain license by setting "true" as the second argument. 172 | Emoji.emojiByLicense("basic", true).then(Emotes => console.log(`Found ${Emotes.length} animated emotes.`)).catch(console.error); 173 | Emoji.emojiByLicense("wtfpl", true).then(Emotes => console.log(`Found ${Emotes.length} animated emotes.`)).catch(console.error); 174 | Emoji.emojiByLicense("cc by 4.0", true).then(Emotes => console.log(`Found ${Emotes.length} animted emotes.`)).catch(console.error); 175 | // Found 649 animated emotes. 176 | // Found 12 animated emotes. 177 | // Found 36 animted emotes. 178 | ``` 179 | 180 | ## 3. License 181 | This module is publisher under the [Apache 2.0](https://github.com/Jinzulen/DEmojiJS/blob/master/LICENSE.md) license. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demojijs", 3 | "version": "1.3.6", 4 | "description": "Extensively powerful API client for Discord Emoji.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "prepublish": "npm run compile", 8 | "compile": "coffee --compile --output lib/ src/" 9 | }, 10 | "keywords": [ 11 | "bot", 12 | "emoji", 13 | "demoji", 14 | "discord", 15 | "discordemoji" 16 | ], 17 | "author": "Jinzulen", 18 | "license": "Apache-2.0", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/Jinzulen/DEmojiJS.git" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/Jinzulen/DEmojiJS/issues" 25 | }, 26 | "homepage": "https://github.com/Jinzulen/DEmojiJS", 27 | "dependencies": { 28 | "node-json-db": "^1.1.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/API/EmojiAPI.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | HTTPS = require "https" 8 | Cache = require "./EmojiCache" 9 | 10 | exports.GrabCategories = () -> 11 | if !Cache.getCache "/Categories" 12 | this.contactAPI "https://emoji.gg/api/?request=categories", (Error, Data) -> 13 | if Error 14 | throw Error 15 | 16 | exports.contactAPI = (Endpoint, Callback) -> 17 | try 18 | Stores = { 19 | "https://emoji.gg/api/": "/Emoji", 20 | "https://emoji.gg/api/packs": "/Packs", 21 | "https://emoji.gg/api/?request=stats": "/Stats", 22 | "https://emoji.gg/api/?request=categories": "/Categories" 23 | } 24 | 25 | Key = Cache.getCache Stores[Endpoint] 26 | 27 | if !Key 28 | HTTPS.get Endpoint, (Response) -> 29 | Error = "" 30 | rawData = "" 31 | 32 | Code = Response.statusCode 33 | Type = Response.headers["content-type"] 34 | 35 | if Code != 200 36 | Error = "# [DEmojiJS] Could not issue request @ " + Endpoint 37 | 38 | if Error 39 | Response.resume() 40 | Callback Error 41 | 42 | Response.setEncoding "utf8" 43 | 44 | Response.on "data", (Buffer) -> 45 | rawData += JSON.parse JSON.stringify Buffer 46 | 47 | Response.on "end", () -> 48 | try 49 | Data = rawData 50 | 51 | Cache.setCache Stores[Endpoint], Data 52 | catch E 53 | throw E 54 | 55 | Callback Error, JSON.parse Data 56 | else 57 | Callback null, JSON.parse Key 58 | catch E 59 | throw E 60 | -------------------------------------------------------------------------------- /src/API/EmojiCache.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | FS = require "fs" 8 | Path = require "path" 9 | JSONDB = require "node-json-db" 10 | JSONConfig = require "node-json-db/dist/lib/JsonDBConfig" 11 | 12 | module.exports = new class EmojiCache 13 | constructor: () -> 14 | this.Storage = new JSONDB.JsonDB(new JSONConfig.Config("./Cache/DiscordEmoji", true, false)) 15 | 16 | this.Storage.push "/Stats" 17 | this.Storage.push "/Emoji" 18 | this.Storage.push "/Packs" 19 | this.Storage.push "/Categories" 20 | 21 | getCache: (Store) -> 22 | try 23 | Data = this.Storage.getData("/")["#{Store.replace "/", ""}"] 24 | 25 | if typeof Data != "undefined" then return Data else return false 26 | catch E 27 | throw E 28 | 29 | setCache: (Store, Data) -> 30 | try 31 | this.Storage.push Store, Data 32 | catch E 33 | throw E 34 | -------------------------------------------------------------------------------- /src/Methods/Emotes/All.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabEverything 10 | constructor: (GIF, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 13 | if Error then Reject Error 14 | 15 | if GIF 16 | Store = [] 17 | 18 | for e in Data 19 | if e["image"].includes ".gif" 20 | Store.push e 21 | 22 | Resolve Store 23 | else Resolve Data 24 | -------------------------------------------------------------------------------- /src/Methods/Emotes/Author.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabAuthor 10 | constructor: (Author, GIF, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !Author then Reject "# [DEmojiJS] Please enter an emote uplaoder to continue." 13 | 14 | if typeof Author != "string" 15 | Reject "# [DEmojiJS] Emote author has to be a string." 16 | 17 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 18 | if Error then Reject Error 19 | 20 | Store = [] 21 | if GIF then Type = ".gif" else Type = "." 22 | 23 | for e in Data 24 | e["submitted_by"] = e["submitted_by"].toLowerCase() 25 | 26 | if e["submitted_by"] == Author.toLowerCase() && e["image"].includes Type 27 | Store.push e 28 | 29 | Resolve Store -------------------------------------------------------------------------------- /src/Methods/Emotes/Category.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabCategory 10 | constructor: (Category, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !Category then Reject "# [DEmojiJS] Please enter an emote category to continue." 13 | 14 | if typeof Category != "string" 15 | Reject "# [DEmojiJS] Emote Category has to be a string." 16 | 17 | # Stores. 18 | Cats = {} 19 | Store = [] 20 | 21 | # Grab emotes. 22 | API.contactAPI "https://emoji.gg/api/", (Error, Emotes) -> 23 | if Error then Reject Error 24 | 25 | # Grab categories. 26 | API.contactAPI "https://emoji.gg/api/?request=categories", (Error, Categories) -> 27 | if Error then Reject Error 28 | 29 | # Store all categories in lowercase. 30 | for c in Object.keys Categories 31 | Cats[c] = Categories[c].toLowerCase() 32 | 33 | # Search for emotes that fit the requested category. 34 | for e in Emotes 35 | if Cats[e["category"]] == Category.toLowerCase() 36 | Store.push e 37 | 38 | Resolve Store -------------------------------------------------------------------------------- /src/Methods/Emotes/ID.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabID 10 | constructor: (ID, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !ID then Reject "# [DEmojiJS] Please enter an emote ID to continue." 13 | 14 | if typeof ID != "number" 15 | Reject "# [DEmojiJS] Emote ID has to be a number." 16 | 17 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 18 | if Error then Reject Error 19 | 20 | i = 0 21 | while i < Object.keys(Data).length 22 | if Data[i]["id"] == ID 23 | Resolve Data[i] 24 | 25 | i++ -------------------------------------------------------------------------------- /src/Methods/Emotes/License.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabLicense 10 | constructor: (License, GIF, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !License 13 | Reject "# [DEmojiJS] Please enter a license name to continue." 14 | 15 | if typeof License != "string" 16 | Reject "# [DEmojiJS] Emote license has to be a string." 17 | 18 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 19 | if Error then Reject Error 20 | 21 | Store = [] 22 | License = License.toLowerCase() 23 | Licenses = {"basic": "0", "cc by 4.0": "1", "wtfpl": "2"} 24 | 25 | if GIF then Type = ".gif" else Type = "." 26 | if !Licenses[License] then Reject "# [DEmojiJS] #{License} is not a valid license." 27 | 28 | for e in Data 29 | if e["license"] == Licenses[License] && e["image"].includes Type 30 | Store.push e 31 | 32 | Resolve Store -------------------------------------------------------------------------------- /src/Methods/Emotes/Random.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabRandom 10 | constructor: (Input, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 13 | if Error then Reject Error 14 | 15 | if Input 16 | Cats = [] 17 | Store = [] 18 | 19 | for e in Data 20 | if typeof Input != "boolean" 21 | API.contactAPI "https://emoji.gg/api/?request=categories", (Error, Categories) -> 22 | if Error 23 | throw Error 24 | 25 | # Store all categories in lowercase. 26 | for c in Object.keys Categories 27 | Cats[c] = Categories[c].toLowerCase() 28 | 29 | if Cats[e["category"]] == Input.toLowerCase() 30 | Store.push e 31 | 32 | if typeof Input == "boolean" && Input != false 33 | if e["image"].includes ".gif" 34 | Store.push e 35 | 36 | Resolve Store[Math.floor Math.random() * Store.length + 1] 37 | else 38 | Resolve Data[Math.floor Math.random() * Object.keys(Data).length + 1] -------------------------------------------------------------------------------- /src/Methods/Emotes/Slug.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabSlug 10 | constructor: (Slug, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !Slug then Reject "# [DEmojiJS] Please enter an emote slug to continue." 13 | 14 | if typeof Slug != "string" 15 | Reject "# [DEmojiJS] Emote slug has to be a string." 16 | 17 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 18 | if Error then Reject Error 19 | 20 | i = 0 21 | while i < Object.keys(Data).length 22 | if Data[i]["slug"] == Slug 23 | Resolve Data[i] 24 | 25 | i++ -------------------------------------------------------------------------------- /src/Methods/Emotes/Title.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabTitle 10 | constructor: (Title, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | if !Title then Reject "# [DEmojiJS] Please enter an emote title to continue." 13 | 14 | if typeof Title != "string" 15 | Reject "# [DEmojiJS] Emote title has to be a string." 16 | 17 | API.contactAPI "https://emoji.gg/api/", (Error, Data) -> 18 | if Error then Reject Error 19 | 20 | i = 0 21 | while i < Object.keys(Data).length 22 | # Get rid of case sensitivity. 23 | Data[i]["title"] = Data[i]["title"].toLowerCase() 24 | 25 | if Data[i]["title"] == Title.toLowerCase() 26 | Resolve Data[i] 27 | 28 | i++ -------------------------------------------------------------------------------- /src/Methods/Packs/Search.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class SearchPacks 10 | constructor: (ID, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | API.contactAPI "https://emoji.gg/api/packs", (Error, Packs) -> 13 | if Error then Reject Error 14 | 15 | if ID 16 | Store = {} 17 | 18 | for p in Packs 19 | # Get rid of case sensitivity. 20 | if typeof ID != "number" then ID = ID.toLowerCase() 21 | 22 | Store["id"] = p["id"] 23 | Store["slug"] = p["slug"] 24 | Store["image"] = p["image"] 25 | Store["amount"] = p["amount"] 26 | Store["download"] = p["download"] 27 | Store["name"] = p["name"].toLowerCase() 28 | 29 | # Return results. 30 | if Store["id"] == ID || Store["name"] == ID || Store["slug"] == ID 31 | Resolve p 32 | else 33 | Resolve Packs -------------------------------------------------------------------------------- /src/Methods/Website/Statistics.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | API = require "../../API/EmojiAPI" 8 | 9 | module.exports = class GrabStatistics 10 | constructor: (Options, Callback) -> 11 | return new Promise (Resolve, Reject) -> 12 | API.contactAPI "https://emoji.gg/api/?request=stats", (Error, Data) -> 13 | if Error then Reject Error 14 | 15 | if Options.length >= 1 16 | Store = {} 17 | 18 | for o in Options 19 | Store[o] = Data[o] 20 | 21 | Resolve Store 22 | else Resolve Data -------------------------------------------------------------------------------- /src/index.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # @author Jinzulen 3 | # @license Apache 2.0 4 | # @copyright Copyright 2020 Khalil G. 5 | ### 6 | 7 | # Grab categories just once at run-time. 8 | API = require "./API/EmojiAPI" 9 | 10 | API.GrabCategories() 11 | 12 | # Method routes scaffolding. 13 | Methods = {} 14 | 15 | Methods.Packs = (ID = null, Callback) -> 16 | new (require "./Methods/Packs/Search")(ID, Callback) 17 | 18 | Methods.allEmoji = (GIF = false, Callback) -> 19 | new (require "./Methods/Emotes/All")(GIF, Callback) 20 | 21 | Methods.randomEmoji = (Input = null, Callback) -> 22 | new (require "./Methods/Emotes/Random")(Input, Callback) 23 | 24 | Methods.emojiByID = (ID, Callback) -> 25 | new (require "./Methods/Emotes/ID")(ID, Callback) 26 | 27 | Methods.emojiByName = (Title, Callback) -> 28 | new (require "./Methods/Emotes/Title")(Title, Callback) 29 | 30 | Methods.emojiBySlug = (Slug, Callback) -> 31 | new (require "./Methods/Emotes/Slug")(Slug, Callback) 32 | 33 | Methods.emojiByAuthor = (Name, GIF = false, Callback) -> 34 | new (require "./Methods/Emotes/Author")(Name, GIF, Callback) 35 | 36 | Methods.emojiByLicense = (License, GIF = false, Callback) -> 37 | new (require "./Methods/Emotes/License")(License, GIF, Callback) 38 | 39 | Methods.emojiByCategory = (Category, Callback) -> 40 | new (require "./Methods/Emotes/Category")(Category, Callback) 41 | 42 | Methods.Statistics = (Options = [], Callback) -> 43 | new (require "./Methods/Website/Statistics")(Options, Callback) 44 | 45 | # Return methods. 46 | module.exports = Methods 47 | --------------------------------------------------------------------------------