Added minecraft to discord messages
This commit is contained in:
parent
1e72ecdf53
commit
0f54fbf07e
Binary file not shown.
@ -1,9 +1,9 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
const simpleEmbed = (value) => {
|
const simpleEmbed = (content) => {
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
.setColor(process.env.EMBED_COLOR)
|
.setColor(process.env.EMBED_COLOR)
|
||||||
.setDescription(value);
|
.setDescription(content);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { simpleEmbed };
|
module.exports = { simpleEmbed };
|
||||||
|
@ -8,9 +8,16 @@ const applyUsername = async (user, member) => {
|
|||||||
rawUsername = minecraftProfile.name;
|
rawUsername = minecraftProfile.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.rawUsername = rawUsername;
|
||||||
|
|
||||||
|
await user.save();
|
||||||
await member.setNickname(rawUsername);
|
await member.setNickname(rawUsername);
|
||||||
|
|
||||||
return rawUsername;
|
return rawUsername;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { applyUsername };
|
const getUsername = (user) => {
|
||||||
|
return user.rawUsername;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { applyUsername, getUsername };
|
||||||
|
@ -59,8 +59,10 @@ const app = express();
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
const verifyMinecraftRoute = require('./routes/verifyminecraft');
|
const verifyMinecraftRoute = require('./routes/verifyminecraft');
|
||||||
|
const messageRoute = require('./routes/message');
|
||||||
|
|
||||||
app.use('/verifyminecraft', verifyMinecraftRoute);
|
app.use('/verifyminecraft', verifyMinecraftRoute);
|
||||||
|
app.use('/message', messageRoute);
|
||||||
|
|
||||||
app.listen('3000', () => {
|
app.listen('3000', () => {
|
||||||
console.log('Express app is running');
|
console.log('Express app is running');
|
||||||
|
56
discordbot/routes/message.js
Normal file
56
discordbot/routes/message.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const { WebhookClient, EmbedBuilder } = require('discord.js');
|
||||||
|
const { getUsername } = require('../functions/utils.js');
|
||||||
|
const { Users } = require('../functions/models.js');
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
const webhookClient = new WebhookClient({ url: process.env.MINECRAFT_WEBHOOK_URL });
|
||||||
|
|
||||||
|
router.post('/player', async (req, res) => {
|
||||||
|
const { content, uuid } = req.body;
|
||||||
|
|
||||||
|
if (!uuid || !content) return res.status(400).send({ errorMessage: 'uuid and content are required' });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await Users.findOne({ where: { minecraftUUID: uuid } });
|
||||||
|
|
||||||
|
const username = getUsername(user);
|
||||||
|
|
||||||
|
webhookClient.send({
|
||||||
|
content,
|
||||||
|
username,
|
||||||
|
avatarURL: 'https://api.mineatar.io/face/' + uuid + '?scale=8',
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send({ status: 'ok' });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
res.status(500).send({ errorMessage: 'Error while sending player message' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/game', async (req, res) => {
|
||||||
|
const { content, uuid } = req.body;
|
||||||
|
|
||||||
|
if (!uuid || !content) return res.status(400).send({ errorMessage: 'uuid and content are required' });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const messageEmbed = new EmbedBuilder()
|
||||||
|
.setColor(process.env.EMBED_COLOR)
|
||||||
|
.setAuthor({ name: content, iconURL: 'https://api.mineatar.io/face/' + uuid + '?scale=8' });
|
||||||
|
|
||||||
|
webhookClient.send({
|
||||||
|
embeds: [messageEmbed],
|
||||||
|
username: 'Server',
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send({ status: 'ok' });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
res.status(500).send({ errorMessage: 'Error while sending player message' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -1,5 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { Minecraft } = require('../functions/models.js');
|
const { Minecraft, Users } = require('../functions/models.js');
|
||||||
|
const { getUsername } = require('../functions/utils.js');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -16,7 +17,10 @@ router.post('/', async (req, res) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
res.send({ code: minecraftCol[0].code, whitelisted: minecraftCol[0].whitelisted, username: 'Username', rawUsername: 'RawUsername' });
|
const user = await Users.findOne({ where: { minecraftUUID: uuid } });
|
||||||
|
const username = getUsername(user);
|
||||||
|
|
||||||
|
res.send({ code: minecraftCol[0].code, whitelisted: minecraftCol[0].whitelisted, username, rawUsername: user.rawUsername });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user