ππ π£π’π₯π§ππ‘π§: π¬π’π¨ π‘πππ π§π’ π₯π¨π‘ π§πππ¦ ππ’ππ ππ₯π’π ππ¨π§π’ππ’ππ π’π‘ππ π§π’ ππ₯πππ§π π§ππ π¦πππ¦π ππ’π π ππ‘π! This is a snippet used to log activity time of your staff members. They have to do /activity clockin when they come online to start and /activity clockout when they go offline. The time from when they do /activity clockin to /activity clockout will be logged and can be later viewed as /activity data. Commands: /activity clockin: Clocks you in, /activity clockout: Clocks you out, /activity data {{mentioned}}: See the total time of the mentioned user, /activity reset {{mentioned}}: Reset the total time of the mentioned user, /activity help: Shows the help menu
// ππ π£π’π₯π§ππ‘π§: π¬π’π¨ π‘πππ π§π’ π₯π¨π‘ π§πππ¦ ππ’ππ ππ₯π’π ππ¨π§π’ππ’ππ π’π‘ππ π§π’ ππ₯πππ§π π§ππ π¦πππ¦π ππ’π π ππ‘π!
/* This is a snippet used to log activity time of your staff members.
They have to do /activity clockin when they come online to start and /activity clockout when they go offline.
The time from when they do /activity clockin to /activity clockout will be logged and can be later viewed as /activity data
Commands: /activity clockin: Clocks you in
/activity clockout: Clocks you out
/activity data {{mentioned}}: See the total time of the mentioned user
/activity reset {{mentioned}}: Reset the total time of the mentioned user
/activity help: Shows the help menu
*/
// <------ Packages ------>
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const convertMS = require('ms-convert');
const event = context.params.event;
let users = await lib.keyvalue.store['@0.1.16'].get({key: `activity`});
// <------ Slash Command Creation ------>
if (!users) { // if the command is not created
await lib.discord.commands['@0.0.0'].create({
guild_id: process.env.guildID,
name: 'activity',
description: 'Track Staff Activity Time',
options: [
{type: 1,name: 'clockin',description: 'Clocks you in.'},
{type: 1,name: 'clockout',description: 'Clocks you out'},
{type: 1,name: 'data',description: 'Get activity for a specified user.',options: [{type: 6,name: 'user',description: 'User to get activity for.',required: true}]},
{type: 1,name: 'reset',description: 'Reset activity for a specific user.',options: [{type: 6,name: 'user',description: 'User to reset activity for.',required: true}]},
{type: 1,name: 'help',description: 'Show Commands.'},
],
});
await lib.keyvalue.store['@0.1.16'].set({key: `activity`,value: {created: true, user: {}}});
await lib.keyvalue.store['@0.1.16'].set({key: `active-users`,value: {}});
console.log('Slash Command Created! Use it from discord!')
return 'Slash Command Created! Use it from discord!'
}
if (event.channel_id == '0000000000000000') { // If the command is not being used from discord
console.log('Use the command from discord!')
return 'Use the command from discord!'
} else {
if (event.member.roles.includes(process.env.StaffRoleID)) { // Checks if user has Staff Role
let user_id = event.member.user.id;
let active_users = await lib.keyvalue.store['@0.1.16'].get({key: `active-users`});
await lib.discord.interactions['@1.0.1'].responses.create({token: event.token,response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE'});
let message = {token: event.token,content: ` `,embeds: [{type: 'rich',title: ``,description: [`\`/activity clockin\`: Clocks you in`,`\`/activity clockout\`: Clocks you out`,`\`/activity data {{mentioned}}\`: See the total time of the mentioned user`,`\`/activity reset {{mentioned}}\`: Reset the total time of the mentioned user`,`\`/activity help\`: Shows the help menu`].join('\n'),color: 0xFF0000,footer: {text: `This bot was created by Nintendo_bot#7518.`}}],};
if (event.data.options[0].name == 'clockin') { // <------ For Clockin ------>
if (active_users[user_id]) {
message.embeds[0].description = `You are already clocked in!`;
return lib.discord.interactions['@1.0.1'].followups.create(message);
};
message.embeds[0].description = `<@${user_id}> successfully clocked in`
await lib.discord.interactions['@1.0.1'].followups.create(message);
active_users[user_id] = event.received_at;
await lib.keyvalue.store['@0.1.16'].set({key: 'active-users',value: active_users});
}
if (event.data.options[0].name == 'clockout') { // <------ For Clockout ------>
if (!active_users[user_id]) {
message.embeds[0].description = `You need to clockin first!`;
return lib.discord.interactions['@1.0.1'].followups.create(message);
}
let date = active_users[user_id];
let duration = new Date() - new Date(date);
if (users.user[user_id]) {total = users.user[user_id]} else {total = 0};
users.user[user_id] = duration + total;
await lib.keyvalue.store['@0.1.16'].set({key: `activity`,value: users});
message.embeds[0].description = `<@${user_id}> successfully clocked out. Added ${convertMS(duration)} to their time. Their total time is **${convertMS(duration + total)}**`;
await lib.discord.interactions['@1.0.1'].followups.create(message);
delete active_users[user_id];
await lib.keyvalue.store['@0.1.16'].set({key: `active-users`,value: active_users});
}
if (event.data.options[0].name == 'data') { // <------ For Getting User Data ------>
if (!users.user[event.data.options[0].options[0].value]) {
message.embeds[0].description = `No Data Found for the user!`;
return lib.discord.interactions['@1.0.1'].followups.create(message);
}
let total = users.user[user_id];
message.embeds[0].description = `**<@${event.data.options[0].options[0].value}>'s Total Time is: ${convertMS(total)}**`;
await lib.discord.interactions['@1.0.1'].followups.create(message);
}
if (event.data.options[0].name == 'reset') { // <------ For resetting User Data ------>
message.embeds[0].description = `**Reset Time For <@${event.data.options[0].options[0].value}>**`;
if (!users.user[event.data.options[0].options[0].value]) {
message.embeds[0].description = `No Data Found for the user!`;
return lib.discord.interactions['@1.0.1'].followups.create(message);
}
delete users.user[event.data.options[0].options[0].value];
await lib.keyvalue.store['@0.1.16'].set({key: `activity`,value: users});
await lib.discord.interactions['@1.0.1'].followups.create(message);
}
if (event.data.options[0].name == 'help') { // <------ To Show All commands ------>
message.embeds[0].title = `Commands:`;
await lib.discord.interactions['@1.0.1'].followups.create(message);
}
} else { // <------- If user does not have Staff Role ------>
await lib.discord.interactions['@1.0.1'].responses.create({token: event.token,content: `You do not have the permission to use this!`});
}
}