diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0bf1312 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +discloud.config diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/Comands/general/sendInformationMessage.js b/Comands/general/sendInformationMessage.js deleted file mode 100644 index 7d2894f..0000000 --- a/Comands/general/sendInformationMessage.js +++ /dev/null @@ -1,31 +0,0 @@ -const Discord = require("discord.js"); -const cron = require('node-cron'); -const client = require("../../bot"); -const dayjs = require("dayjs"); - -const sendInformationMessage = async () => { - const horaMensagem = dayjs().set('date', 7).set('hour', 8).set('minute', 00).set('second', 0); - const horaAtual = dayjs(); - - if (horaMensagem.isBefore(horaAtual)) { - horaMensagem.add(1, 'month'); - } - - const diff = horaMensagem.diff(horaAtual); - - setTimeout(async () => { - const channelToSend = await client.channels - .fetch("1113553458931437720") - .catch(() => null); - - if (channelToSend) { - const embed = new Discord.EmbedBuilder() - .setDescription("**📢 Dia de rodar o comando ```.rw``` no servidor _Discloud >> 🔌 commands_!**") - .setColor(15548997); - - channelToSend.send({ embeds: [embed] }); - } - }, diff); -}; - -cron.schedule('0 8 7 * *', sendInformationMessage); \ No newline at end of file diff --git a/Comands/general/sendMessage.js b/Comands/general/sendMessage.js index 394cb08..470e282 100644 --- a/Comands/general/sendMessage.js +++ b/Comands/general/sendMessage.js @@ -1,6 +1,6 @@ const Discord = require("discord.js"); const schedule = require("node-schedule"); -const client = require("../../bot") +const client = require("../../index") const jobOne = schedule.scheduleJob("0 8 * * *", () => { sendMessage("8:00", "Ancoron"); diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..81b1305 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# syntax = docker/dockerfile:1 + +# Adjust NODE_VERSION as desired +ARG NODE_VERSION=20.11.1 +FROM node:${NODE_VERSION}-slim as base + +LABEL fly_launch_runtime="Node.js" + +# Node.js app lives here +WORKDIR /app + +# Set production environment +ENV NODE_ENV="production" + + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Install packages needed to build node modules +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3 + +# Install node modules +COPY --link package.json ./ +RUN npm install + +# Copy application code +COPY --link . . + + +# Final stage for app image +FROM base + +# Copy built application +COPY --from=build /app /app + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD [ "node", "index.js" ] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..ebb586f --- /dev/null +++ b/fly.toml @@ -0,0 +1,22 @@ +# fly.toml app configuration file generated for bot-discord-wandering-sun-3360 on 2024-08-06T14:16:58-03:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'bot-discord-wandering-sun-3360' +primary_region = 'gru' + +[build] + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/bot.js b/index.js similarity index 100% rename from bot.js rename to index.js diff --git a/package.json b/package.json index f41497f..c756a92 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,24 @@ { "name": "bot-discord", "version": "1.0.0", - "description": "", + "description": "Bot criado para gerar alertas avisando sobre algum compromisso.", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "keywords": [], - "author": "", - "license": "ISC", + "keywords": [ + "bot", + "discord", + "node-schedule", + "alerta" + ], + "author": "Jackson Dhanyel Santin", + "license": "MIT", "dependencies": { - "dayjs": "^1.11.8", - "discord.js": "^14.11.0", + "dayjs": "^1.11.12", + "discord.js": "^14.15.3", "fs": "^0.0.1-security", - "node-cron": "^3.0.2", + "node-cron": "^3.0.3", "node-schedule": "^2.1.1" } }