Hello there !
As I didn’t find any uses of the rescently added Adaptive Cards in the forum, I decided to try and make a really basic use of it ! I made it in Node.js because it is the language I use for scripting, but it should be easy to change it to lua or c#.
This snippet checks if the uses already has an account, and if he doesn’t, sends him a card. The user fills the card with his identity and sends it, then the server saves him in the database.
Notes :
- In this code, I use my own MongoDB resource, you should replace the
DB.user.?
with your database API of choice as well as theutils.getDiscordId
function. - I didn’t change the style of the card as this is just a test.
- I am trying to use the Adaptive Cards as a login page but hidden password inputs are not implemented yet, if anyone has a solution for this, feel free to share it !
Connection handler
on("playerConnecting", (name, setKickReason, deferrals) => {
deferrals.defer();
const discordId = utils.getDiscordId(global.source);
if (discordId) {
DB.user.FindByDiscordId(discordId, (err, user) => {
if (err) {
deferrals.done("An error has occured, please try again later.");
return;
} else if (user) {
deferrals.done();
return;
} else {
deferrals.presentCard(identityCard, (data) => {
if (data.last_name && data.first_name && data.nationality && data.sex && data.birth_date) {
const obj = {
discord_id: discordId,
identity: data,
}
DB.user.create(obj, (error) => {
if (error) {
deferrals.done("An error has occured, please try again later.");
return;
} else {
deferrals.done();
return;
}
});
} else {
deferrals.done("Please fill your identity card.");
return;
}
});
}
});
} else {
deferrals.done("Please launch Discord first.");
return;
}
});
Adaptive Card
const identityCard = {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Identity"
},
{
"type": "TextBlock",
"text": "Last name :",
"isSubtle": true
},
{
"type": "Input.Text",
"id": "last_name",
"maxLength": 60,
"placeholder": "Last name"
},
{
"type": "TextBlock",
"text": "First name :",
"isSubtle": true
},
{
"type": "Input.Text",
"id": "first_name",
"maxLength": 60,
"placeholder": "First name"
},
{
"type": "TextBlock",
"text": "Nationality :",
"isSubtle": true
},
{
"type": "Input.Text",
"id": "nationality",
"maxLength": 60,
"placeholder": "Nationality"
},
{
"type": "TextBlock",
"text": "Sex :",
"isSubtle": true
},
{
"type": "Input.ChoiceSet",
"choices": [
{
"title": "Male",
"value": "m"
},
{
"title": "Female",
"value": "f"
}
],
"id": "sex",
"value": "m"
},
{
"type": "TextBlock",
"text": "Birth date :",
"isSubtle": true
},
{
"type": "Input.Date",
"id": "birthdate"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Save"
}
]
}
Preview