forked from Dragios/Discord-Bot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Significantly reduced deployment size * Bot starts up much more faster
- Loading branch information
Showing
9 changed files
with
4,098 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Node.js CI | |
|
||
on: | ||
push: | ||
branches: [ master ] | ||
branches: [ "*" ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,5 @@ config/development.json | |
CMakeLists.txt.user* | ||
|
||
/dist | ||
# Parcel's cache | ||
/.parcel-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@parcel/config-default", | ||
"resolvers": ["@parcel/resolver-glob", "..."] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash -e | ||
yarn | ||
|
||
[ -d "dist" ] && rm -rf dist | ||
|
||
echo "[+] Applying patches to accommodate bundler ..." | ||
for i in patches/*.patch; do | ||
echo "Applying $i ..." | ||
patch -Np1 --no-backup-if-mismatch -i "$i" | ||
done | ||
|
||
yarn run parcel build | ||
|
||
echo "[+] Installing non-bundle-able packages ..." | ||
cd "dist" | ||
echo '{"name": "citra-discord-bot","license": "GPL-2.0+"}' > package.json | ||
yarn add discord.js@^13 | ||
cd .. | ||
|
||
echo "[+] Reversing patches ..." | ||
for i in patches/*.patch; do | ||
echo "Reversing $i ..." | ||
patch -Np1 -R -i "$i" | ||
done | ||
|
||
echo "[+] Removing patch backup files ..." | ||
find . -name "*.orig" -print -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
From 2ae094e7ad43d9137fafe84a36eac3e9bf0a8245 Mon Sep 17 00:00:00 2001 | ||
From: liushuyu <liushuyu011@gmail.com> | ||
Date: Wed, 15 Sep 2021 22:49:40 -0600 | ||
Subject: [PATCH] server: make it bundler friendly | ||
|
||
--- | ||
src/server.ts | 49 ++++++++++++++++++++----------------------------- | ||
1 file changed, 20 insertions(+), 29 deletions(-) | ||
|
||
diff --git a/src/server.ts b/src/server.ts | ||
index bc63ae7..7cf8825 100644 | ||
--- a/src/server.ts | ||
+++ b/src/server.ts | ||
@@ -1,5 +1,7 @@ | ||
// Check for environmental variables. | ||
-require('checkenv').check(); | ||
+const checkenv = require('checkenv'); | ||
+checkenv.setConfig(require('../env.json')); | ||
+checkenv.check(); | ||
|
||
import discord = require('discord.js'); | ||
import path = require('path'); | ||
@@ -9,6 +11,10 @@ import logger from './logging'; | ||
import state from './state'; | ||
import * as data from './data'; | ||
import { IModule, ITrigger } from './models/interfaces'; | ||
+// Parcel glob imports | ||
+import commands from './commands/*.ts'; | ||
+import triggers from './triggers/*.ts'; | ||
+import responses from './responses/*.json'; | ||
|
||
interface IModuleMap { | ||
[name: string]: IModule; | ||
@@ -233,37 +239,16 @@ client.on('message', message => { | ||
}); | ||
|
||
// Cache all command modules. | ||
-cachedModules = {}; | ||
-fs.readdirSync('./commands/').forEach(function (file) { | ||
- // Load the module if it's a script. | ||
- if (path.extname(file) === '.js') { | ||
- if (file.includes('.disabled')) { | ||
- logger.info(`Did not load disabled module: ${file}`); | ||
- } else { | ||
- const moduleName = path.basename(file, '.js').toLowerCase(); | ||
- logger.info(`Loaded module: ${moduleName} from ${file}`); | ||
- cachedModules[moduleName] = require(`./commands/${file}`); | ||
- } | ||
- } | ||
+cachedModules = commands; | ||
+Object.entries(commands).forEach(function (command) { | ||
+ logger.info(`Loaded command: ${command[0]}`); | ||
}); | ||
|
||
// Cache all triggers. | ||
cachedTriggers = []; | ||
-fs.readdirSync('./triggers/').forEach(function (file) { | ||
- // Load the module if it's a script. | ||
- if (path.extname(file) === '.js') { | ||
- if (file.includes('.disabled')) { | ||
- logger.info(`Did not load disabled trigger: ${file}`); | ||
- } else { | ||
- const moduleName = path.basename(file, '.js').toLowerCase(); | ||
- logger.info(`Loaded trigger: ${moduleName} from ${file}`); | ||
- try { | ||
- cachedTriggers.push(require(`./triggers/${file}`)); | ||
- } catch (e) { | ||
- logger.error(`Could not load trigger ${moduleName}: ${e}`); | ||
- } | ||
- } | ||
- } | ||
+Object.entries(triggers).forEach((trigger: [string, ITrigger]) => { | ||
+ cachedTriggers.push(trigger[1]); | ||
+ logger.info(`Loaded trigger: ${trigger[0]}`); | ||
}); | ||
|
||
data.readWarnings(); | ||
@@ -271,7 +256,13 @@ data.readBans(); | ||
|
||
// Load custom responses | ||
if (process.env.DATA_CUSTOM_RESPONSES) { | ||
- data.readCustomResponses(); | ||
+ // Load the responses file into the responses variable. | ||
+ state.responses = responses[process.env.TENANT]; | ||
+ if (!state.responses) { | ||
+ logger.error(`Failed to load ${process.env.TENANT} from cache! Custom responses are disabled.`); | ||
+ } else { | ||
+ logger.debug(`Loaded ${process.env.TENANT} responses from cache.`); | ||
+ } | ||
} | ||
|
||
client.login(process.env.DISCORD_LOGIN_TOKEN); | ||
-- | ||
2.33.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- a/node_modules/winston/dist/winston.js 2021-08-26 22:26:24.296000000 -0600 | ||
+++ b/node_modules/winston/dist/winston.js 2021-09-15 23:35:13.136034453 -0600 | ||
@@ -6,7 +6,7 @@ | ||
*/ | ||
'use strict'; | ||
|
||
-var logform = require('logform'); | ||
+import * as logform from 'logform/dist/browser.js'; | ||
|
||
var _require = require('./winston/common'), | ||
warn = _require.warn; |
Oops, something went wrong.