feat: ✨ Introduce role check and timer before server stop
All checks were successful
Publish staging Docker image / Push Docker image to Gitea Container Registry (push) Successful in 1m40s
All checks were successful
Publish staging Docker image / Push Docker image to Gitea Container Registry (push) Successful in 1m40s
This commit is contained in:
parent
320cdc2b14
commit
a0656c5831
14
.github/workflows/push-docker.yml
vendored
14
.github/workflows/push-docker.yml
vendored
@ -7,12 +7,12 @@
|
|||||||
# To get a newer version, you will need to update the SHA.
|
# To get a newer version, you will need to update the SHA.
|
||||||
# You can also reference a tag or branch, but the action may change without warning.
|
# You can also reference a tag or branch, but the action may change without warning.
|
||||||
|
|
||||||
name: Publish Docker image
|
name: Publish staging Docker image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- feature/*
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
push_to_registry:
|
push_to_registry:
|
||||||
@ -30,6 +30,14 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
-
|
||||||
|
# Add support for more platforms with QEMU (optional)
|
||||||
|
# https://github.com/docker/setup-qemu-action
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
|
@ -29,12 +29,25 @@ module.exports = {
|
|||||||
content: 'Are you sure you want to start the Minecraft server?',
|
content: 'Are you sure you want to start the Minecraft server?',
|
||||||
components: [row]
|
components: [row]
|
||||||
})
|
})
|
||||||
|
// Before stop variable which return the time between now and 4am in discord timestamp
|
||||||
|
const date = new Date(new Date().setDate(new Date().getDate() + 1))
|
||||||
|
date.setUTCHours(3, 0, 0, 0)
|
||||||
|
const test = Math.round(date.getTime() / 1000);
|
||||||
const collectorFilter = i => i.user.id === interaction.user.id;
|
const collectorFilter = i => i.user.id === interaction.user.id;
|
||||||
|
let allowed = false;
|
||||||
|
for (const role of config.allowedRoles) {
|
||||||
|
if (interaction.member.roles.cache.has(role)) {
|
||||||
|
allowed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 30_000 });
|
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 30_000 });
|
||||||
if (confirmation.customId === 'confirm') {
|
if (confirmation.customId === 'confirm') {
|
||||||
proxmox.qemu.start("pve", "102", function(err, res) {
|
if (!allowed) {
|
||||||
|
await confirmation.update({ content: 'You do not have permission to start the Minecraft server.', components: [] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
proxmox.qemu.start("pve", "103", function(err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
confirmation.update("Error starting the Minecraft server: " + err);
|
confirmation.update("Error starting the Minecraft server: " + err);
|
||||||
} else {
|
} else {
|
||||||
@ -44,7 +57,7 @@ module.exports = {
|
|||||||
.setURL('https://mc.louisgallet.fr')
|
.setURL('https://mc.louisgallet.fr')
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.addComponents(linkButton)
|
.addComponents(linkButton)
|
||||||
confirmation.update({content: "Minecraft server started successfully. Please wait a few minutes for it to boot.", components: [row]});
|
confirmation.update({content: "Minecraft server started successfully. Please wait a few minutes for it to boot. Use the command `/stop-mc` to stop it, otherwise, the server will be automatically shut down " + `<t:${test}:R>`, components: [row]});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (confirmation.customId === 'cancel') {
|
} else if (confirmation.customId === 'cancel') {
|
||||||
@ -53,6 +66,5 @@ module.exports = {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
await confirmation.update({ content: 'You took too long to respond.', components: [] });
|
await confirmation.update({ content: 'You took too long to respond.', components: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ module.exports = {
|
|||||||
.setName('stop-mc')
|
.setName('stop-mc')
|
||||||
.setDescription('Stops the minecraft server machine.'),
|
.setDescription('Stops the minecraft server machine.'),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
proxmox.qemu.shutdown("pve", "102", function(err, res) {
|
proxmox.qemu.shutdown("pve", "103", function(err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
interaction.reply("Error starting the Minecraft server: " + err);
|
interaction.reply("Error starting the Minecraft server: " + err);
|
||||||
} else {
|
} else {
|
||||||
|
17
commands/utility/check-perms.js
Normal file
17
commands/utility/check-perms.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js')
|
||||||
|
const config = require('../../config.json')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('check-perms')
|
||||||
|
.setDescription('Check if the user has the correct permissions to start the Minecraft server.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
for (const role of config.allowedRoles) {
|
||||||
|
if (interaction.member.roles.cache.has(role)) {
|
||||||
|
await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true });
|
||||||
|
},
|
||||||
|
}
|
13
commands/utility/test-time.js
Normal file
13
commands/utility/test-time.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('test-time')
|
||||||
|
.setDescription('Test the time between now and 4am in discord timestamp'),
|
||||||
|
async execute(interaction) {
|
||||||
|
const date = new Date(new Date().setDate(new Date().getDate() + 1))
|
||||||
|
date.setUTCHours(3, 0, 0, 0)
|
||||||
|
const test = Math.round(date.getTime() / 1000);
|
||||||
|
await interaction.reply({ content: `Time between now and 4am: <t:${test}:R>`}, {ephemeral: true});
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user