mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-04-09 08:59:39 +00:00
Merge pull request #2 from Myxelium/fix-complaints
Add custom port support
This commit is contained in:
@@ -6,12 +6,15 @@ import fs from 'fs';
|
|||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import ip from 'ip';
|
import ip from 'ip';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
import { Handlers } from "./handlers/index"
|
import { Handlers } from "./handlers/index"
|
||||||
import { loadAvoidList } from '../helpers/load-avoid-list';
|
import { loadAvoidList } from '../helpers/load-avoid-list';
|
||||||
import { LoggerColors } from '../helpers/logger-colors';
|
import { LoggerColors } from '../helpers/logger-colors';
|
||||||
import { generateFileName } from '../helpers/generate-file-name';
|
import { generateFileName } from '../helpers/generate-file-name';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const storage = diskStorage({
|
const storage = diskStorage({
|
||||||
destination: 'sounds/',
|
destination: 'sounds/',
|
||||||
@@ -100,7 +103,7 @@ app.get('/avoidlist', (_req, res) => {
|
|||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
export function startServer() {
|
export function startServer() {
|
||||||
let port: 80 | 443 = 80;
|
let port: number = 80;
|
||||||
let server;
|
let server;
|
||||||
let ssl: "https" | "http" = "http";
|
let ssl: "https" | "http" = "http";
|
||||||
|
|
||||||
@@ -111,6 +114,7 @@ export function startServer() {
|
|||||||
key: fs.readFileSync(path.join(__dirname, '/certs/key.pem')),
|
key: fs.readFileSync(path.join(__dirname, '/certs/key.pem')),
|
||||||
cert: fs.readFileSync(path.join(__dirname, '/certs/cert.pem')),
|
cert: fs.readFileSync(path.join(__dirname, '/certs/cert.pem')),
|
||||||
};
|
};
|
||||||
|
|
||||||
server = https.createServer(options, app);
|
server = https.createServer(options, app);
|
||||||
ssl = "https";
|
ssl = "https";
|
||||||
port = 443;
|
port = 443;
|
||||||
@@ -120,6 +124,10 @@ export function startServer() {
|
|||||||
ssl = "http";
|
ssl = "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.WEBPORT) {
|
||||||
|
port = parseInt(process.env.WEBPORT, 10);
|
||||||
|
}
|
||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Server started at ${ssl}://${ip.address()}:${port}`);
|
console.log(`Server started at ${ssl}://${ip.address()}:${port}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "Discord bot randomly plays sounds",
|
"description": "Discord bot randomly plays sounds",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "ts-node bot.ts",
|
"start": "ts-node bot.ts",
|
||||||
"create": "node -e \"require('fs').writeFileSync('.env', 'TOKEN=MY-API-TOKEN\\nINTERVALMIN_MINUTES=10\\nINTERVALMAX_HOURS=6\\nVOICECHANNELRETRIES=12')\"",
|
"create": "node -e \"require('fs').writeFileSync('.env', 'TOKEN=MY-API-TOKEN\\nINTERVALMIN_MINUTES=10\\nINTERVALMAX_HOURS=6\\nVOICECHANNELRETRIES=12')\" && mkdir sounds",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "SocksOnHead",
|
"author": "SocksOnHead",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ TOKEN=<your Discord bot token>
|
|||||||
INTERVALMIN_MINUTES=<minimum interval in minutes>
|
INTERVALMIN_MINUTES=<minimum interval in minutes>
|
||||||
INTERVALMAX_HOURS=<maximum interval in hours>
|
INTERVALMAX_HOURS=<maximum interval in hours>
|
||||||
VOICECHANNELRETRIES=<number of retries to find a voice channel with members in it>
|
VOICECHANNELRETRIES=<number of retries to find a voice channel with members in it>
|
||||||
|
WEBPORT=<The port you want to use for the webserver, (Optional)>
|
||||||
```
|
```
|
||||||
|
|
||||||
replace `<your Discord bot token>` with your actual Discord bot token. replace `<minimum interval in minutes>`, `<maximum interval in hours>`, and `<number of retries to find a voice channel with members in it>` with your desired values.
|
replace `<your Discord bot token>` with your actual Discord bot token. replace `<minimum interval in minutes>`, `<maximum interval in hours>`, and `<number of retries to find a voice channel with members in it>` with your desired values.
|
||||||
|
|||||||
Reference in New Issue
Block a user