Code Monkey home page Code Monkey logo

common-bot-library's Introduction

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

common-bot-library's People

Contributors

bcanseco avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

sepppenner

common-bot-library's Issues

Perf improvements

For services that use third party SDKs, store the wrapped service instance as a private member rather than the API key. This avoids having to reinitialize the instance each time a request is made.

Standardize exceptions and params

If something can't be null, throw an ArgumentNullException.

Also, go through each service and see which actually return an HTTP code on failure (essentially resulting in a thrown HttpRequestException) and which do not. Maybe the custom exceptions can be removed in favor of something built in?

Add Cloud APIs

The do-able ones:

Google

  • Vision
    • FREE
    • includes color detection

Yandex

  • Translation
    • has language detection
    • inferior competition
      • Microsoft's requires a new token every 10m
      • Bluemix's doesn't have language detection
      • Google's isn't free

Bluemix

  • Personality insights
    • FREE
    • requires body of text

Add ImgurService

https://api.imgur.com/3/gallery/search?q=query
Also take note of their compound query capabilities (including file extension choice!)

Improve OWM Service

Pulling from the XML API will net more useful fields (like a city/country code?).
Look into the newest JSON.NET release which might do the XML parsing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.