Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added name on sprockets and announcers #78

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Extensions/CalculatorSprocket/CalculatorSprocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ public override bool ExecuteCommand()
default:
return false;
}
}

private bool CalculateExpression(string mathExpression)
}

public override string SprocketName
{
get { return "Calculator Sprocket"; }
}

private bool CalculateExpression(string mathExpression)
{
var expression = new Expression(mathExpression, EvaluateOptions.IgnoreCase);
object result = null;
Expand Down
8 changes: 6 additions & 2 deletions Extensions/DisqusAnnouncer/DisqusAnnouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
namespace DisqusAnnouncer
{
public class DisqusAnnouncer : IAnnounce
{
public TimeSpan Interval
{
public string AnnouncerName
{
get { return "Disqus Announcer"; }
}
public TimeSpan Interval
{
get { return TimeSpan.FromMinutes(5); }
}
Expand Down
10 changes: 7 additions & 3 deletions Extensions/GithubAnnouncements/GithubAnnouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public class GithubAnnouncer : IAnnounce
public IEnumerable<IGitHubTask> Tasks { get; set; }

[Import]
public ILogger Log { get; set; }

public TimeSpan Interval
public ILogger Log { get; set; }

public string AnnouncerName
{
get { return "GitHub Announcer"; }
}
public TimeSpan Interval
{
get { return TimeSpan.FromMinutes(10); }
}
Expand Down
14 changes: 8 additions & 6 deletions Extensions/HelpSprocket/Help.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using Jabbot;
using Jabbot.Models;
using Jabbot.Sprockets.Core;
Expand All @@ -12,7 +9,7 @@ public class Help : ISprocket
{
public bool Handle(ChatMessage message, IBot bot)
{
var acceptedCommands = new string[] { bot.Name + " help", "@" + bot.Name + " help" };
var acceptedCommands = new[] { bot.Name + " help", "@" + bot.Name + " help" };

if (acceptedCommands.Contains(message.Content.Trim()))
{
Expand All @@ -23,5 +20,10 @@ public bool Handle(ChatMessage message, IBot bot)

return false;
}

public string SprocketName
{
get { return "Help sprocket"; }
}
}
}
}
7 changes: 6 additions & 1 deletion Extensions/IPityTheFoolSprocket/PityTheFoolSprocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public override Regex Pattern
protected override void ProcessMatch(Match match, ChatMessage message, IBot bot)
{
bot.Say("http://xamldev.dk/IPityTheFool.gif", message.Receiver);
}
}

public override string SprocketName
{
get { return "I Pity the Fool Sprocket"; }
}
}
}
11 changes: 8 additions & 3 deletions Extensions/QuizSprocket/QuizSprocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,14 @@ public override bool ExecuteCommand()
default:
return false;
}
}

private bool ShowTop10()
}

public override string SprocketName
{
get { return "Quiz Sprocket"; }
}

private bool ShowTop10()
{
var stringBuilder = new StringBuilder();

Expand Down
6 changes: 5 additions & 1 deletion Extensions/SampleAnnouncement/EchoAnnouncement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
namespace SampleAnnouncement
{
public class EchoAnnouncement : IAnnounce
{
{
public string AnnouncerName
{
get { return "Aussie Time Announcer"; }
}
public TimeSpan Interval
{
get { return TimeSpan.FromMinutes(10); }
Expand Down
5 changes: 5 additions & 0 deletions Extensions/SampleSprocket/HelloSprocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ public override bool ExecuteCommand()

return true;
}

public override string SprocketName
{
get { return "Hello Sprocket"; }
}
}
}
4 changes: 4 additions & 0 deletions Extensions/TwitterAnnouncer/TwitterAnnouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class TwitterAnnouncer : IAnnounce
private DateTime lastRun = DateTime.Now;
private TwitterStatus latestTweet;

public string AnnouncerName
{
get { return "Twitter Announcer"; }
}
public TimeSpan Interval
{
get { return TimeSpan.FromMinutes(10); }
Expand Down
8 changes: 6 additions & 2 deletions Extensions/UserVoiceAnnouncer/UserVoiceAnnouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
namespace UserVoiceAnnouncer
{
public class UserVoiceAnnouncer : IAnnounce
{
public TimeSpan Interval
{
public string AnnouncerName
{
get { return "UserVoice Announcer"; }
}
public TimeSpan Interval
{
get { return TimeSpan.FromMinutes(5); }
}
Expand Down
7 changes: 6 additions & 1 deletion Extensions/VolunteerSprocket/VolunteerSprocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ protected override void ProcessMatch(Match match, ChatMessage message, IBot bot)

bot.Say(string.Format("I volunteer {0} for that!", users[randomUser].Name), message.Receiver);
}
}
}

public override string SprocketName
{
get { return "Volunteer Sprocket"; }
}
}
}
105 changes: 55 additions & 50 deletions Extensions/WeatherSprocket/WeatherSprocket.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,56 @@
using System;
using System.Text.RegularExpressions;
using Jabbot;
using Jabbot.Models;
using Jabbot.Sprockets;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;

namespace WeatherSprocket
{
public class WeatherSprocket : RegexSprocket
{

public override Regex Pattern
{
get { return new Regex(@"(?<=\bweather[ ])\d{4,5}", RegexOptions.IgnoreCase); }
}

protected override void ProcessMatch(Match match, ChatMessage message, IBot bot)
{
if (match.Length > 0)
{
var matchResult = match.Captures[0].ToString();
bot.Say(getWeather(matchResult), message.Receiver); ;
}
}

private string getWeather(string zipcode)
{
string requestUri = String.Format("http://api.wunderground.com/api/ffb2f3f9960dd675/geolookup/conditions/forecast/q/{0}.json",zipcode);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
Stream dataStream;
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
JObject obj = JObject.Parse(responseFromServer);
JToken currentObservation = obj["current_observation"];
JToken displayLocation = obj["current_observation"]["display_location"];
reader.Close();
dataStream.Close();
response.Close();
var cityState = (string)displayLocation["full"];
var weather = (string)currentObservation["weather"];
var temperature = (string)currentObservation["temperature_string"];
var output = string.Format("Weather in {0} is {1} and {2}",cityState,temperature,weather);
return output;
}
}
using System;
using System.Text.RegularExpressions;
using Jabbot;
using Jabbot.Models;
using Jabbot.Sprockets;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;

namespace WeatherSprocket
{
public class WeatherSprocket : RegexSprocket
{

public override Regex Pattern
{
get { return new Regex(@"(?<=\bweather[ ])\d{4,5}", RegexOptions.IgnoreCase); }
}

protected override void ProcessMatch(Match match, ChatMessage message, IBot bot)
{
if (match.Length > 0)
{
var matchResult = match.Captures[0].ToString();
bot.Say(getWeather(matchResult), message.Receiver); ;
}
}

public override string SprocketName
{
get { return "Weather Sprocket"; }
}

private string getWeather(string zipcode)
{
string requestUri = String.Format("http://api.wunderground.com/api/ffb2f3f9960dd675/geolookup/conditions/forecast/q/{0}.json", zipcode);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
Stream dataStream;
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
JObject obj = JObject.Parse(responseFromServer);
JToken currentObservation = obj["current_observation"];
JToken displayLocation = obj["current_observation"]["display_location"];
reader.Close();
dataStream.Close();
response.Close();
var cityState = (string)displayLocation["full"];
var weather = (string)currentObservation["weather"];
var temperature = (string)currentObservation["temperature_string"];
var output = string.Format("Weather in {0} is {1} and {2}", cityState, temperature, weather);
return output;
}
}
}
106 changes: 56 additions & 50 deletions Jabbot.CommandSprockets/CommandSprocket.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Jabbot.Models;

namespace Jabbot.CommandSprockets
{
public abstract class CommandSprocket : ICommandSprocket
{
public abstract IEnumerable<string> SupportedInitiators { get; }
public abstract IEnumerable<string> SupportedCommands { get; }
public abstract bool ExecuteCommand();
public string Intitiator { get; protected set; }
public string Command { get; protected set; }
public string[] Arguments { get; protected set; }
public ChatMessage Message { get; protected set; }
public IBot Bot { get; protected set; }
public bool HasArguments { get { return Arguments.Length > 0; } }

public virtual bool MayHandle(string initiator, string command)
{
return SupportedInitiators.Any(i => i.Equals(initiator, StringComparison.OrdinalIgnoreCase)) &&
SupportedCommands.Any(c => c.Equals(command, StringComparison.OrdinalIgnoreCase));
}

public virtual bool Handle(ChatMessage message, IBot bot)
{
try
{
string[] args = message.Content
.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Intitiator = args.Length > 0 ? args[0] : string.Empty;
Command = args.Length > 1 ? args[1] : string.Empty;
Message = message;
Bot = bot;

if (MayHandle(Intitiator, Command))
{
Arguments = args.Skip(2).ToArray();
return ExecuteCommand();
}
}
catch (InvalidOperationException e)
{
Bot.PrivateReply(Message.Sender, e.GetBaseException().Message);
}
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using Jabbot.Models;

namespace Jabbot.CommandSprockets
{
public abstract class CommandSprocket : ICommandSprocket
{
public abstract IEnumerable<string> SupportedInitiators { get; }
public abstract IEnumerable<string> SupportedCommands { get; }
public abstract bool ExecuteCommand();
public string Intitiator { get; protected set; }
public string Command { get; protected set; }
public string[] Arguments { get; protected set; }
public ChatMessage Message { get; protected set; }
public IBot Bot { get; protected set; }

public bool HasArguments
{
get { return Arguments.Length > 0; }
}

public virtual bool MayHandle(string initiator, string command)
{
return SupportedInitiators.Any(i => i.Equals(initiator, StringComparison.OrdinalIgnoreCase)) &&
SupportedCommands.Any(c => c.Equals(command, StringComparison.OrdinalIgnoreCase));
}

public virtual bool Handle(ChatMessage message, IBot bot)
{
try
{
var args = message.Content.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Intitiator = args.Length > 0 ? args[0] : string.Empty;
Command = args.Length > 1 ? args[1] : string.Empty;
Message = message;
Bot = bot;

if (MayHandle(Intitiator, Command))
{
Arguments = args.Skip(2).ToArray();
return ExecuteCommand();
}
}
catch (InvalidOperationException e)
{
Bot.PrivateReply(Message.Sender, e.GetBaseException().Message);
}

return false;
}

public abstract string SprocketName { get; }
}
}
Loading