Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit d082de6
Author: yanukadeneth99 <[email protected]>
Date:   Sun Aug 21 16:42:34 2022 +0530

    Worked on getting the balance of goerli

commit 4d83345
Author: yanukadeneth99 <[email protected]>
Date:   Sun Aug 21 15:34:47 2022 +0530

    Worked on Feedback

commit 84e42c8
Author: yanukadeneth99 <[email protected]>
Date:   Sun Aug 21 02:05:14 2022 +0530

    Removed website command

commit 1421fa9
Author: yanukadeneth99 <[email protected]>
Date:   Sun Aug 21 00:22:56 2022 +0530

    Removed unwanted packages and moved to discord.js

commit 4d897b0
Author: yanukadeneth99 <[email protected]>
Date:   Sun Aug 21 00:10:15 2022 +0530

    Checking Webhook discord github

commit bd0ddcb
Author: yanukadeneth99 <[email protected]>
Date:   Sat Aug 20 23:30:42 2022 +0530

    Updated code
  • Loading branch information
yanukadeneth99 committed Aug 21, 2022
1 parent 80c70a5 commit a771777
Show file tree
Hide file tree
Showing 21 changed files with 761 additions and 357 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ DCB_CLIENT_ID="00000000000"
# Discord Server ID
DCB_GUILD_ID="00000000000"
# Discord Channel ID to post log
DCB_BOT_LOG_CHANNEL="000000000"
DCB_LOG_CHANNEL="000000000"
# Discord Admin Role ID
DCB_ADMIN_ROLE_ID="00000000"
# Discord Feedback Channel ID
DCB_FEEDBACK_CHANNEL="00000000000"
# Goerli Alchemy Key
ALCHEMY_GOERLI_URL="https://eth-goerli.g.alchemy.com/v2/xxxxxxxxxxxxxxxxxxxx"
# Own Wallet Address
WALLET_ADDRESS="xxxxxxxxxxxxxxxxxxxxx"
```
4 changes: 2 additions & 2 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Exporting the Client

const { Client, Intents } = require("discord.js");
const { Client, GatewayIntentBits } = require("discord.js");

// Create a new Client with these permissions
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

module.exports = client;
31 changes: 31 additions & 0 deletions commands/balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Get the balance of the Address only for admins

const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("balance")
.setDescription("Get the balance remaining of the contract")
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption((option) =>
option
.setName("network")
.setDescription("Select the network to view balance")
.setRequired(true)
.addChoices({
name: "Goerli",
value: "goerli",
})
)
.addStringOption((option) =>
option
.setName("token")
.setDescription("Token Type to search")
.setRequired(false)
.addChoices({
name: "ETH",
value: "eth",
})
),
};
5 changes: 3 additions & 2 deletions commands/beep.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Respond user beep with Boop

const { SlashCommandBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("beep")
.setDescription("Replies with boop!"),
.setDescription("Replies with boop!")
.setDMPermission(true),
};
3 changes: 2 additions & 1 deletion commands/echo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Replying the User with what the user typed

const { SlashCommandBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("echo")
.setDescription("Replies with your input!")
.setDMPermission(true)
.addStringOption((option) =>
option
.setName("input")
Expand Down
11 changes: 11 additions & 0 deletions commands/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generate a Modal where you can enter your required eth
// Address, Token(LINK, ETH, MATIC), Network(Mumbai,Rinkeby)

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("feedback")
.setDescription("Send Feedback to the Faucet Bot")
.setDMPermission(true),
};
7 changes: 3 additions & 4 deletions commands/info.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Replies user with user info or server info

const { SlashCommandBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Get info about a user or a server!")
.setDMPermission(false)
.addSubcommand((subcommand) =>
subcommand
.setName("user")
Expand All @@ -15,8 +16,6 @@ module.exports = {
)
)
.addSubcommand((subcommand) =>
subcommand
.setName("server")
.setDescription("Info about the server")
subcommand.setName("server").setDescription("Info about the server")
),
};
6 changes: 4 additions & 2 deletions commands/ping.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Respond the user with the bot's ping

const { SlashCommandBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Check the ping of the bot (for admins only)"),
.setDescription("Check the ping of the bot (for admins only)")
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
};
26 changes: 26 additions & 0 deletions delete-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Run `node delete-commands.js` to delete all the commands

const { REST } = require("@discordjs/rest");
const { Routes } = require("discord.js");
require("dotenv").config();

// Get the REST
const rest = new REST({ version: "10" }).setToken(process.env.DCB_TOKEN);

//* Use to remove all commands from the Guild
// rest
// .put(
// Routes.applicationGuildCommands(
// process.env.DCB_CLIENT_ID,
// process.env.DCB_GUILD_ID
// ),
// { body: [] }
// )
// .then(() => console.log("Successfully deleted all guild commands."))
// .catch(console.error);

//* Use to remove all commands publically
rest
.put(Routes.applicationCommands(process.env.DCB_CLIENT_ID), { body: [] })
.then(() => console.log("Successfully deleted all application commands."))
.catch(console.error);
31 changes: 23 additions & 8 deletions deploy-commands.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
const fs = require("fs");
//? Run `node deploy-commands.js` to set the commands

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({ path: ".env" });
const { Routes } = require("discord.js");
require("dotenv").config();

// Get the commands from the `/commands` folder and to the array
const commands = [];
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync("./commands")
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
const command = require(`./commands/${file}`);
const commandPath = path.join(commandsPath, file);
const command = require(commandPath);
commands.push(command.data.toJSON());
}

const rest = new REST({ version: "9" }).setToken(process.env.DCB_TOKEN);
// Get the REST
const rest = new REST({ version: "10" }).setToken(process.env.DCB_TOKEN);

//* Use for Development (Updates only the passed guild data)
rest
.put(
Routes.applicationGuildCommands(
process.env.DCB_CLIENT_ID,
process.env.DCB_GUILD_ID
), //* Use for Production
//Routes.applicationCommands(process.env.DBC_CLIENT_ID) //* Use for Development as its updated instantly (no cache)
),
{ body: commands }
)
.then(() => console.log("Successfully registered application commands"))
.catch(console.error);

//* Use for Production as it updates the commands public
// rest
// .put(Routes.applicationCommands(process.env.DCB_CLIENT_ID), {
// body: commands,
// })
// .then(() => console.log("Successfully registered application commands"))
// .catch(console.error);
51 changes: 40 additions & 11 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
// For all the Interactions

const { InteractionType } = require("discord.js");

module.exports = {
name: "interactionCreate",
async execute(interaction) {
if (!interaction.isCommand()) return;

if (interaction.commandName === "beep") {
await require("../responses/beep_response")(interaction);
} else if (interaction.commandName === "echo") {
await require("../responses/echo_response")(interaction);
} else if (interaction.commandName === "info") {
await require("../responses/info_response")(interaction);
} else if (interaction.commandName === "ping") {
await require("../responses/ping_response")(interaction);
async execute(client, interaction) {
// Chat Commands only
if (interaction.isChatInputCommand()) {
if (interaction.commandName === "beep") {
await require("../responses/beep_response")(interaction);
} else if (interaction.commandName === "echo") {
await require("../responses/echo_response")(interaction);
} else if (interaction.commandName === "info") {
await require("../responses/info_response")(interaction);
} else if (interaction.commandName === "ping") {
await require("../responses/ping_response")(interaction);
} else if (interaction.commandName === "feedback") {
await require("../responses/feedback_response")(interaction);
} else if (interaction.commandName === "balance") {
await require("../responses/balance_response")(interaction);
}
}
// Modal Commands
else if (interaction.type === InteractionType.ModalSubmit) {
if (interaction.customId === "feedbackModal") {
// Get the Feedback Channel
const fdChannel = await client.channels.cache.get(
process.env.DCB_FEEDBACK_CHANNEL
);
// Get the value of the sent messages and send on the feedback channel
const subject = interaction.fields.getTextInputValue("subject");
const description = interaction.fields.getTextInputValue("description");
fdChannel.send(
`[FEEDBACK] | ${new Date(
Date.now()
).toUTCString()} | Subject : ${subject} | Description : ${description}`
);
// Reply the user
await interaction.reply({
content: `Your feedback of ${subject} was received successfully!`,
ephemeral: true,
});
}
}
// Final Reply if non exists
else {
Expand Down
12 changes: 6 additions & 6 deletions events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module.exports = {
console.log(`Ready! Logged in as ${client.user.tag}`);

const logchannel = await client.channels.cache.get(
process.env.DCB_BOT_LOG_CHANNEL
);
logchannel.send(
`${new Date(
Date.now()
).toUTCString()} | Faucet Bot | Restarted, and set activity`
process.env.DCB_LOG_CHANNEL
);
// logchannel.send(
// `[LOGIN] | ${new Date(
// Date.now()
// ).toUTCString()} | Faucet Bot | Restarted, and set activity`
// );

// Setting Status of Bot
await client.user.setActivity("a tutorial on how to be a good bot", {
Expand Down
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
//* Run node deploy-commands to register the commands added

// Requires
const fs = require("fs");
const fs = require("node:fs");
const path = require("node:path");
const { Collection } = require("discord.js");
require("dotenv").config({ path: ".env" });
const client = require("./client"); // Get Client

// Get the Events
// Run the Events depending on whether it's once or on.
const eventsPath = path.join(__dirname, "events");
const eventFiles = fs
.readdirSync("./events")
.readdirSync(eventsPath)
.filter((file) => file.endsWith(".js"));

// Run the Events depending on whether it's once or on.
for (const file of eventFiles) {
const event = require(`./events/${file}`);
const ePath = path.join(eventsPath, file);
const event = require(ePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
client.on(event.name, (...args) => event.execute(client, ...args));
}
}

// Setting Commands
client.commands = new Collection();

// Gets all command files
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync("./commands")
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));

// Setting the command for every file
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
const filePath = path.join(commandsPath, file);
const command = require(filePath);
//Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
"author": "Yanuka Deneth",
"license": "MIT",
"dependencies": {
"@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.3.0",
"@discordjs/rest": "^1.0.1",
"axios": "^0.26.1",
"discord-api-types": "^0.27.1",
"discord-rpc": "^4.0.1",
"discord.js": "^13.6.0",
"discordbot": "^0.0.21",
"dotenv": "^16.0.1"
"discord-api-types": "^0.37.3",
"discord.js": "^14.2.0",
"dotenv": "^16.0.1",
"ethers": "^5.7.0"
}
}
Loading

0 comments on commit a771777

Please sign in to comment.