This repository has been archived by the owner. It is now read-only.
🌐 An asynchronous .NET library of API wrappers designed to help with typical bot commands.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src/CommonBotLibrary
tests
.gitattributes
.gitignore
CBL.sln
LICENSE
README.md
build.cake
build.ps1
build.sh
tokens.json

README.md

Common Bot Library NuGet Build status

Tired of rewriting the same code for all your bots? The Common Bot Library (CBL) is for you.

CBL is an asynchronous .NET library of API wrappers designed to help with typical bot commands. Things like weather, definitions, movie information, etc. are all readily available for your projects.

ICalculatorService calc = new NCalcService();
var result = await calc.EvaluateAsync("1 + (3 / (23 - 5) * 6)");
Console.WriteLine(result); // 2

You can check out the full list of services here.

Quick start

If you're using Visual Studio, you can install this library by following these instructions.
The package name on NuGet is CommonBotLibrary. Note: this library targets .NET Standard 1.6.

Authentication

You have two choices for services that require API keys or other tokens.

  1. Construct the service by passing in the necessary keys as arguments.
  2. Load in tokens from a file once, then forget about 'em.
/* Method 1 */
var service = new GoogleService("platformKey", "engineId");
var results = await service.SearchAsync("dogs");

/* Method 2 */
await Tokens.LoadAsync("mytokens.json");
var service = new GoogleService(); // notice we don't pass any keys in!
var results = await service.SearchAsync("dogs");

In the second example, we keep a JSON file with our API keys and import them before creating our services. This process only needs to be done once unless your tokens file changes.

Extensibility

What if your project has extra services that need API keys? For example, take this token file:

{
  "OpenWeatherMap": "Im_a_key_that_CBL_recognizes",
  "MyCustomDatabaseString": "Im_a_custom_key"
}

You can take advantage of the CBL token system by subclassing the Tokens class.

public class MyCustomTokens : Tokens
{
    [JsonProperty]
    public string MyCustomDatabaseString { get; set; } // don't forget the setter!
}

Then, instead of calling LoadAsync("mytokens.json") normally, you would use your custom token class as a typeparam:

await Tokens.LoadAsync<MyCustomTokens>("mytokens.json");
var databaseConnection = MyCustomTokens.MyCustomDatabaseString;

Now you can use all the CBL services plus your own custom services without having to worry about API keys.

Services

More services are constantly added. If you prefer to keep things tidy, there are interfaces available.

Contributing

This project is actively maintained! Please feel free to open an issue or submit a pull request if you have a suggestion, an idea, run into a bug, or have any other questions. Everything is responded to within 24 hours.

License

MIT