Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use slash commands #1

Merged
merged 13 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GUILD_ID=GUILD_ID
BOT_TOKEN="BOT_TOKEN"
phoenixpereira marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format Code

on:
pull_request:
branches:
- '*'
push:
branches: [main]

jobs:
black:
name: Black
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
phoenixpereira marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install

- name: Format code with Black
run: poetry run black .

- name: Check for changes
run: git diff --exit-code
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
# DuckBot

## Running
DuckBot is a Discord bot written in Python using the discord.py library for the CS Club's Discord Server. It provides various commands and functionalities to enhance your Discord server experience.
phoenixpereira marked this conversation as resolved.
Show resolved Hide resolved

Add the Discord bot token in the `.env` file.
## Getting Started

To get started, please follow these steps:

1. Install Poetry if not already installed:

```bash
curl -sSL https://install.python-poetry.org | python3 -
phoenixpereira marked this conversation as resolved.
Show resolved Hide resolved
```
BOT_TOKEN="YOUR_TOKEN_HERE"

2. Install the dependencies.

```bash
poetry install
```

Make sure you have the dependencies installed as well. They are listed in `requirements.txt`. Copy `example.config.json` and rename to `config.json`. Edit the values in the config file accordingly.
3. Copy `.env.example` to a new file `.env` and set required environment variables.

4. Navigate to the src directory

```bash
cd src
```

5. Run the bot.

```bash
poetry run python main.py
```

## Contributing

We welcome contributions to enhance Duckbot! If you find any issues, have suggestions, or want to request a feature, please follow our [Contributing Guidelines](https://github.com/compsci-adl/.github/blob/main/CONTRIBUTING.md).

## License

The entry point of the bot is `main.py`.
This project is licensed under the MIT License.
See [LICENSE](LICENSE) for details.
601 changes: 601 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "duckbot"
version = "0.1.0"
description = "DuckBot is the CS Club's Discord Bot, created by the CS Club Open Source Team."
authors = ["CS Club Open Source Team <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
"discord.py" = "2.3.2"
python-dotenv = "1.0.0"
black = "^24.4.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

91 changes: 0 additions & 91 deletions src/duckbot.py

This file was deleted.

5 changes: 0 additions & 5 deletions src/example.config.json

This file was deleted.

65 changes: 59 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
"""
Entrypoint for the bot
"""
import discord
import os
from dotenv import load_dotenv

import duckbot
# Load environment variables from .env file
load_dotenv()

if __name__ == "__main__":
duckbot.run()
# Retrieve guild ID and bot token from environment variables
GUILD_ID = os.getenv("GUILD_ID")
BOT_TOKEN = os.getenv("BOT_TOKEN")

# Load the permissions the bot has been granted in the previous configuration
intents = discord.Intents.default()
intents.message_content = True


class DuckBot(discord.Client):
def __init__(self):
super().__init__(intents=intents)
self.synced = False # Make sure that the command tree will be synced only once
self.added = False

async def on_ready(self):
await self.wait_until_ready()
if not self.synced: # Check if slash commands have been synced
await tree.sync(guild=discord.Object(GUILD_ID))
self.synced = True
if not self.added:
self.added = True
print(f"Say hi to {self.user}!")


client = DuckBot()
tree = discord.app_commands.CommandTree(client)


@tree.command(description="Pong!", guild=discord.Object(GUILD_ID))
async def ping(interaction: discord.Interaction):
await interaction.response.send_message("Pong!")


@tree.command(
description="View useful information about using the bot.",
guild=discord.Object(GUILD_ID),
)
async def help(interaction: discord.Interaction):
commands = list(tree.get_commands(guild=discord.Object(GUILD_ID)))
embed = discord.Embed(
title="DuckBot",
description="DuckBot is the CS Club's Discord bot, created by the CS Club Open Source Team.",
color=discord.Color.yellow(),
)
for command in commands:
embed.add_field(
name=f"/{command.name}", value=command.description, inline=False
)
await interaction.response.send_message(embed=embed)


# Add the token of bot
client.run(BOT_TOKEN)
14 changes: 0 additions & 14 deletions src/modules/chat.py

This file was deleted.

14 changes: 0 additions & 14 deletions src/modules/info.py

This file was deleted.

27 changes: 0 additions & 27 deletions src/modules/test.py

This file was deleted.

25 changes: 0 additions & 25 deletions src/modules/utils.py

This file was deleted.

14 changes: 0 additions & 14 deletions src/util.py

This file was deleted.

Loading