-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2d86c7
commit 47de7c8
Showing
7 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
var formatDistanceToNow = require("date-fns/formatDistanceToNow"); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName("survey") | ||
.setDescription("Send surveys") | ||
.addSubcommand((subcommand) => | ||
subcommand | ||
.setName("by-role") | ||
.setDescription("Send surveys by role") | ||
.addRoleOption((option) => | ||
option | ||
.setName("role") | ||
.setDescription("name of the role") | ||
.setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option.setName("link").setDescription("survey link").setRequired(true) | ||
) | ||
) | ||
.addSubcommand((subcommand) => | ||
subcommand | ||
.setName("by-date") | ||
.setDescription("Send surveys by date") | ||
.addStringOption((option) => | ||
option.setName("link").setDescription("survey link").setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("since") | ||
.setDescription("date in timestamp (milliseconds)") | ||
.setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("till") | ||
.setDescription("date in timestamp (milliseconds)") | ||
) | ||
), | ||
async execute(interaction) { | ||
const guild = await interaction.client.guilds.cache.get( | ||
interaction.guildId | ||
); | ||
const Members = await guild.members.cache.map((member) => member); | ||
const link = interaction.options.getString("link"); | ||
|
||
if (interaction.options._subcommand === "by-role") { | ||
const role = interaction.options.getRole("role"); | ||
Members.map(async ({ roles, id, user, joinedTimestamp }) => { | ||
if (roles.cache.some((memberRole) => memberRole.name === role.name)) { | ||
const targetUser = await interaction.client.users.fetch(id); | ||
const message = `Dear ${user}, It's been ${formatDistanceToNow( | ||
joinedTimestamp | ||
)} Since you joined to the ${ | ||
guild.name | ||
}. \n\nWe'd love to hear how things are going!\nYour feedback is important to us!\n\nWe use it to ensure our dao is providing proper direction and to ensure we have the opportunity \nto change our approach to better suit your needs if necessary\n\nPlease use the following link to fill out the survey: | ||
\n${link}`; | ||
targetUser.send(message); | ||
} | ||
}); | ||
} else { | ||
const since = interaction.options.getString("since"); | ||
const till = interaction.options.getString("till"); | ||
Members.map(async ({ id, user, joinedTimestamp }) => { | ||
const message = `Dear ${user}, It's been ${formatDistanceToNow( | ||
joinedTimestamp | ||
)} Since you joined to the ${ | ||
guild.name | ||
}. \n\nWe'd love to hear how things are going!\nYour feedback is important to us!\n\nWe use it to ensure our dao is providing proper direction and to ensure we have the opportunity \nto change our approach to better suit your needs if necessary\n\nPlease use the following link to fill out the survey: | ||
\n${link}`; | ||
if (!user.bot) { | ||
if (till) { | ||
if (joinedTimestamp < till && joinedTimestamp > since) { | ||
const targetUser = await interaction.client.users.fetch(id); | ||
console.log(targetUser); | ||
targetUser.send(message); // 1655729528883 till | ||
} | ||
} else { | ||
if (joinedTimestamp > since) { | ||
const targetUser = await interaction.client.users.fetch(id); | ||
console.log(targetUser); | ||
targetUser.send(message); // 1654087928883 since | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
await interaction.reply({ content: "Surveys sent!!!", ephemeral: true }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require("node:fs"); | ||
const path = require("node:path"); | ||
const { REST } = require("@discordjs/rest"); | ||
const { Routes } = require("discord-api-types/v9"); | ||
require("dotenv").config(); | ||
|
||
const commands = []; | ||
const commandsPath = path.join(__dirname, "commands"); | ||
const commandFiles = fs | ||
.readdirSync(commandsPath) | ||
.filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of commandFiles) { | ||
const filePath = path.join(commandsPath, file); | ||
const command = require(filePath); | ||
commands.push(command.data.toJSON()); | ||
} | ||
|
||
const rest = new REST({ version: "9" }).setToken(process.env.TOKEN); | ||
|
||
(async () => { | ||
try { | ||
console.log("Started refreshing application (/) commands."); | ||
|
||
await rest.put( | ||
Routes.applicationGuildCommands( | ||
process.env.CLIENT_ID, | ||
process.env.GUILD_ID | ||
), | ||
{ | ||
body: commands, | ||
} | ||
); | ||
|
||
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { | ||
body: commands, | ||
}); | ||
|
||
console.log("Successfully reloaded application (/) commands."); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
name: "interactionCreate", | ||
async execute(interaction) { | ||
if (!interaction.isCommand()) return; | ||
|
||
const command = interaction.client.commands.get(interaction.commandName); | ||
|
||
if (!command) return; | ||
|
||
try { | ||
await command.execute(interaction); | ||
} catch (error) { | ||
console.error(error); | ||
await interaction.reply({ | ||
content: "There was an error while executing this command!", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
name: 'ready', | ||
once: true, | ||
execute(client) { | ||
console.log(`Ready! Logged in as ${client.user.tag}`); | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require("node:fs"); | ||
const path = require("node:path"); | ||
const { Client, Collection, Intents } = require("discord.js"); | ||
require("dotenv").config(); | ||
|
||
const intents = new Intents(32767); | ||
const client = new Client({ intents }); | ||
|
||
client.commands = new Collection(); | ||
const commandsPath = path.join(__dirname, "commands"); | ||
const commandFiles = fs | ||
.readdirSync(commandsPath) | ||
.filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of commandFiles) { | ||
const filePath = path.join(commandsPath, file); | ||
const command = require(filePath); | ||
client.commands.set(command.data.name, command); | ||
} | ||
|
||
const eventsPath = path.join(__dirname, "events"); | ||
const eventFiles = fs | ||
.readdirSync(eventsPath) | ||
.filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of eventFiles) { | ||
const filePath = path.join(eventsPath, file); | ||
const event = require(filePath); | ||
if (event.once) { | ||
client.once(event.name, (...args) => event.execute(...args)); | ||
} else { | ||
client.on(event.name, (...args) => event.execute(...args)); | ||
} | ||
} | ||
|
||
client.login(process.env.TOKEN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "pulseSurvey", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@discordjs/rest": "^0.5.0", | ||
"date-fns": "^2.28.0", | ||
"discord-api-types": "^0.34.0", | ||
"discord.js": "^13.8.0" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^16.0.1" | ||
} | ||
} |
Oops, something went wrong.