-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
14 changed files
with
1,591 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,108 @@ | ||
const fs = require('fs'); | ||
const csv = require('csv-parser'); | ||
let IDs = []; | ||
let LABELS = []; | ||
let roles=[]; | ||
let rolemoji='' | ||
require('dotenv').config(); | ||
const { | ||
Client, | ||
IntentsBitField, | ||
ActionRowBuilder, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
|
||
} = require('discord.js'); | ||
function containsEmoji(str) { | ||
const emojiRegex = /(\p{Emoji_Presentation}|\p{Emoji}\uFE0F|\p{Emoji_Modifier_Base}|\p{Emoji_Component}|\u200D[\p{Emoji}]+|\p{Emoji})(\uFE0F|\u20E3)?/gu; | ||
return emojiRegex.test(str); | ||
} | ||
const client = new Client({ | ||
intents: [ | ||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMembers, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.MessageContent, | ||
], | ||
}); | ||
|
||
|
||
function readCSVAndPopulateArrays(filePath) { | ||
fs.createReadStream(filePath) | ||
.pipe(csv()) | ||
.on('data', (data) => { | ||
const [LABEL, ID] = Object.values(data); | ||
LABELS.push(LABEL); | ||
IDs.push(ID); | ||
}) | ||
.on('end', () => { | ||
|
||
for (let i = 0; i < IDs.length; i++) { | ||
roles.push({ | ||
id:IDs[i], | ||
label:LABELS[i] | ||
|
||
}) | ||
} | ||
|
||
|
||
}); | ||
|
||
} | ||
|
||
readCSVAndPopulateArrays("./csv/roles.csv") | ||
|
||
|
||
|
||
|
||
client.on('ready', async (c) => { | ||
try { | ||
const guild = await client.guilds.fetch(process.env.GUILD_ID); | ||
|
||
|
||
const channel = await client.channels.cache.get(process.env.ReactRole); | ||
if (!channel) return; | ||
var welcomeMessage = `React to the roles relative to you to gain access to different parts of the server | ||
Select according to your current status | ||
—————————————————————————————— | ||
KU Student - | ||
KU Alumni - | ||
Working - | ||
Out Student - | ||
——————————————————————————————`; | ||
|
||
|
||
|
||
|
||
|
||
const message=await channel.send({ | ||
content: welcomeMessage, | ||
|
||
}); | ||
|
||
const filePath = "./csv/reactmessage.txt"; | ||
fs.writeFileSync(filePath, `${message.id}\n`, function(err) { | ||
if (err) throw err; | ||
|
||
}); | ||
|
||
for (let i = 0; i < roles.length; i++) { | ||
rolemoji=roles[i].label | ||
|
||
if(!containsEmoji(rolemoji)){ | ||
const emojis = await guild.emojis.fetch(); | ||
|
||
const newemoji = emojis.find(e => e.name === rolemoji); | ||
rolemoji=newemoji | ||
} | ||
|
||
await message.react(rolemoji.id ? `<:${rolemoji.name}:${rolemoji.id}>` : rolemoji); | ||
} | ||
process.exit(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}); | ||
|
||
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,49 @@ | ||
require('dotenv').config(); | ||
const { REST, Routes,ApplicationCommandOptionType } = require('discord.js'); | ||
|
||
const commands = [ | ||
{ | ||
name: 'createrole', | ||
description: 'create a new role along with the needed channel(Admin Level Only)', | ||
options:[ | ||
{ | ||
name:'role_name', | ||
description:'name of the role', | ||
type: ApplicationCommandOptionType.String, | ||
required: true, | ||
}, | ||
{ | ||
name: 'role_emoji', | ||
description: 'emoji for the role', | ||
type: ApplicationCommandOptionType.String, | ||
required: true, | ||
}, | ||
|
||
|
||
] | ||
}, | ||
|
||
|
||
|
||
|
||
]; | ||
|
||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); | ||
|
||
(async () => { | ||
try { | ||
console.log('Registering slash commands...'); | ||
|
||
await rest.put( | ||
Routes.applicationGuildCommands( | ||
process.env.CLIENT_ID, | ||
process.env.GUILD_ID | ||
), | ||
{ body: commands } | ||
); | ||
|
||
console.log('Slash commands were registered successfully!'); | ||
} catch (error) { | ||
console.log(`There was an 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 @@ | ||
1256665015117680642 |
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,8 @@ | ||
emoji,Role | ||
😀,1256550175174950922 | ||
😊,1256550703686615041 | ||
😃,1256550539303325757 | ||
😁,1256550802416472066 | ||
🍏,1256660401739923477 | ||
Sigil_of_Baphomet,1256660569327538261 | ||
🧢,1256665937336340614 |
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,54 @@ | ||
const fs = require('fs'); | ||
const csv = require('csv-parser'); | ||
const Discord = require("discord.js"); | ||
const { | ||
Client, | ||
IntentsBitField, | ||
ActionRowBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
ModalBuilder, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
EmbedBuilder, | ||
ChannelType, | ||
PermissionFlagsBits, | ||
} = require("discord.js"); | ||
|
||
|
||
|
||
require("dotenv").config(); | ||
module.exports = async (client) => { | ||
client.on('messageCreate', async (message) => { | ||
const channel = await client.channels.fetch(process.env.ANNOUNCEMENT_ID); | ||
// Ignore messages from the bot itself | ||
if (message.author.bot) return; | ||
|
||
// Check if the message starts with *KUCC | ||
if (message.content.startsWith('*KUCC ')) { | ||
// Check if the author has the "moderator" role | ||
const moderatorRole = message.guild.roles.cache.find(role => role.name === 'moderators'); | ||
if (!moderatorRole || !message.member.roles.cache.has(moderatorRole.id)) { | ||
const reply = await message.reply('You do not have the necessary role to use this command.'); | ||
setTimeout(() => reply.delete(), 5000); // Delete reply after 5 seconds | ||
return; | ||
} | ||
|
||
// Extract the text after *KUCC | ||
const kuccText = message.content.slice(6).trim(); | ||
await channel.send({ | ||
content: kuccText, | ||
|
||
}); | ||
|
||
// Do something with the text | ||
|
||
|
||
// Respond to the message and delete the response after a delay | ||
const reply = await message.reply(`You triggered the KUCC command with: ${kuccText}`); | ||
setTimeout(() => reply.delete(), 5000); // Delete reply after 5 seconds | ||
|
||
} | ||
}); | ||
|
||
}; |
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,64 @@ | ||
const Discord = require("discord.js"); | ||
const { | ||
Client, | ||
IntentsBitField, | ||
ActionRowBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
ModalBuilder, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
EmbedBuilder, | ||
ChannelType, | ||
PermissionFlagsBits, | ||
|
||
} = require("discord.js"); | ||
|
||
const createchannels=require("./submodules/channelcreation.js") | ||
|
||
module.exports = async (interaction) => { | ||
try{ | ||
//previlage check | ||
const newrole = interaction.options.get('role_name').value; | ||
const modRole = interaction.guild.roles.cache.find( | ||
(role) => role.name === "moderators" | ||
); | ||
const hasrole = interaction.member.roles.cache.has(modRole.id); | ||
|
||
if (!hasrole) { | ||
await interaction.reply({ | ||
content: "Not enough privilege to use this command", | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
|
||
//check if role exists | ||
const mentioned = interaction.guild.roles.cache.find( | ||
(role) => role.name == newrole | ||
); | ||
|
||
if (mentioned) { | ||
await interaction.reply({ | ||
content: "Role Already Exists", | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
|
||
//if not exists now create | ||
createchannels(interaction); | ||
|
||
await interaction.reply({ | ||
content: `Role ${newrole} and associated channels created successfully.`, | ||
ephemeral: true, | ||
}); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
await interaction.reply({ | ||
content: "An error occurred while creating the role or channels.", | ||
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,93 @@ | ||
const fs = require('fs'); | ||
const csv = require('csv-parser'); | ||
const Discord = require("discord.js"); | ||
const { | ||
Client, | ||
IntentsBitField, | ||
ActionRowBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
ModalBuilder, | ||
ButtonBuilder, | ||
ButtonStyle, | ||
EmbedBuilder, | ||
ChannelType, | ||
PermissionFlagsBits, | ||
} = require("discord.js"); | ||
|
||
async function readCSVAndPopulateArrays(filePath) { | ||
let IDs = []; | ||
let LABELS = []; | ||
let roles = []; | ||
|
||
return new Promise((resolve, reject) => { | ||
fs.createReadStream(filePath) | ||
.pipe(csv()) | ||
.on('data', (data) => { | ||
const [LABEL, ID] = Object.values(data); | ||
LABELS.push(LABEL); | ||
IDs.push(ID); | ||
}) | ||
.on('end', () => { | ||
for (let i = 0; i < IDs.length; i++) { | ||
roles.push({ | ||
id: IDs[i], | ||
label: LABELS[i] | ||
}); | ||
} | ||
|
||
resolve(roles); | ||
}) | ||
.on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
require("dotenv").config(); | ||
module.exports = async (client) => { | ||
const channel = client.channels.cache.get(process.env.ReactRole); | ||
const messageold = await channel.messages.fetch(process.env.MessageId); | ||
|
||
client.on('messageReactionAdd', async (reaction, user) => { | ||
if (user.bot) return; // Ignore reactions from bots | ||
|
||
const roles = await readCSVAndPopulateArrays("./csv/roles.csv"); | ||
|
||
|
||
const { message, emoji } = reaction; | ||
const guild = message.guild; | ||
const member = await guild.members.fetch(user.id); | ||
|
||
if (message.id == messageold.id) { // Replace 'YOUR_MESSAGE_ID' with the actual message ID | ||
for (let i = 0; i < roles.length; i++) { | ||
if (emoji.name == roles[i].label) { | ||
await member.roles.add(roles[i].id); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
client.on('messageReactionRemove', async (reaction, user) => { | ||
if (user.bot) return; // Ignore reactions from bots | ||
|
||
const roles = await readCSVAndPopulateArrays("./csv/roles.csv"); | ||
const { message, emoji } = reaction; | ||
const guild = message.guild; | ||
const member = await guild.members.fetch(user.id); | ||
|
||
if (message.id === messageold.id) { // Replace 'messageold.id' with the actual message ID | ||
for (let i = 0; i < roles.length; i++) { | ||
if (emoji.name === roles[i].label) { | ||
const roleId = roles[i].id; | ||
const roleToRemove = guild.roles.cache.get(roleId); | ||
if (roleToRemove && member.roles.cache.has(roleId)) { | ||
await member.roles.remove(roleId); | ||
|
||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
}; |
Oops, something went wrong.