summaryrefslogtreecommitdiff
path: root/node_modules/demojijs/README.md
blob: 528befe75b62e3d1d4ddb67288a7fe7de7f6149c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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.