using Concilium.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Concilium.Bot.Features
{
    [BotFeature(".fortune")]
    public class FortuneFeature : BotFeatureBase
    {
        public override void Execute(string _sCommand, string _sSource, string _sTarget, string _sMessage, IList<string> _parameters, string _ip)
        {
            if (_parameters.Count != 0)
                throw new InvalidCommandParametersException(".fortune", 0);

            var wc = Concilium.CreateWebClient();
            var result = Encoding.UTF8.GetString(wc.DownloadData("http://www.fortunefortoday.com/getfortuneonly.php"));
            result = result.Replace("\n", "");
            Log.Get().Info(string.Format("{0} requested a fortune cookie", _sSource));

            Client.LocalUser.SendMessage(Concilium.GetDefaultReplyTarget(_sSource, _sTarget), string.Format("{0}: {1}", _sSource, result));
        }
    }
}
