Skip to content

Commit

Permalink
feat: Plugin football (#2461)
Browse files Browse the repository at this point in the history
* feat: inital football plugin setup from using bootstrap plugin

* feat: get match action

* feat: fetch standings  action

* fix: type script error

* feat: enhance fetchMatchAction and fetchStandingsAction with reliability and validation updates

- Added 5-second timeout using AbortController for fetchMatchAction.
- Implemented response validation to ensure data structure matches expected types.
- Improved error handling with detailed logs for better debugging.
- Removed .ts extensions from imports in index.ts to prevent production build issues.
- Cleaned up tsup.config.ts by removing unused externals (@reflink/reflink and @node-llama-cpp).
- Guarded against invalid API responses to enhance type safety.

* Update pnpm-lock.yaml

* feat: football.character

* feat: display standing result with callback

* Update pnpm-lock.yaml

* Update .env.example

---------

Co-authored-by: Sayo <[email protected]>
  • Loading branch information
suleigolden and wtfsayo authored Jan 23, 2025
1 parent b776877 commit 0afde97
Show file tree
Hide file tree
Showing 17 changed files with 1,101 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,7 @@ HYPERBOLIC_ENV=production
HYPERBOLIC_API_KEY=
HYPERBOLIC_GRANULAR_LOG=true
HYPERBOLIC_SPASH=true
HYPERBOLIC_LOG_LEVEL=debug
HYPERBOLIC_LOG_LEVEL=debug

# Football Plugin Configuration
FOOTBALL_API_KEY= # API key from Football-Data.org (https://www.football-data.org/)
4 changes: 3 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"@elizaos/plugin-suno": "workspace:*",
"@elizaos/plugin-udio": "workspace:*",
"@elizaos/plugin-hyperbolic": "workspace:*",
"readline": "1.3.0",
"@elizaos/plugin-football": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
},
Expand All @@ -135,3 +136,4 @@
"tsup": "8.3.5"
}
}

6 changes: 4 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
validateCharacterConfig,
} from "@elizaos/core";
import { zgPlugin } from "@elizaos/plugin-0g";
import { footballPlugin } from "@elizaos/plugin-football";

import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import { normalizeCharacter } from "@elizaos/plugin-di";
Expand Down Expand Up @@ -947,6 +948,7 @@ export async function createAgent(
getSecret(character, "DEXSCREENER_API_KEY")
? dexScreenerPlugin
: null,
getSecret(character, "FOOTBALL_API_KEY") ? footballPlugin : null,
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
? confluxPlugin
: null,
Expand Down Expand Up @@ -1397,12 +1399,12 @@ if (
parseBooleanFromText(process.env.PREVENT_UNHANDLED_EXIT)
) {
// Handle uncaught exceptions to prevent the process from crashing
process.on("uncaughtException", (err) => {
process.on('uncaughtException', function(err) {
console.error("uncaughtException", err);
});

// Handle unhandled rejections to prevent the process from crashing
process.on("unhandledRejection", (err) => {
process.on('unhandledRejection', function(err) {
console.error("unhandledRejection", err);
});
}
2 changes: 1 addition & 1 deletion packages/core/src/defaultCharacter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Character, ModelProviderName } from "./types.ts";
import { Character, ModelProviderName } from "./types.ts";

export const defaultCharacter: Character = {
name: "Eliza",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-football/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
216 changes: 216 additions & 0 deletions packages/plugin-football/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# @elizaos/plugin-football

A plugin providing live football match data and league standings integration for ElizaOS agents.

## Description

The Football plugin integrates with the [Football-Data.org API](https://www.football-data.org/) to enable ElizaOS agents to fetch live football match information and league standings. It includes actions and utilities to provide real-time football data in conversations.

## Installation

To install the plugin, use the following command:

```bash
pnpm install @elizaos/plugin-football
```

## Features

### 1. Live Match Data

- **Action**: `fetchMatchAction`
- Retrieves live football match data, including:
- Teams
- Scores
- Game events
- Provides real-time updates for ongoing matches.

### 2. League Standings

- **Action**: `fetchStandingsAction`
- Fetches league standings for a specified competition, including:
- Team rankings
- Points
- Goals scored
- Other league statistics.

### 3. Flexible Integration

- Extendable for additional football data, such as:
- Player statistics
- Match schedules
- Historical match data.

## API Key Configuration

To use this plugin, you need an API key from [Football-Data.org](https://www.football-data.org/).

1. Register and obtain your API key from Football-Data.org.
2. Add the API key to your `.env` file:

```env
FOOTBALL_API_KEY=your_api_key_here
```
The plugin will use this key to authenticate requests.
## Usage Examples
### `fetchMatchAction`
**Description**: Retrieves live match data.
**Code Example**:
```javascript
import { fetchMatchAction } from "@elizaos/plugin-football";
const result = await fetchMatchAction.handler(runtime, message, state);
console.log(result);
```

**Sample Output**:

```json
{
"matches": [
{
"homeTeam": { "name": "Chelsea" },
"awayTeam": { "name": "Arsenal" },
"score": {
"fullTime": { "homeTeam": 1, "awayTeam": 2 }
}
}
]
}
```

### `fetchStandingsAction`

**Description**: Fetches league standings for a specific competition.

**Code Example**:

```javascript
import { fetchStandingsAction } from "@elizaos/plugin-football";

const result = await fetchStandingsAction.handler(runtime, message, state);
console.log(result);
```

**Sample Output**:

```json
{
"standings": [
{
"table": [
{
"position": 1,
"team": { "name": "Manchester City" },
"points": 45
},
{ "position": 2, "team": { "name": "Arsenal" }, "points": 42 }
]
}
]
}
```

## Development

### Steps to Build and Test

1. Clone the repository:

```bash
git clone https://github.com/elizaOS/eliza.git
```

2. Navigate to the `plugin-football` directory and install dependencies:

```bash
cd packages/plugin-football
pnpm install
```

3. Build the plugin:

```bash
pnpm run build
```

4. Run linting:

```bash
pnpm run lint
```

5. Test the plugin:

```bash
pnpm vitest src/tests/match-action.test.ts
pnpm vitest src/tests/fetch-standings-action.test.ts
```

## Dependencies

This plugin relies on the following dependency:

- `@elizaos/core: workspace:*`

## Future Enhancements

### Expanded Football Data Features

- Player statistics
- Match schedules and fixtures
- Team information and histories
- Historical match data

### Advanced League Tracking

- Real-time updates for all supported leagues
- Integration with more competitions (e.g., Champions League, World Cup)

### Customizable Output

- Improved data formatting for conversational outputs
- Support for additional localization options

### Integration Improvements

- Enhanced API error handling
- Caching for frequently accessed data
- Increased rate-limit compliance for the Football-Data.org API

### Developer Tools

- Sample applications for plugin usage
- Test suites for advanced football scenarios
- Examples for extending plugin functionality

## Contributing

Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.

## Credits

This plugin integrates with and builds upon several key technologies:

- [Football-Data.org](https://www.football-data.org/documentation/quickstart/) Official Football-Data platform API

Special thanks to:

- Special thanks to [Football-Data.org](https://www.football-data.org/) for providing the API that powers this plugin.
- The Eliza Core development team.
- The Eliza community for their contributions and feedback

For more information about Football-Data integration capabilities:

- [Football-Data API Documentation](https://www.football-data.org/documentation/quickstart)
- [Football-Data Developer Portal](https://www.football-data.org/documentation/api)

## License

This plugin is part of the Eliza project. See the main project repository for license information.
3 changes: 3 additions & 0 deletions packages/plugin-football/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
33 changes: 33 additions & 0 deletions packages/plugin-football/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@elizaos/plugin-football",
"version": "0.1.8+build.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"@elizaos/source": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"dependencies": {
"@elizaos/core": "workspace:*",
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
Loading

0 comments on commit 0afde97

Please sign in to comment.