{"id":19764280,"url":"https://github.com/theobori/teeworlds-econ","last_synced_at":"2026-05-10T12:06:40.828Z","repository":{"id":240812487,"uuid":"802125089","full_name":"theobori/teeworlds-econ","owner":"theobori","description":"Teeworlds econ server library","archived":false,"fork":false,"pushed_at":"2024-06-12T23:03:33.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T23:47:20.161Z","etag":null,"topics":["econ","library","teeworlds"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theobori.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-17T15:10:58.000Z","updated_at":"2024-11-26T19:35:25.000Z","dependencies_parsed_at":"2024-06-19T14:58:56.336Z","dependency_job_id":"bb3d7f54-3110-46d8-ab4e-4527411debb0","html_url":"https://github.com/theobori/teeworlds-econ","commit_stats":null,"previous_names":["theobori/teeworlds-econ"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fteeworlds-econ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fteeworlds-econ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fteeworlds-econ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fteeworlds-econ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theobori","download_url":"https://codeload.github.com/theobori/teeworlds-econ/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241096177,"owners_count":19908931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["econ","library","teeworlds"],"created_at":"2024-11-12T04:13:01.625Z","updated_at":"2026-05-10T12:06:35.788Z","avatar_url":"https://github.com/theobori.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Teeworlds econ server library\n\n![golangci-lint](https://github.com/theobori/teeworlds-econ/actions/workflows/lint.yml/badge.svg)\n\nThis library is highly flexible and thread-safe by design, it allows you to interact with a Teeworlds econ server. It provides tools and help for abstracting econ server functionalities, such as in-game command error handling or event handling.\n\nIt is a kind of meta library.\n\n## 📖 Build and run\n\nYou only need the following requirements:\n\n- [Go](https://golang.org/doc/install) 1.22.3\n\n## 🤝 Contribute\n\nIf you want to help the project, you can follow the guidelines in [CONTRIBUTING.md](./CONTRIBUTING.md).\n\n## 🧪 Tests\n\nThere are some tests that require a running Teeworlds econ server, feel free to use the `econ_server.sh` script that create a DDNet server and a econ server.\n\nIt also requires the following environment variables.\n\n| Name | Description | Optional\n| - | - | - |\n`ECON_DEBUG` | Enables the debug verbose | Yes\n`ECON_PORT` | Specifies the econ port | Yes (7000 by default)\n`ECON_PASSWORD` | Specifies the econ password | No\n\nBy default, the test are using `localhost` as host.\n\nBelow, an example of running the test.\n\n```bash\n# Override some variables for the container and the Go tests\nexport ECON_PORT=1234\nexport ECON_PASSWORD=just_a_test_password\n\n# Run the script\n./econ_test.sh\n\n# Wait for the econ server being ready\nsleep 10\n\n# Run the Go tests\nmake test\n```\n\n## 📎 Some examples\n\nYou can also take a look at [`command_kick.go`](./command_kick.go) and [`command_ban.go`](./command_ban.go) command\n\n### Authenticate to the econ server\n\n```go\npackage main\n\nimport twecon \"github.com/theobori/teeworlds-econ\"\n\nfunc main() {\n    // Econ server configuration\n    config := twecon.EconConfig{\n        Host: \"127.0.0.1\",\n        Port: 7000,\n        Password: \"hello_world\",\n    }\n\n    // Create the econ controller\n    econ := twecon.NewEcon(\u0026config)\n\n    // Connect to the econ server\n    if err := econ.Connect(); err != nil {\n        return\n    }\n\n    // Authenticate to the econ server\n    if _, err := econ.Authenticate(); err != nil {\n        return\n    }\n}\n```\n\n### Send a payload\n\n```go\npackage main\n\nfunc main {\n    ...\n    // Once you are authenticated\n\n    // Send a payload to the econ server,\n\t// in this case it is sending the broadcast command and its argument\n\terr := econ.Send(\"broadcast server shutdown in 5 minutes\")\n\tif err != nil {\n\t\treturn\n\t}\n}\n```\n\n### Create your own command\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\ttwecon \"github.com/theobori/teeworlds-econ\"\n)\n\nfunc main() {\n    ...\n    // Once you are authenticated\n\n    // Create a your own command\n    // This command wraps the in-game `say` command\n    // So, as in-game, it takes one string argument\n\tsayCommand := twecon.EconCommand{\n\t\tName: \"say\",\n\t\tArgumentsAmount: 1,\n\t\tFunc: func(econ *twecon.Econ, arguments ...any) (*twecon.EconResponse, error) {\n\t\t\tmessage, ok := arguments[0].(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid message type\")\n\t\t\t}\n\n\t\t\tpayload := \"say From the server: \" + message\n\n\t\t\tif err := econ.Send(payload); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn \u0026twecon.EconResponse{State: true}, nil\n\t\t},\n\t}\n\n\t// Register your command\n\terr = econ.CommandManager.Register(\u0026sayCommand)\n\tif err != nil {\n\t\treturn\n\t}\n\n\t// Execute your registered command\n\t_, err = econ.CommandManager.Exec(\n\t\tecon,\n\t\t\"say\",\n\t\t\"server shutdown in 1 minute\",\n\t)\n\tif err != nil {\n\t\treturn\n\t}\n}\n```\n\n### Event handler for player messages\n\n```go\npackage main\n\nimport twecon \"github.com/theobori/teeworlds-econ\"\n\nfunc main() {\n    ...\n    // Once you are authenticated\n\n    // Create an event handlers\n\tplayerMessage := twecon.EconEvent{\n\t\tName: \"player_message\",\n\t\tRegex: \"chat: .*:.*: .*\",\n\t\tFunc: func(econ *twecon.Econ, eventPayload string) any {\n\t\t\tfmt.Println(eventPayload)\n\n\t\t\treturn nil\n\t\t},\n\t}\n\n\t// Register the simple event\n\terr = econ.EventManager.Register(\u0026playerMessage)\n\tif err != nil {\n\t\treturn\n\t}\n}\n```\n\n### A more complex event handler\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"regexp\"\n\t\"strings\"\n\n\ttwecon \"github.com/theobori/teeworlds-econ\"\n)\n\nfunc main() {\n    ...\n    // Once you are authenticated\n\n    // Custom in-game chatbot\n\tchatbot := twecon.EconEvent{\n\t\tName: \"player_chat_bot\",\n\t\tRegex: \"chat: .*:.*: .*\",\n\t\tFunc: func(econ *twecon.Econ, eventPayload string) any {\n\t\t\tre := regexp.MustCompile(`chat: .*:(.*): (.*)`)\n\t\t\tmatches := re.FindStringSubmatch(eventPayload)\n\n\t\t\tmsg := matches[2]\n\n\t\t\tif strings.HasPrefix(msg, \"!random\") {\n\t\t\t\t_, err := econ.CommandManager.Exec(\n\t\t\t\t\tecon,\n\t\t\t\t\t\"say\",\n\t\t\t\t\tfmt.Sprintf(\"%d\", rand.Intn(100)),\n\t\t\t\t)\n\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t}\n\n\t// Register the chatbot event\n\terr = econ.EventManager.Register(\u0026chatbot)\n\tif err != nil {\n\t\treturn\n\t}\n\n    // Start handling the events\n\t// `HandleEvents` is a control loop, by default it is not a goroutine\n\tgo econ.HandleEvents()\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheobori%2Fteeworlds-econ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheobori%2Fteeworlds-econ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheobori%2Fteeworlds-econ/lists"}