-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (50 loc) · 2.08 KB
/
index.js
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
const mongoose = require('mongoose');
const discord = require('discord.js');
const stickerController = require("./controller/stickerController");
const langStrings = require("./language/language_strings");
const lang = require("./language/language");
const dc = new discord.Client();
const express = require('express');
const app = express();
const PREFIX = ".s";
require('dotenv').config()
app.use(express.static('public'));
app.use(express.urlencoded({
limit: "500mb",
extended: true
}));
app.use(express.json({limit: "500mb"}));
mongoose.connect(process.env.HOST_NAME, {
useNewUrlParser: true,
useUnifiedTopology: true
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'Database Connection ERROR:'));
dc.login(process.env.TOKEN, console.log(`Connected`)).catch((err) => console.log(`Connection failed: ${err}`));
dc.on('ready', () => {
console.log('Bot Ready!');
});
dc.on('message', async message => {
if (message.content.startsWith(PREFIX)) {
const input = message.content.slice(PREFIX.length).trim().split(' ');
const command = input.shift();
if (command === "add") stickerController.addSticker(message.guild.id, message.member.roles.cache, input, (err) => {
message.channel.send(lang.useTemplate(langStrings.tr.add[err], [input[0]]))
});
else if (command === "remove") stickerController.removeSticker(message.guild.id, message.member.roles.cache, input, (err) => {
message.channel.send(lang.useTemplate(langStrings.tr.remove[err], [input[0]]))
});
else if (command === "help"){
message.channel.send(langStrings.tr.help[0]);
message.channel.send(langStrings.tr.help[1]);
message.channel.send(langStrings.tr.help[2]);
}
else stickerController.getSticker(message.guild.id, command, (result) => {
if (result) message.channel.send(result.url);
else message.channel.send(lang.useTemplate(langStrings.tr.use[0], command));
});
}
});
app.get("/", (req, res) => res.sendFile("index.html"));
app.post("/sticker", (req, res) => console.log(req.body));
app.listen(process.env.PORT, () => console.log(`Sunucu ${process.env.PORT} da başladı`));