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.
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.
You have two choices for services that require API keys or other tokens.
- Construct the service by passing in the necessary keys as arguments.
- 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.
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.
- Github Service [API docs]
- Posts issues to a https://github.com repository.
- Requires an access token.
- Google Search Service [API docs]
- Searches https://google.com for webpages
- Requires a Cloud Platform API key and a Custom Search Engine ID.
- To search all of Google, set your engine to "search the entire web" but don't add any emphasized sites.
- Google Vision Service [API docs]
- Uses Google Cloud Vision to analyze images.
- A demo is available here.
- Requires a Cloud Platform API key.
- Imgur Service [API docs]
- Searches https://imgur.com for images.
- Requires a client ID.
- MyAnimeList Service [API docs]
- Searches https://myanimelist.net for anime.
- Requires a MAL account username and password.
- NCalc Service [API docs]
- Evaluates mathematical expressions.
- Omdb Service [API docs]
- Searches https://omdbapi.com for media.
- Requires an API key.
- OpenTriviaDb Service [API docs]
- Searches https://opentdb.com for trivia.
- OpenWeatherMap Service [API docs]
- Searches https://openweathermap.org for weather data.
- Requires an API key.
- Pandorabot Service [API docs]
- Converses with a Cleverbot-like chatbot.
- Requires a bot ID.
- Random Service [API docs]
- Flips coins and rolls dice.
- Good for when you have users input their desired die side numbers (e.g.
d20
). Everything is validated.
- Reddit Service [API docs]
- Gets posts from https://reddit.com.
- Steam Service [API docs]
- Searches https://store.steampowered.com for games.
- Twitter Service [API docs]
- Searches https://twitter.com for tweets.
- Requires four keys that can be registered here.
- UrbanDictionary Service [API docs]
- Searches https://www.urbandictionary.com for definitions.
- Watson Personality Service [API docs]
- Uses IBM Watson to create a personality profile based on a user's text.
- A demo is available here.
- Requires a Personality Insights Service username and password.
- Yahoo Finance Service [API docs]
- Searches https://finance.yahoo.com/ for stock information.
- Yandex Translate Service [API docs]
- Translates text using https://translate.yandex.com/.
- Requires an API key.
- YouTube Service [API docs]
- Searches https://youtube.com for videos.
- Requires a Google Cloud Platform API key.
More services are constantly added. If you prefer to keep things tidy, there are interfaces available.
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.