diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..175f95f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +Dockerfile +.dockerignore +.git +.gitignore +.env \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6704566..3add76d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ dist # TernJS port file .tern-port + +# Environment Variables +.env diff --git a/DockerFile b/DockerFile new file mode 100644 index 0000000..096c790 --- /dev/null +++ b/DockerFile @@ -0,0 +1,13 @@ +# Following https://www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker +FROM node:17 + +RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app + +WORKDIR /home/node/app +COPY package.json ./ +USER node +RUN npm install +COPY --chown=node:node . . + +EXPOSE 8080 +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/README.md b/README.md index b5e4f85..14de382 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ If you want to use this code for your game, you will need to create your own bot 5. In your new application, go to the 'Bot' section and click 'Add Bot'. Click the button to confirm that you want to create a bot. 6. Click on 'Click to Reveal Token' and then copy this. **WARNING**: DO NOT SHARE THIS TOKEN WITH ANYONE ELSE; it could be used to hack into your bot. 7. Go to the folder with the code and open Index.js (you can do this in notepad) -8. At the bottom of the file is the line "client.login('process.env.LOGIN_TOKEN');" replace process.env.LOGIN_TOKEN with the bot's token you've just copied (keep the single quote marks around it!). Save the file. +8. At the bottom of the file is the line `let token = process.env.LOGIN_TOKEN`. Replace this with `let token = "YOUR_TOKEN" where YOUR_TOKEN is bot's token you've just copied (keep the quote marks around it!). Save the file. Alternatively, set the token as the environment variable LOGIN_TOKEN. 9. You need some way to install the Javascript libraries; I suggest installing Node from https://nodejs.org/en/download/. You can then open a Node command prompt and enter "cd [folder address]" with the address of your new folder containing the bot code. This should navigate the command prompt to your folder. You should then enter the command 'npm install' to set up the libraries. @@ -33,6 +33,7 @@ Now that you have a bot, you need to know how to set it running. 2. Under '0Auth2', go to the URL Generator, and click 'bot'. Underneath this, you will see a new list of permissions; select 'Manage Roles', 'Manage Channels', 'Read Messages/View Channels', 'Send Messages', and 'Manage Messages'. 3. This will cause a URL to be generated under the 'permissions' section. Copy that URL and enter it into a web browser to invite the bot into your server. Make sure you've selected the permissions first as in the previous step, otherwise your bot won't be able to do its job! 4. Now you just need some way to run the code whenever you want the bot to be working. If you already installed Node earlier, you can use this. Open a Node command prompt and enter "cd [folder address]" with the address of your new folder containing the bot code. Finally, enter the command 'Node Index' to run the Index file. +5. You can also run the bot in docker if you prefer, using the dockerfile provided and supplying the token as an environment variable. Once the bot is already on your server, you only need to follow **step 4** again to set the bot going. Note that if the code is not currently being run somewhere, the bot won't function, and it will forget any games or game channels it made earlier if it closes while you were in the middle of a game. You can just run it on your own computer if you're happy with it only working when you're online, otherwise you'll need to find a server to keep it going. diff --git a/index.js b/index.js index 3d5b35c..21cf9bd 100644 --- a/index.js +++ b/index.js @@ -13,4 +13,7 @@ client.on('messageCreate', msg => { game.messagehandler(msg,client.user.id); }); -client.login(process.env.LOGIN_TOKEN); \ No newline at end of file +let token = process.env.LOGIN_TOKEN +if (!token) throw new Error("Missing token") + +client.login(token); \ No newline at end of file