summaryrefslogtreecommitdiff
path: root/node_modules/demojijs
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/demojijs
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/demojijs')
-rw-r--r--node_modules/demojijs/LICENSE15
-rw-r--r--node_modules/demojijs/README.md165
-rw-r--r--node_modules/demojijs/index.js7
-rw-r--r--node_modules/demojijs/package.json58
-rw-r--r--node_modules/demojijs/src/DEmojiJS.js327
5 files changed, 572 insertions, 0 deletions
diff --git a/node_modules/demojijs/LICENSE b/node_modules/demojijs/LICENSE
new file mode 100644
index 0000000..a6cf90b
--- /dev/null
+++ b/node_modules/demojijs/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+Copyright (c) 2018, Jinzulen <[email protected]>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file
diff --git a/node_modules/demojijs/README.md b/node_modules/demojijs/README.md
new file mode 100644
index 0000000..528befe
--- /dev/null
+++ b/node_modules/demojijs/README.md
@@ -0,0 +1,165 @@
+DEmojiJS is a lightweight, simple NodeJS wrapper around the DiscordEmoji API.
+
+You can quickly and easily install the library using NPM, via the following command: `npm i demojijs`. - Alternatively, you can just download the ZIP from here and require it in your project.
+
+
+[![https://nodei.co/npm/demojijs.png](https://nodei.co/npm/demojijs.png)](https://www.npmjs.com/package/demojijs)
+
+## Features
+- DiscordEmoji API Features:
+1. You can fetch the full extent of DiscordEmoji's statistics, as published by their API, including:
+ - Number of users in their database.
+ - Number of emojis pending approval.
+ - Number of emojis in their database.
+ - Number of user favorites in their database.
+
+2. You can fetch information on a particular emoji, as indicated by their API, the information includes:
+ - Emoji ID
+ - Emoji Name
+ - Emoji Slug
+ - Emoji Image
+ - Emoji Width
+ - Emoji Height
+ - Emoji Source
+ - Emoji License
+ - Emoji Category
+ - Emoji File Size
+ - Emoji Favorites
+ - Emoji Submitter
+ - Emoji Description
+
+3. You can fetch the full list of available emoji categories, as indicated by their API.
+
+- Wrapper Features
+1. **Caching:** DEmojiJS makes use of local, file cache to lighten the load on DiscordEmoji's API and improve response time, the cache lifetime is by default set to **12 hours**.
+
+## Guides:
+> Please keep in mind that data in the DiscordEmoji database is case-sensitive, which means that if you were to request an emoji by name, it'd be have to be "KappaYugi" not "kappayugi" or such, same thing goes for requesting an emoji by author, etc...
+
+- First, call DEmojiJS using:
+```js
+const DEmojiJS = require('demojijs');
+```
+
+1. Fetching emojis:
+- We have quite a number of ways to fetch emojis here, but let's get this thing out of the way first, we can get a random emoji using:
+```js
+/**
+ * Emoji here will return a JSON object carrying the following information:
+ * * id
+ * * title
+ * * slug
+ * * image
+ * * description
+ * * category
+ * * license
+ * * source
+ * * faves
+ * * submitted_by
+ * * width
+ * * height
+ * * filesize
+ */
+DEmojiJS.randomEmoji().then(Emoji => {
+ console.log(`${Emoji.title} (${Emoji.image}), submitted by: ${Emoji.submitted_by}.`);
+}).catch(console.error);
+```
+
+- Fetching all of the available emojis
+> If the data had been cached, then it will pull from cache, if not then it will make an API request, cache then pull from cache, pretty straightforward me thinks, neh?
+```js
+DEmojiJS.allEmoji().then(Emotes => {
+ console.log(Emotes);
+
+ // Implement your own logic here to deal with the data as you wish.
+}).catch(console.error);
+```
+
+- Fetching an emoji by ID
+```js
+DEmojiJS.emojiByID(5054).then(Emoji => {
+ console.log(`${Emoji.title} (${Emoji.image}), submitted by: ${Emoji.submitted_by}.`);
+}).catch(console.error);
+// {"id":5054,"title":"KappaYugi","slug":"KappaYugi","image":"https:\/\/discordemoji.com\/assets\/emoji\/KappaYugi.png","description":"KappaYugi is a emoji that you can use on discord or slack. View more info at https:\/\/discordemoji.com\/emoji\/KappaYugi","category":3,"license":"1","source":"","faves":8,"submitted_by":"Jin","width":0,"height":0,"filesize":0}
+```
+
+- Fetching an emoji by name
+```js
+DEmojiJS.emojiByName('KappaYugi').then(Emoji => {
+ console.log(`${Emoji.title} (${Emoji.image}), submitted by: ${Emoji.submitted_by}.`);
+}).then(console.error);
+// {"id":5054,"title":"KappaYugi","slug":"KappaYugi","image":"https:\/\/discordemoji.com\/assets\/emoji\/KappaYugi.png","description":"KappaYugi is a emoji that you can use on discord or slack. View more info at https:\/\/discordemoji.com\/emoji\/KappaYugi","category":3,"license":"1","source":"","faves":8,"submitted_by":"Jin","width":0,"height":0,"filesize":0}
+```
+
+- Fetching emojis by author/person who submitted them:
+```js
+DEmojiJS.emojiByAuthor('Kohai').then(Emotes => {
+ Emotes.forEach(function(Element) {
+ console.log(`- ${Element.title} (${Element.image}) by ${Element.submitted_by}`);
+ });
+}).catch(console.error);
+
+//- MadmanShrug (https://discordemoji.com/assets/emoji/6461_MadmanShrug.png) by Kohai
+//- Telegram (https://discordemoji.com/assets/emoji/9297_Telegram.png) by Kohai
+//- hedhurt (https://discordemoji.com/assets/emoji/6700_hedhurt.png) by Kohai
+//- blobwitchtea (https://discordemoji.com/assets/emoji/9643_blobwitchtea.png) by Kohai
+//- eymario (https://discordemoji.com/assets/emoji/5501_eymario.png) by Kohai
+// [... 496 more items]
+```
+
+- Fetching emojis by license
+> License input here is not case-sensitive.
+```js
+DEmojiJS.emojiByLicense('basic').then(Emotes => {
+ console.log(`- Found ${Emotes.length} emotes using this license.`);
+}).catch(console.error);
+// - Found 4772 emotes using this license.
+
+DEmojiJS.emojiByLicense('cc by 4.0').then(Emotes => {
+ console.log(`- Found ${Emotes.length} emotes using this license.`);
+}).catch(console.error);
+// - Found 251 emotes using this license.
+
+DEmojiJS.emojiByLicense('wtfpl').then(Emotes => {
+ console.log(`- Found ${Emotes.length} emotes using this license.`);
+}).catch(console.error);
+//- Found 72 emotes using this license.
+```
+
+2. Fetching Statistics
+```js
+DEmojiJS.Statistics().then(Stats => {
+ console.log(Stats.emoji);
+ // returns: 5660
+
+ console.log(Stats.users);
+ // return: 34701
+
+ console.log(Stats.faves);
+ // returns: 30051
+
+ console.log(Stats.pending_approvals);
+ // returns: 1
+
+ console.log(Stats);
+ // returns: { emoji: 5660, users: 34701, faves: 30051, pending_approvals: 1 }
+}).catch(console.error);
+```
+
+## Dependencies
+- [underscore](https://www.npmjs.com/package/underscore)
+- [node-file-cache](https://www.npmjs.com/package/node-file-cache)
+
+## Contributors
+- Jinzulen (Jin#8303) - Making this.
+- Coffee-chan - Keeping me alive and focused. <3
+
+## Useful Links
+- [DiscordEmoji](https://discordemoji.com/)
+- [DiscordEmoji Server](https://discord.gg/Fh6q2Fw)
+- [DEmojiJS NPM](https://www.npmjs.com/package/demojijs)
+
+## Developer Note
+- Callbacks are being problematic, please avoid using them right now and instead go only for promises.
+- This wrapper is released under the ISC license, as such, you can do with it what you want so long as credits remain.
+- If you encounter an issue with it, then feel free to open an issue and I'll tend to it and see what can be done about it, same thing goes for feature requests. \ No newline at end of file
diff --git a/node_modules/demojijs/index.js b/node_modules/demojijs/index.js
new file mode 100644
index 0000000..b94bbdd
--- /dev/null
+++ b/node_modules/demojijs/index.js
@@ -0,0 +1,7 @@
+/**
+ * Copyright (c) 2018 Jinzulen <[email protected]>
+ *
+ * @license ISC
+ */
+
+module.exports = require('./src/DEmojiJS'); \ No newline at end of file
diff --git a/node_modules/demojijs/package.json b/node_modules/demojijs/package.json
new file mode 100644
index 0000000..d22d085
--- /dev/null
+++ b/node_modules/demojijs/package.json
@@ -0,0 +1,58 @@
+{
+ "_from": "demojijs",
+ "_id": "[email protected]",
+ "_inBundle": false,
+ "_integrity": "sha512-EhsPdOMXOS7YkePQZnKWnVtxBw+4nMxeHCl3qTCfqHQk5qyqSbvzkcfFy7KQCEjBgD3rh/4TtCky/4G97rHLOA==",
+ "_location": "/demojijs",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "tag",
+ "registry": true,
+ "raw": "demojijs",
+ "name": "demojijs",
+ "escapedName": "demojijs",
+ "rawSpec": "",
+ "saveSpec": null,
+ "fetchSpec": "latest"
+ },
+ "_requiredBy": [
+ "#USER",
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/demojijs/-/demojijs-1.2.0.tgz",
+ "_shasum": "a357a09eed1cee254fdac5b593b4dc380361aea1",
+ "_spec": "demojijs",
+ "_where": "E:\\Documents\\GitHub\\s5nical",
+ "author": {
+ "name": "Jinzulen"
+ },
+ "bugs": {
+ "url": "https://github.com/Jinzulen/DEmojiJS/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "node-file-cache": "^1.0.2",
+ "underscore": "^1.9.1"
+ },
+ "deprecated": false,
+ "description": "DEmojiJS is a lightweight, simple NodeJS wrapper around the DiscordEmoji API.",
+ "homepage": "https://github.com/Jinzulen/DEmojiJS#readme",
+ "keywords": [
+ "discord",
+ "emojis",
+ "discordemoji",
+ "discordemoji.com",
+ "bots"
+ ],
+ "license": "ISC",
+ "main": "index.js",
+ "name": "demojijs",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/Jinzulen/DEmojiJS.git"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "version": "1.2.0"
+}
diff --git a/node_modules/demojijs/src/DEmojiJS.js b/node_modules/demojijs/src/DEmojiJS.js
new file mode 100644
index 0000000..45d8939
--- /dev/null
+++ b/node_modules/demojijs/src/DEmojiJS.js
@@ -0,0 +1,327 @@
+/**
+ * Copyright (c) 2018 Jinzulen <[email protected]>
+ *
+ * @license ISC
+ */
+
+const HTTPS = require('https'),
+ _ = require('underscore'),
+ Cache = require('node-file-cache').create({
+ file: 'demoji-cache',
+ life: 43200
+ });
+
+const Methods = {};
+
+/**
+ * Will tend to this among other things in later revisions.
+ *
+ * @todo Proper error handling.
+ */
+process.on('unhandledRejection', (E) => {
+ return;
+});
+
+function fetchAPI(Path, Callback)
+{
+ try
+ {
+ const cacheKey = Cache.get(Path);
+
+ if (!cacheKey)
+ {
+ HTTPS.get(Path, (Result) => {
+ let Error;
+ let rawData = '';
+ const Type = Result.headers['content-type'];
+ const Code = Result.statusCode;
+
+ if (Code !== 200)
+ {
+ Error = '# [DEmojiJS] Could not send request for the specified emoji. Status code: ' + Code;
+ Error.code = 'ERR_REQUEST_SEND';
+ } else if (Type.indexOf('application/json') === -1) {
+ Error = '# [DEmojiJS] The content received isn\'t JSON. The returned content type is: ' + Type;
+ Error.code = 'ERR_REQUEST_NOT_JSON';
+ };
+
+ if (Error)
+ {
+ Result.resume();
+ Callback(Error);
+ return;
+ };
+
+ Result.setEncoding('utf8');
+
+ Result.on('data', function (Buffer) {
+ rawData += Buffer;
+ });
+
+ Result.on('end', () => {
+ let Data = null;
+ let Error = null;
+
+ try
+ {
+ Data = JSON.parse(JSON.stringify(rawData));
+
+ if (Cache.set(Path, Data, 43200))
+ {
+ console.log(`# [DEmojiJS] Cached: ${Path}`);
+ }
+ } catch (unusedError) {
+ Error = '# [DEmojiJS] Failed to parse retrieved JSON.';
+ Error.code = 'ERR_JSON_PARSE';
+ };
+
+ Callback(Error, Data);
+ });
+ });
+ } else {
+ let Data = null;
+ let Error = null;
+
+ try
+ {
+ Data = JSON.parse(JSON.stringify(cacheKey));
+ } catch (unusedError) {
+ Error = '# [DEmojiJS] Failed to parse retrieved JSON.';
+ Error.code = 'ERR_JSON_PARSE';
+ };
+
+ Callback(Error, Data);
+ }
+ } catch (E) { throw E; };
+};
+
+Methods.allEmoji = function allEmoji (Callback)
+{
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if(Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ Resolve(JSON.parse(Result));
+ });
+ });
+};
+
+Methods.randomEmoji = function randomEmoji (Callback)
+{
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ const Parse = JSON.parse(Result);
+ const Count = Math.floor(Math.random() * Object.keys(Parse).length) + 1;
+
+ Resolve(Parse[Count]);
+ });
+ });
+};
+
+Methods.emojiByID = function emojiByID (ID, Callback)
+{
+ if (typeof ID !== 'number')
+ {
+ let Error = new TypeError('ID has to be a number.');
+ Error.code = 'ERR_ID_NOT_NUM'
+
+ throw Error;
+ };
+
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ Resolve(_.where(JSON.parse(Result), {
+ id: ID
+ })[0]);
+ });
+ });
+};
+
+Methods.emojiByName = function emojiByName (Name, Callback)
+{
+ if (typeof Name !== 'string')
+ {
+ let Error = new TypeError('Name has to be a string.');
+ Error.code = 'ERR_NAME_NOT_STRING'
+
+ throw Error;
+ };
+
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ Resolve(_.where(JSON.parse(Result), {
+ title: Name
+ })[0]);
+ });
+ });
+};
+
+Methods.emojiByAuthor = function emojiByAuthor (Author, Callback)
+{
+ if (typeof Author !== 'string')
+ {
+ let Error = new TypeError('Author has to be a string.');
+ Error.code = 'ERR_AUTHNAME_NOT_STRING'
+
+ throw Error;
+ };
+
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ Resolve(_.where(JSON.parse(Result), {
+ submitted_by: Author
+ }));
+ });
+ });
+};
+
+Methods.emojiByLicense = function emojiByLicense (License, Callback)
+{
+ if (typeof License !== 'string')
+ {
+ let Error = new TypeError('License has to be a string.');
+ Error.code = 'ERR_LIC_NOT_STRING'
+
+ throw Error;
+ };
+
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ const uLicense = License.toLowerCase();
+ const Licenses = {'basic':'0','cc by 4.0':'1','wtfpl':'2'};
+
+ if (!uLicense.indexOf(Licenses))
+ {
+ let Error = new TypeError('License not found.');
+ Error.code = 'ERR_LIC_NOT_FOUND'
+
+ throw Error;
+ };
+
+ Resolve(_.where(JSON.parse(Result), {
+ license: Licenses[uLicense]
+ }));
+ });
+ });
+};
+
+Methods.Statistics = function Statistics (Callback)
+{
+ return new Promise((Resolve, Reject) => {
+ fetchAPI('https://discordemoji.com/api/?request=stats', (Error, Result) => {
+ if (Error)
+ {
+ if (typeof Callback === 'function')
+ {
+ Callback(Error);
+ };
+
+ Reject(Error);
+ return;
+ };
+
+ if (typeof Callback === 'function')
+ {
+ Callback(null, Result[0]);
+ };
+
+ Resolve(JSON.parse(Result));
+ });
+ });
+};
+
+module.exports = Methods; \ No newline at end of file