Skip to content

Commit e39febd

Browse files
committed
slash commands
0 parents  commit e39febd

17 files changed

+4758
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
node_modules

Diff for: .prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 100
3+
}

Diff for: cognitoConfirmUser.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { CognitoUser } from "amazon-cognito-identity-js";
2+
import { createUserPool } from "./createUserPool.js";
3+
4+
const userPool = createUserPool();
5+
6+
export const cognitoConfirmUser = (username, code, callback) => {
7+
const cognitoUser = new CognitoUser({
8+
Username: username,
9+
Pool: userPool,
10+
});
11+
12+
cognitoUser.confirmRegistration(code, true, (err, result) => {
13+
if (err) {
14+
console.log(err);
15+
callback({
16+
message: "Uyelik onaylanamadi. Lutfen tekrar deneyin.",
17+
});
18+
return;
19+
}
20+
callback({
21+
message: "Uyelik onaylandi.",
22+
});
23+
});
24+
};

Diff for: cognitoResendActivation.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createUserPool } from "./createUserPool.js";
2+
import { CognitoUser } from "amazon-cognito-identity-js";
3+
4+
const userPool = createUserPool();
5+
6+
export const cognitoResendActivation = (username, callback) => {
7+
const cognitoUser = new CognitoUser({
8+
Username: username,
9+
Pool: userPool,
10+
});
11+
12+
cognitoUser.resendConfirmationCode((err) => {
13+
if (err) {
14+
callback({
15+
message: "Aktivasyon kodu gonderme islemi basarisiz. Lutfen tekrar deneyiniz",
16+
});
17+
return;
18+
}
19+
callback({
20+
message: "Aktivasyon kodu başarıyla gönderildi.",
21+
});
22+
});
23+
};

Diff for: cognitoSignUp.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { CognitoUserAttribute } from "amazon-cognito-identity-js";
2+
import { createUserPool } from "./createUserPool.js";
3+
4+
const generatePassword = (length) => {
5+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
6+
let password = "";
7+
for (let i = 0; i < length; i++) {
8+
password += characters.charAt(Math.floor(Math.random() * characters.length));
9+
}
10+
return password;
11+
};
12+
13+
const userPool = createUserPool();
14+
15+
export const cognitoSignUp = (username, email, callback) => {
16+
const emailData = {
17+
Name: "email",
18+
Value: email,
19+
};
20+
const emailAttribute = new CognitoUserAttribute(emailData);
21+
const password = generatePassword(8);
22+
23+
userPool.signUp(username, password, [emailAttribute], null, (err, result) => {
24+
if (err) {
25+
callback({ username: null, password: null, error: err.message });
26+
} else {
27+
callback({ username: result.user.getUsername(), password, error: null });
28+
}
29+
});
30+
};

Diff for: commands/confirmActivation.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { SlashCommandBuilder } from "@discordjs/builders";
2+
import { cognitoConfirmUser } from "../cognitoConfirmUser.js";
3+
4+
const confirmActivation = {
5+
data: new SlashCommandBuilder()
6+
.setName("uyelik-onayla")
7+
.setDescription("Uyelik onayla")
8+
.addStringOption((option) =>
9+
option.setName("kullanici-adi").setRequired(true).setDescription("Kullanici adinizi giriniz.")
10+
)
11+
.addStringOption((option) =>
12+
option
13+
.setName("aktivasyon-kodu")
14+
.setRequired(true)
15+
.setDescription("Aktivasyon kodunu giriniz.")
16+
),
17+
async execute(interaction) {
18+
const code = interaction.options.getString("aktivasyon-kodu");
19+
const username = interaction.options.getString("kullanici-adi");
20+
21+
cognitoConfirmUser(username, code, async ({ message }) => {
22+
await interaction.user.send(message);
23+
});
24+
},
25+
};
26+
27+
export default confirmActivation;

Diff for: commands/goLive.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { SlashCommandBuilder } from "@discordjs/builders";
2+
import { MessageEmbed } from "discord.js";
3+
4+
const goLive = {
5+
data: new SlashCommandBuilder()
6+
.setName("yayindayim")
7+
.setDescription("Yayinda oldugunu belli etmek icin kullanilir")
8+
.addStringOption((option) =>
9+
option.setName("yayin-basligi").setDescription("Yayin basligini belirtin").setRequired(true)
10+
)
11+
.addStringOption((option) =>
12+
option.setName("yayin-linki").setDescription("Yayin linkini belirtin").setRequired(true)
13+
),
14+
async execute(interaction, discordClient) {
15+
const streamTitle = interaction.options.getString("yayin-basligi");
16+
const streamLink = interaction.options.getString("yayin-linki");
17+
const channel = discordClient.channels.cache.get("672571847467860027");
18+
const user = interaction.user;
19+
20+
const exampleEmbed = new MessageEmbed()
21+
.setColor("#ff8a00")
22+
.setTitle(streamTitle)
23+
.setURL(streamLink)
24+
.setAuthor({
25+
name: user.username,
26+
iconURL: user.displayAvatarURL(),
27+
})
28+
.setDescription("Yayindayim arkadaslarim")
29+
.setImage("https://bit.ly/3k5XcAT")
30+
.setTimestamp();
31+
32+
// channel.send("@everyone, yayindayim! haberiniz olsun.");
33+
channel.send({ embeds: [exampleEmbed] });
34+
},
35+
};
36+
37+
export default goLive;

Diff for: commands/info.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { bold, SlashCommandBuilder, spoiler } from "@discordjs/builders";
2+
3+
const info = {
4+
data: new SlashCommandBuilder()
5+
.setName("info")
6+
.setDescription("Get info about a user or a server!")
7+
.addSubcommand((subcommand) =>
8+
subcommand
9+
.setName("user")
10+
.setDescription("Info about a user")
11+
.addUserOption((option) => option.setName("target").setDescription("The user"))
12+
)
13+
.addSubcommand((subcommand) =>
14+
subcommand.setName("server").setDescription("Info about the server")
15+
)
16+
.addSubcommand((subcommand) => subcommand.setName("deneme").setDescription("deneme")),
17+
async execute(interaction) {
18+
const subCommand = interaction.options.getSubcommand();
19+
const a = interaction.isMessageComponent();
20+
console.log(a, "AAAAAAAAAAAAAAAAA");
21+
console.log(interaction, "INTERACTION");
22+
23+
switch (subCommand) {
24+
case "user":
25+
const user = interaction.options.getUser("target");
26+
if (user) {
27+
await interaction.reply(`Username: ${user.username}\nID: ${user.id}`);
28+
} else {
29+
await interaction.reply(
30+
`Your username: ${interaction.user.username}\nYour ID: ${interaction.user.id}`
31+
);
32+
}
33+
break;
34+
35+
case "server":
36+
await interaction.reply(
37+
`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`
38+
);
39+
break;
40+
41+
case "deneme":
42+
await interaction.reply(
43+
`
44+
-> ${bold(
45+
"elwyron"
46+
)} <- ismiyle kayit oldunuz. Kayit oldugunuz maile aktivasyon kodu gonderilmistir.\n
47+
${bold(
48+
"/uyelik-onayla <aktivasyon-kodu>"
49+
)} komutunu calistirarak uyeliginizi onaylayabilirsiniz.\n
50+
Hesabinizin sifresi -> ${spoiler(
51+
"sifre"
52+
)} <- olarak ayarlanmistir. Bu sifreyini kullanarak https://pano.kamp.us/login adresinden giris yaptiktan sonra sifrenizi degistirmenizi oneririz.\n
53+
kamp.us'e hosgeldiniz!`
54+
);
55+
}
56+
},
57+
};
58+
59+
export default info;

Diff for: commands/resendActivation.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { SlashCommandBuilder } from "@discordjs/builders";
2+
import { cognitoResendActivation } from "../cognitoResendActivation.js";
3+
4+
const resendActivation = {
5+
data: new SlashCommandBuilder()
6+
.setName("uyelik-aktivasyon-kodu-yenile")
7+
.setDescription("Uyelik aktivasyon kodunu tekrar gonderir.")
8+
.addStringOption((option) =>
9+
option.setName("kullanici-adi").setRequired(true).setDescription("Kullanici adi")
10+
),
11+
async execute(interaction) {
12+
const username = interaction.options.getString("kullanici-adi");
13+
14+
cognitoResendActivation(username, async ({ message }) => {
15+
await interaction.user.send(message);
16+
});
17+
},
18+
};
19+
20+
export default resendActivation;

Diff for: commands/signup.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { SlashCommandBuilder } from "@discordjs/builders";
2+
import { cognitoSignUp } from "../cognitoSignUp.js";
3+
4+
const signup = {
5+
data: new SlashCommandBuilder()
6+
.setName("uye-ol")
7+
.setDescription("pano.kamp.us'a uye olmak icin kullanilir")
8+
.addStringOption((option) =>
9+
option
10+
.setName("kullanici-adi")
11+
.setDescription("pano.kamp.us'e kayit olmak icin kullanici adi")
12+
.setRequired(true)
13+
)
14+
.addStringOption((option) =>
15+
option
16+
.setName("e-posta")
17+
.setDescription("sunucuya kayit olmak icin email adresi")
18+
.setRequired(true)
19+
),
20+
async execute(interaction) {
21+
const email = interaction.options.getString("e-posta");
22+
const username = interaction.options.getString("kullanici-adi");
23+
const loginUrl = "https://pano.kamp.us/login";
24+
25+
cognitoSignUp(username, email, ({ username, password, error }) => {
26+
if (error) {
27+
interaction.reply(error);
28+
return;
29+
}
30+
interaction.reply("Hosgeldin, detaylari DM olarak gonderdim");
31+
interaction.user.send(
32+
`->${username}<- kullanici adiyla kayit olunuyor...\nSifreniz: ${password}\nLutfen bu bilgileri kullanarak ${loginUrl} sayfasindan giris yapiniz.`
33+
);
34+
});
35+
},
36+
};
37+
38+
export default signup;

Diff for: config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const DISCORD_TOKEN = "OTY3NTI0OTM2NTUxODk1MDUx.YmRj0A.Qgn849DFxCQpC2evCr2MB_suQ3A";
2+
export const GUILD_ID = "504590280675295233";
3+
export const CLIENT_ID = "967524936551895051";
4+
export const COGNITO_USERPOOL_ID = "eu-central-1_qjcEK6bV5";
5+
export const COGNITO_CLIENT_ID = "4gp7ftff543envgdr5alpa2105";

Diff for: createDiscordClient.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Create a new client instance
2+
import { Client, Collection, Intents } from "discord.js";
3+
import { readdirSync } from "fs";
4+
5+
export const createDiscordClient = async () => {
6+
const client = new Client({
7+
intents: [Intents.FLAGS.GUILDS],
8+
});
9+
10+
// When the client is ready, run this code (only once)
11+
client.once("ready", () => {
12+
console.log("Ready!");
13+
});
14+
15+
client.commands = new Collection();
16+
const commandFiles = readdirSync("./commands").filter((file) => file.endsWith(".js"));
17+
18+
for (const file of commandFiles) {
19+
const command = await import(`./commands/${file}`);
20+
client.commands.set(command.default.data.name, command);
21+
}
22+
23+
return client;
24+
};

Diff for: createUserPool.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { COGNITO_CLIENT_ID, COGNITO_USERPOOL_ID } from "./config.js";
2+
import { CognitoUserPool } from "amazon-cognito-identity-js";
3+
4+
const poolData = {
5+
UserPoolId: COGNITO_USERPOOL_ID,
6+
ClientId: COGNITO_CLIENT_ID,
7+
};
8+
9+
export const createUserPool = () => {
10+
return new CognitoUserPool(poolData);
11+
};

Diff for: deploy-commands.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Routes } from "discord-api-types/v9";
2+
import { REST } from "@discordjs/rest";
3+
import { CLIENT_ID, DISCORD_TOKEN, GUILD_ID } from "./config.js";
4+
import { readdirSync } from "fs";
5+
6+
const commands = [];
7+
const commandFiles = readdirSync("./commands").filter((file) => file.endsWith(".js"));
8+
9+
for (const file of commandFiles) {
10+
const command = await import(`./commands/${file}`);
11+
commands.push(command.default.data.toJSON());
12+
}
13+
14+
const rest = new REST({ version: "9" }).setToken(DISCORD_TOKEN);
15+
16+
rest
17+
.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands })
18+
.then(() => {
19+
console.log("Commands updated!");
20+
})
21+
.catch((error) => {
22+
console.error(error);
23+
});

Diff for: index.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { DISCORD_TOKEN } from "./config.js";
2+
import { createDiscordClient } from "./createDiscordClient.js";
3+
4+
const client = await createDiscordClient();
5+
6+
client.on("messageCreate", async (message) => {
7+
console.log(message, MESSAGE);
8+
if (message.content === "!ping") {
9+
await message.channel.send("Pong!");
10+
}
11+
// if (message.author.bot) return;
12+
// if (message.content.startsWith("!")) {
13+
// const command = message.content.slice(1);
14+
// const commandHandler = client.commandHandlers.get(command);
15+
// if (commandHandler) {
16+
// await commandHandler(message);
17+
// }
18+
// }
19+
});
20+
21+
client.on("interactionCreate", async (interaction) => {
22+
if (!interaction.isCommand()) return;
23+
console.log(interaction);
24+
25+
const command = client.commands.get(interaction.commandName);
26+
27+
if (!command) return;
28+
29+
try {
30+
await command.default.execute(interaction, client);
31+
} catch (error) {
32+
console.error(error);
33+
await interaction.reply({
34+
content: "There was an error trying to execute that command!",
35+
ephemeral: true,
36+
});
37+
}
38+
});
39+
40+
// Login to Discord with your client's token
41+
client.login(DISCORD_TOKEN);

0 commit comments

Comments
 (0)