Skip to content

Commit 303e898

Browse files
committed
V1.0
0 parents  commit 303e898

File tree

4 files changed

+1087
-0
lines changed

4 files changed

+1087
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# API example for discord bot
2+
3+
This is an example to get random images or videos for your discord bot
4+
5+
## Usage
6+
7+
### For discord bot written in python
8+
9+
For the images/videos
10+
```py
11+
def genshin():
12+
response = requests.get('https://api.pellinuz.repl.co/api/type=genshin')
13+
if response.status_code == 200:
14+
image_url = response.json()['message']
15+
image_url = random.choice("message")
16+
else:
17+
print('Error getting random image')
18+
return image_url
19+
```
20+
21+
For the color
22+
```py
23+
def embedColor():
24+
response = requests.get('https://api.pellinuz.repl.co/api?type=genshin')
25+
if response.status_code == 200:
26+
color = int(response.json()['color'], 16)
27+
embed_color = discord.Color(color)
28+
else:
29+
print('Error getting random color')
30+
embed_color = discord.Color.default()
31+
return embed_color
32+
```
33+
34+
Define the functions
35+
```py
36+
genshin_images = genshin()
37+
color_embed = embedColor()
38+
```
39+
40+
Command example
41+
```py
42+
@client.slash_command(name="image", description="Random Image")
43+
async def image(ctx):
44+
await ctx.respond(genshin())
45+
```
46+
47+
### For discord bot written in js
48+
49+
For the images/videos
50+
```js
51+
async function genshin() {
52+
const response = await fetch('https://api.pellinuz.repl.co/api?type=genshin');
53+
if (response.ok) {
54+
const image_url = (await response.json()).message;
55+
return image_url;
56+
} else {
57+
console.log('Error getting random image');
58+
}
59+
}
60+
```
61+
62+
For color
63+
```js
64+
async function embedColor() {
65+
const response = await fetch('https://api.pellinuz.repl.co/api?type=genshin');
66+
if (response.ok) {
67+
const color = parseInt((await response.json()).color, 16);
68+
const embedColor = new Discord.MessageEmbed().setColor(color);
69+
return embedColor;
70+
} else {
71+
console.log('Error getting random color');
72+
const embedColor = new Discord.MessageEmbed().setColor('DEFAULT');
73+
return embedColor;
74+
}
75+
}
76+
```
77+
78+
NOTE: if the js codes isn't right it isn't my problem, it has been conveted using ChatGPT
79+
80+
## HOST
81+
82+
[![Run on Repl.it](https://replit.com/badge/github/pellinuz/api)](https://replit.com/new/github/pellinuz/api)

index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const express = require('express');
2+
const app = express();
3+
const path = require('path');
4+
const router = express.Router();
5+
const port = 5000
6+
7+
let count = 0;
8+
9+
app.use(express.static('public'));
10+
11+
12+
app.get("/",function(req,res) {
13+
res.json({ "message": "Check docs not made", "example": "https://api.pellinuz.repl.co/api?type=genshin"});
14+
});
15+
16+
17+
app.get('/api', (req, res) => {
18+
const type = req.query.type;
19+
if (type === 'examples') {
20+
//media
21+
const imageLinks = [
22+
`https://t3.ftcdn.net/jpg/00/92/53/56/240_F_92535664_IvFsQeHjBzfE6sD4VHdO8u5OHUSc6yHF.jpg`,
23+
`http://www.clker.com/cliparts/e/1/d/1/1513780035272509829example-stamp-vector.med.png`
24+
];
25+
26+
const randomIndex = Math.floor(Math.random() * imageLinks.length);
27+
28+
//random number
29+
const min = 1000000;
30+
const max = 9999999;
31+
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
32+
33+
res.json({ message: imageLinks[randomIndex], color: `${randomNumber}`});
34+
35+
}
36+
});
37+
38+
app.listen(port, () => {
39+
console.log(`Example app listening on port ${port}`)
40+
})

0 commit comments

Comments
 (0)