Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Elite-tch/starky into fix-n…
Browse files Browse the repository at this point in the history
  • Loading branch information
Elite-tch committed Feb 18, 2025
2 parents ec583e6 + bffc645 commit 62ddb80
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 1,360 deletions.
118 changes: 118 additions & 0 deletions db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Database Setup Guide

This guide provides step-by-step instructions for setting up a PostgreSQL database, including environment variable configuration and troubleshooting common issues.

---

## Prerequisites

Ensure the following are installed on your system:

- [PostgreSQL](https://www.postgresql.org/download/)
- [Node.js](https://nodejs.org/)
- [Docker](https://www.docker.com/) (optional, for containerized setup)

---

## 1. Install PostgreSQL

### Option 1: Local Installation

1. Download and install PostgreSQL from the [official website](https://www.postgresql.org/download/).
2. During installation, set a username and password. Use "mysecretpassword" as the password.
3. Verify the installation:
```sh
psql --version
```

### Option 2: Docker Installation (Alternative)

Run the following command to set up PostgreSQL in a Docker container:

```sh
docker run --name starky-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
```
(Please checkout the port if it matches yours.)

---

## 2. Configure Environment Variables

Create a `.env` file in your project's root directory and add the following:

```sh
NEXT_PUBLIC_DISCORD_CLIENT_ID=your_application_id
DISCORD_BOT_TOKEN=your_bot_token
DATABASE_URL=postgresql://postgres:mysecretpassword@localhost:5432/postgres
DOMAIN=http://localhost:8080
PORT=8080
NODE_ENV=development
BASE_URL=http://localhost:8080/
UPDATE_STATUS_EVERY_SECONDS=5
APIBARA_AUTH_TOKEN_MAINNET=xxx
APIBARA_AUTH_TOKEN_SEPOLIA=xxx
APIBARA_DEFAULT_BLOCK_NUMBER_MAINNET=644802
APIBARA_DEFAULT_BLOCK_NUMBER_SEPOLIA=70133
STARKSCAN_API_KEY=xxx
RPC_URL_MAINNET=https://rpc.starknet.id/
RPC_URL_SEPOLIA=https://sepolia.rpc.starknet.id/
WATCHTOWER_ENABLED=false
APP_ID=xxx
WATCHTOWER_URL=https://api.watchtower.starknet.id/service/add_message
WATCHTOWER_TOKEN=xxx
LOG_EVERY_X_BLOCK=1
```

## 3. Install Dependencies

Install the required Node.js dependencies:

```sh
yarn install
```

---

## 4. Verify Database Connection

Run your application to verify the database connection:

```sh
yarn run dev or yarn start
```

If successful, you should see a message confirming the connection to the database.

---

## Common Issues & Fixes

### 1. **Connection Refused**
- **Cause:** PostgreSQL is not running.
- **Fix:** Start PostgreSQL:
```sh
pg_ctl -D /usr/local/var/postgres start
```
For Docker:
```sh
docker start postgres
```

### 2. **Port Conflict**
- **Cause:** Another service is using port `5433`.
- **Fix:** Stop the conflicting service or change the `DATABASE_PORT` in `.env`.
```sh
lsof -i :5433
kill -9 <PID>
```

---

## Conclusion

Your PostgreSQL database is now set up and ready to use. If you encounter issues, revisit the configuration steps or refer to the troubleshooting guide above.

---

## Happy Coding! 🚀

14 changes: 12 additions & 2 deletions discord/interactions/helpCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { REST } from "@discordjs/rest";
import { ChatInputCommandInteraction, Client } from "discord.js";

import { slashCommandsArray } from "../slashCommands";

export const handleHelpCommand = async (
interaction: ChatInputCommandInteraction,
client: Client,
Expand All @@ -9,10 +11,18 @@ export const handleHelpCommand = async (
try {
const userId = interaction.member?.user?.id;
const guildId = interaction.guildId;
console.log({ interaction });

if (!userId || !guildId) return;

const commands =
slashCommandsArray
.map((cmd) => `• \`/${cmd.name}\` - ${cmd.description}`)
.join("\n") || "No commands available.";

const responseMessage = `**Available Commands:**\n${commands}\n\nFor support, join our [Telegram Group](https://t.me/+Mi34Im1Uafc1Y2Q8).\nFor more information, visit [Starky](https://starky.wtf/).`;

await interaction.reply({
content: "For more information, visit [Starky](https://starky.wtf/).",
content: responseMessage,
ephemeral: true,
});
} catch (error) {
Expand Down
171 changes: 111 additions & 60 deletions discord/slashCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,124 @@ import { Routes, SlashCommandBuilder } from "discord.js";
import config from "../config";
import WatchTowerLogger from "../watchTower";

export const registerSlashCommands = async () => {
type SlashCommandOption = {
type: "role" | "user";
name: string;
description: string;
required: boolean;
};

type SlashCommandData = {
name: string;
description: string;
options?: SlashCommandOption[];
};

export const slashCommandsArray: SlashCommandData[] = [
{
name: "starky-connect",
description: "Connect your Starknet wallet to this Discord server",
},
{
name: "starky-disconnect",
description: "Disconnect your Starknet wallet from this Discord server",
},
{
name: "starky-add-config",
description: "Add a starky configuration to this server",
options: [
{
type: "role",
name: "role",
description:
"What role do you want to assign to people matching your criteria?",
required: true,
},
],
},
{
name: "starky-delete-config",
description: "Delete a Starky configuration from this server",
},
{
name: "starky-refresh",
description: "Refresh your Starky roles on this server",
},
{
name: "starky-view-config",
description: "View your Starky configurations on this server",
options: [
{
type: "role",
name: "role",
description: "The role of the configuration you want to check.",
required: true,
},
],
},
{
name: "starky-debug-user",
description: "Debug a user on this server",
options: [
{
type: "user",
name: "user",
description: "The user you want to debug.",
required: true,
},
],
},
{
name: "starky-set-config-custom-api",
description:
"Set a custom API URI for a configuration (Instead of Starkscan)",
},
{ name: "help", description: "Get help with Starky" },
{
name: "list-configs",
description: "View your Starky configurations on this server",
},
];

const buildSlashCommand = (
commandData: SlashCommandData
): SlashCommandBuilder => {
const command = new SlashCommandBuilder()
.setName(commandData.name)
.setDescription(commandData.description);
commandData.options?.forEach((option) => {
if (option.type === "role") {
command.addRoleOption((opt) =>
opt
.setName(option.name)
.setDescription(option.description)
.setRequired(option.required)
);
} else if (option.type === "user") {
command.addUserOption((opt) =>
opt
.setName(option.name)
.setDescription(option.description)
.setRequired(option.required)
);
}
});
return command;
};

export const registerSlashCommands = async (): Promise<void> => {
const restDiscordClient = new REST({ version: "10" }).setToken(
config.DISCORD_BOT_TOKEN
);

const slashCommands = [
new SlashCommandBuilder()
.setName("starky-connect")
.setDescription("Connect your Starknet wallet to this Discord server"),
new SlashCommandBuilder()
.setName("starky-disconnect")
.setDescription(
"Disconnect your Starknet wallet from this Discord server"
),
new SlashCommandBuilder()
.setName("starky-add-config")
.setDescription("Add a starky configuration to this server")
.addRoleOption((option) =>
option
.setName("role")
.setDescription(
"What role do you want to assign to people matching your criteria?"
)
.setRequired(true)
),
new SlashCommandBuilder()
.setName("starky-delete-config")
.setDescription("Delete a Starky configuration from this server"),
new SlashCommandBuilder()
.setName("starky-refresh")
.setDescription("Refresh your Starky roles on this server"),
new SlashCommandBuilder()
.setName("starky-view-config")
.setDescription("View your Starky configurations on this server")
.addRoleOption((option) =>
option
.setName("role")
.setDescription("The role of the configuration you want to check.")
.setRequired(true)
),
new SlashCommandBuilder()
.setName("list-configs")
.setDescription("View your Starky configurations on this server"),
new SlashCommandBuilder()
.setName("starky-debug-user")
.setDescription("Debug a user on this server")
.addUserOption((option) =>
option
.setName("user")
.setDescription("The user you want to debug.")
.setRequired(true)
),
new SlashCommandBuilder()
.setName("starky-set-config-custom-api")
.setDescription(
"Set a custom API URI for a configuration (Instead of Starkscan)"
),
new SlashCommandBuilder()
.setName("help")
.setDescription("Display a link to help"),
].map((command) => command.toJSON());
const slashCommands = slashCommandsArray
.map(buildSlashCommand)
.map((cmd) => cmd.toJSON());

WatchTowerLogger.info("> Registering Discord slash commands...");
await restDiscordClient.put(
Routes.applicationCommands(config.NEXT_PUBLIC_DISCORD_CLIENT_ID),
{
body: slashCommands,
}
{ body: slashCommands }
);
WatchTowerLogger.info("> Registered Discord slash commands!");
};
Loading

0 comments on commit 62ddb80

Please sign in to comment.