All pastes #736882 Raw Edit

JokeCommand

public text v1 · immutable
·published 2007-10-14 22:13 UTC
rendered paste body
// BitchSlapCommand.cs created with MonoDevelop
// User: damien at 13:49 28/09/2007
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using DigitalNetworks.Irc.Bot.Common;

namespace DigitalNetworks.Irc.Bot.Plugins
{
	public class BashCommand : ICommand
	{
		public string Command
		{
			get { return "bash"; }
		}
		
		public string Name
		{
			get { return "Bash"; }
		}
		
		public bool Watcher
		{
			get { return false; }
		}
		
		public void Process(string line)
		{
			string param = Helper.GetParameters(line);
			int id;
			HttpWebRequest request;
			if (int.TryParse(param, out id))
			{
				
				request = (HttpWebRequest)WebRequest.Create("http://bash.org/?" + id);
			}
			else
			{
				request = (HttpWebRequest)WebRequest.Create("http://bash.org/?random1");
			}
			
			WebResponse response = request.GetResponse();
			StreamReader sr = new StreamReader(response.GetResponseStream());
			string quote = sr.ReadToEnd();
			
			Match match = Regex.Match(quote, @"(?:<p class=""qt"">)(?<quote>.*)(?:</p>)", RegexOptions.Singleline);
			Console.WriteLine(match.Success);
			quote = match.Groups["quote"].Value;
			quote = quote.Replace("&lt;", "<");
			quote = quote.Replace("<br />", "\n");
			quote = quote.Replace("&gt;", ">");
			quote = quote.Replace("&quote;", "\"");
			IrcClient.PrivateMessage(quote);
		}
		
		public void ProcessWatch(string line)
		{
			
		}
		
		public string GetHelp()
		{
			return string.Empty;
		}
	}
}