This repository was archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
78 lines (69 loc) · 2.32 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const moment = require("moment");
const fs = require("fs");
const notrigger = require("./commands/notrigger/commands");
const path = require("path");
const Enmap = require("enmap");
const express = require("express");
const app = express();
const server = require("https").createServer(app);
const line = require("@waynechang65/linebot");
require("dotenv").config();
let client = line({
channelId: process.env.id,
channelSecret: process.env.channel,
channelAccessToken: process.env.secret,
});
const axios = require("axios");
client.commands = new Enmap();
//
fs.readdirSync("./commands").forEach((dirs) => {
const commands = fs
.readdirSync(`./commands/${dirs}`)
.filter((files) => files.endsWith(".js"));
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
console.log(`Loading command ${file}`);
client.commands.set(command.name.toLowerCase(), command);
}
});
//
const events = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"));
for (const file of events) {
console.log(`memuat event ${file}`);
const event = require(`./events/${file}`);
client.on(file.split(".")[0], event.bind(null, client));
}
app.use("/img", express.static(path.join(__dirname, "public")));
const linebotParser = client.parser();
app.post("/callback", linebotParser);
app.set("port", process.env.PORT || 3000); // Process.env.PORT change automatically the port IF 3000 port is being used.
app.listen(app.get("port"), () =>
console.log(`Node server listening on port ${app.get("port")}!`)
);
app.get("/", (request, response) => {
console.log(`Ping Received.`);
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Tama server for replit ping");
});
//CHAT CONSOLE
let y = process.openStdin();
y.addListener("data", (res) => {
let x = res.toString().trim().split(/ +/g);
client.push(process.env.consoleguild, x.join(" "));
});
notrigger(client);
//Unhandled rejection
process.on("unhandledRejection", (err) => {
console.error(err);
});
process.on("uncaughtException", function (err) {
console.error(err);
});
//err
client
.on("disconnect", () => console.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => console.log("Bot reconnecting...", "log"))
.on("error", (e) => console.log(e, "error"))
.on("warn", (info) => console.log(info, "warn"));