From 444605ecbe2019a5e8e7bd7829494071f4dd8db7 Mon Sep 17 00:00:00 2001 From: Stanislaw <62724833+BoberITman@users.noreply.github.com> Date: Sun, 26 Jun 2022 19:40:23 +0200 Subject: [PATCH] dockerization --- .github/deploy.yaml | 23 +++++++++++++++++++ Dockerfile | 6 +++++ events/messageCreate.js | 51 ++++++++++++++++++++++++++--------------- main.js | 26 ++++++++++----------- 4 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 .github/deploy.yaml create mode 100644 Dockerfile diff --git a/.github/deploy.yaml b/.github/deploy.yaml new file mode 100644 index 0000000..4f8d0f4 --- /dev/null +++ b/.github/deploy.yaml @@ -0,0 +1,23 @@ +name: Deploy + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +jobs: + build: + runs-on: self-hosted + steps: + - uses: actions/checkout@v3 + - name: Build image + run: docker build -t ${{ github.repository }} . + - name: Deploy image + run: | + docker stop muzykant || true + docker rm muzykant || true + docker stop muzykant2 || true + docker rm muzykant2 || true + docker run -d -e "DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN_1 }}" -e "PREFIX=";" --restart always --name muzykant ${{ github.repository }} + docker run -d -e "DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN_2 }}" -e "PREFIX=":" --restart always --name muzykant2 ${{ github.repository }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b4e9620 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +# syntax=docker/dockerfile:1 +FROM node:16.10.0 +WORKDIR /app +COPY ./ ./ +RUN npm install +CMD ["node", "index.js"] \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js index 7cb9502..67395ea 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -1,30 +1,45 @@ module.exports = (client, message) => { - if (message.author.bot || message.channel.type === 'dm') return; + if (message.author.bot || message.channel.type === "dm") return; - const prefix = client.config.app.px; + const prefix = process.env.PREFIX; - if (message.content.indexOf(prefix) !== 0) return; + if (message.content.indexOf(prefix) !== 0) return; - const args = message.content.slice(prefix.length).trim().split(/ +/g); - const command = args.shift().toLowerCase(); + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); - const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command)); + const cmd = + client.commands.get(command) || + client.commands.find((cmd) => cmd.aliases && cmd.aliases.includes(command)); - const DJ = client.config.opt.DJ; + const DJ = client.config.opt.DJ; - if (cmd && DJ.enabled && DJ.commands.includes(cmd.name)) { - const roleDJ = message.guild.roles.cache.find(x => x.name === DJ.roleName); + if (cmd && DJ.enabled && DJ.commands.includes(cmd.name)) { + const roleDJ = message.guild.roles.cache.find( + (x) => x.name === DJ.roleName + ); - if (!message.member._roles.includes(roleDJ.id)) { - return message.channel.send(`This command is reserved for members with the ${DJ.roleName} role on the server ${message.author}... try again ? ❌`); - } + if (!message.member._roles.includes(roleDJ.id)) { + return message.channel.send( + `This command is reserved for members with the ${DJ.roleName} role on the server ${message.author}... try again ? ❌` + ); } + } - if (cmd && cmd.voiceChannel) { - if (!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${message.author}... try again ? ❌`); + if (cmd && cmd.voiceChannel) { + if (!message.member.voice.channel) + return message.channel.send( + `You're not in a voice channel ${message.author}... try again ? ❌` + ); - if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`You are not in the same voice channel ${message.author}... try again ? ❌`); - } + if ( + message.guild.me.voice.channel && + message.member.voice.channel.id !== message.guild.me.voice.channel.id + ) + return message.channel.send( + `You are not in the same voice channel ${message.author}... try again ? ❌` + ); + } - if (cmd) cmd.execute(client, message, args); -}; \ No newline at end of file + if (cmd) cmd.execute(client, message, args); +}; diff --git a/main.js b/main.js index 01a56f2..78f3590 100644 --- a/main.js +++ b/main.js @@ -1,21 +1,21 @@ -const { Player } = require('discord-player'); -const { Client, Intents } = require('discord.js'); +const { Player } = require("discord-player"); +const { Client, Intents } = require("discord.js"); global.client = new Client({ - intents: [ - Intents.FLAGS.GUILDS, - Intents.FLAGS.GUILD_MEMBERS, - Intents.FLAGS.GUILD_MESSAGES, - Intents.FLAGS.GUILD_VOICE_STATES - ], - disableMentions: 'everyone', + intents: [ + Intents.FLAGS.GUILDS, + Intents.FLAGS.GUILD_MEMBERS, + Intents.FLAGS.GUILD_MESSAGES, + Intents.FLAGS.GUILD_VOICE_STATES, + ], + disableMentions: "everyone", }); -client.config = require('./config'); +client.config = require("./config"); global.player = new Player(client, client.config.opt.discordPlayer); -require('./src/loader'); -require('./src/events'); +require("./src/loader"); +require("./src/events"); -client.login(client.config.app.token); \ No newline at end of file +client.login(process.env.DISCORD_TOKEN);