This commit is contained in:
phlux 2024-11-10 21:22:50 -05:00
parent cd33fd2584
commit 56d4158d8e
3 changed files with 48 additions and 82 deletions

120
README.md
View File

@ -1,105 +1,71 @@
# Discord College Football Bot
A Discord bot written in Go that provides up-to-date college football scores and schedules. It responds to commands to show recent or upcoming games for specific teams using the [College Football Data API](https://collegefootballdata.com/). # Discord Scores Bot
**Discord Scores Bot** is a powerful, user-friendly bot designed to bring real-time college sports scores and updates directly to your Discord server. Whether you follow college football or basketball, this bot keeps you up-to-date with live game information, final scores, and upcoming match schedules.
## Features ## Features
- Retrieves college football scores by team, including live scores (for Patreon members) - **Live Score Updates**: Get real-time scores for ongoing games.
- Provides upcoming game schedules if a game hasnt started - **Upcoming Matches**: Check when your favorite teams are playing next.
- Designed to run on a Discord server, responds to commands in real-time - **Final Scores**: View results from completed games.
- **Team Search**: Search for scores using team names.
- **Date & Week Specification**: Specify dates (e.g., `MM/DD`) for basketball and weeks for football to view related games.
## Commands ## Supported Commands
- **!s `<team_name>`** — Retrieves the score for the most recent game or the upcoming game schedule if the game hasnt started. - `!cfb [team] [week]`: Retrieves college football game details for the specified team and week (current week if not specified).
- `!cbb [team] [MM/DD]`: Retrieves college basketball game details for the specified team and date (today's date if not specified).
Example:
```
!s Alabama
```
## Setup ## Installation
### Prerequisites 1. Clone this repository:
- **Go** (1.19 or later)
- **College Football Data API key**: Sign up at [College Football Data](https://collegefootballdata.com/) and obtain an API key.
- **Discord Bot Token**: Set up a bot on the [Discord Developer Portal](https://discord.com/developers/applications) to obtain a token.
### Installation
1. **Clone the repository**:
```bash ```bash
git clone https://github.com/yourusername/discord-cfb-bot.git git clone https://your-repo-url/discord-scores-bot.git
cd discord-cfb-bot cd discord-scores-bot
``` ```
2. **Configure API keys**: 2. Install dependencies:
- In `config/config.go`, set the `CFBDAPIKey` with your College Football Data API key and your Discord bot token. ```bash
go mod tidy
3. **Run the bot**:
- To test locally:
```bash
go run main.go
```
- To run in the background:
- Use `nohup`, `screen`, `tmux`, or create a `systemd` service (see below for options).
### Running the Bot in the Background
You can keep the bot running in the background by using tools like `nohup`, `screen`, or `tmux`. For production servers, consider creating a `systemd` service.
Example with `nohup`:
```bash
nohup go run main.go > bot.log 2>&1 &
```
### Deployment with `systemd` (Linux)
1. Create a `systemd` service file at `/etc/systemd/system/discord-cfb-bot.service`:
```ini
[Unit]
Description=Discord College Football Bot
After=network.target
[Service]
ExecStart=/usr/local/go/bin/go run /path/to/main.go
WorkingDirectory=/path/to/discord-cfb-bot
StandardOutput=append:/path/to/bot.log
StandardError=append:/path/to/bot.log
Restart=always
User=yourusername
[Install]
WantedBy=multi-user.target
``` ```
2. **Enable and start the service**: 3. Create a `.env` file and add your Discord bot token:
```env
BOT_TOKEN=your-discord-bot-token
```
4. Run the bot:
```bash ```bash
sudo systemctl enable discord-cfb-bot go run cmd/main.go
sudo systemctl start discord-cfb-bot
``` ```
## Usage ## Usage
Invite the bot to your server and type commands in any text channel where the bot has permissions. For example: - Invite the bot to your Discord server and type `!cfb [team] [week]` or `!cbb [team] [MM/DD]` to get game information.
``` - If a date or week is not specified, the bot defaults to today's date or the current week.
!s Texas A&M
```
The bot will reply with the score or the upcoming game schedule for the team. ## Examples
## Project Structure - `!cfb Alabama`: Get details of Alabama's football games for the current week.
- `!cbb Duke 11/10`: Get details of Duke's basketball game on November 10th.
- `main.go`: Entry point of the bot ## Configuration
- `config/config.go`: Configuration file for the API keys and other settings
- `clients/cfbd_client.go`: Client for interacting with the College Football Data API
- `bot/bot.go`: Discord bot setup and command handling
## Contributions The bot is configured to use pre-defined API endpoints for fetching scores:
- College football: `https://ncaa.ewnix.net/football/fbs`
- College basketball: `https://ncaa.ewnix.net/scoreboard/basketball-men/d1`
Contributions are welcome! Feel free to submit a pull request to improve the bot or add new features. Ensure that your bot has the necessary permissions to read and send messages in the channels where it's active.
## Contribution
Contributions are welcome! Feel free to open an issue or submit a pull request to improve the bot or add new features.
## License ## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
Stay connected with your favorite college sports and enhance your Discord experience with **Discord Scores Bot**!

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"discord-cfb-bot/internal/bot" "discord-scores-bot/internal/bot"
"discord-cfb-bot/config" "discord-scores-bot/config"
"fmt" "fmt"
) )

View File

@ -1,9 +1,9 @@
package bot package bot
import ( import (
"discord-cfb-bot/config" "discord-scores-bot/config"
cfbClient "discord-cfb-bot/internal/clients/cfb" cfbClient "discord-scores-bot/internal/clients/cfb"
cbbClient "discord-cfb-bot/internal/clients/cbb" cbbClient "discord-scores-bot/internal/clients/cbb"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"fmt" "fmt"
"strings" "strings"