https://github.com/davidfowl/jabbot
Bot API for JabbR
https://github.com/davidfowl/jabbot
Last synced: 4 months ago
JSON representation
Bot API for JabbR
- Host: GitHub
- URL: https://github.com/davidfowl/jabbot
- Owner: davidfowl
- Created: 2011-12-03T08:01:20.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T19:14:19.000Z (about 2 years ago)
- Last Synced: 2025-03-14T20:58:17.887Z (4 months ago)
- Language: C#
- Homepage:
- Size: 607 KB
- Stars: 66
- Watchers: 6
- Forks: 22
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jabbot
Jabbot is a bot API for [JabbR](https://github.com/davidfowl/JabbR).
Why not write an apater for [Hubot](https://github.com/github/hubot)?
I like writing C# :).
It's as easy as:
```csharp
var bot = new Bot("http://myjabbot", "username", "password");
bot.PowerUp();
bot.Join("someroom");
bot.Say("Hello", "someroom");
bot.Say("Ok I'm off");
bot.ShutDown();
```## Writing Sprokets
Sprokets are things you can plug-in to enhance the behavior of your bot. Simply drop a dll with classes that implement
ISproket into a Sprokets folder and you're done. Here's an port of the [math.coffee](https://github.com/github/hubot/blob/master/src/scripts/math.coffee) from hubot:```csharp
public class MathSproket : RegexSproket
{
public override Regex Pattern
{
get { return new Regex("(calc|calculate|convert|math)( me)? (.*)"); }
}protected override void ProcessMatch(Match match, ChatMessage message, Bot bot)
{
var client = new HttpClient();
client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-us"));
client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));client.GetAsync("http://www.google.com/ig/calculator?hl=en&q=" + Uri.EscapeDataString(match.Groups[3].Value))
.ContinueWith(task =>
{
if (task.Result.IsSuccessStatusCode)
{
task.Result.Content.ReadAsStringAsync().ContinueWith(readTask =>
{
dynamic json = JsonConvert.DeserializeObject(readTask.Result);string solution = json.rhs;
bot.Reply(message.FromUser, solution ?? "Could not compute.", message.Room);
});
}
});
}
}
```