Exemple #1
0
	EventResult OnLog(Log *l)
	{
		Channel *c = findchannel(Config->LogChan);

		if(!c)
			return EVENT_CONTINUE;

		std::stringstream logstream;
		Flux::string message = Flux::Sanitize(l->buffer.str());

		if(l->u && !l->c)
			message = l->u->nick + " " + message;

		if(l->u && l->c)
			message = l->u->nick + " used " + l->c->name + " " + message;

		switch(l->type)
		{
			case LOG_NORMAL:
				logstream << message;
				break;
			case LOG_THREAD:

				if(protocoldebug)
					logstream << "[THREAD] " << message;

				break;
			case LOG_DEBUG:

				if(dev || protocoldebug)
					logstream << message;

				break;
//       case LOG_DEVEL:
//  if(!protocoldebug && dev)
//    logstream << message;
//  break;
			case LOG_RAWIO:
				return EVENT_CONTINUE;
			case LOG_CRITICAL:
				logstream << "\0034[CRITICAL] " << message << "\017";
				break;
			case LOG_WARN:
				logstream << "\0037[WARNING]\017 " << message;
				break;
			default:
				break;
		}

		c->SendMessage(NoTermColor(logstream.str()));
		return EVENT_CONTINUE;
	}
Exemple #2
0
  void Run(CommandSource &source, const Flux::vector &params)
  {
    User *u = source.u;
    Channel *c = source.c;
    Flux::string area = params[0], tmpfile = TextFile::TempFile(binary_dir+"/runtime/navn_xml.tmp.XXXXXX");

    if(tmpfile.empty())
    {
      Log() << "Failed to get temp file";
      return;
    }
    area.trim();

    Flux::string url = Config->Parser->Get("Modules", "WeatherURL", "http://www.google.com/ig/api?weather=%l");
    url = url.replace_all_cs("%l", area.is_number_only()?area:area.url_str());

    Log(LOG_DEBUG) << "wget weather url \"" << url << "\" for !weather command used";
    system(Flux::string("wget -q -O "+tmpfile+" - "+url).c_str());
    XMLFile *xf = new XMLFile(tmpfile);

    Flux::string city = xf->Tags["xml_api_reply"].Tags["weather"].Tags["forecast_information"].Tags["city"].Attributes["data"].Value;
    Flux::string condition = xf->Tags["xml_api_reply"].Tags["weather"].Tags["current_conditions"].Tags["condition"].Attributes["data"].Value;
    Flux::string temp_f = xf->Tags["xml_api_reply"].Tags["weather"].Tags["current_conditions"].Tags["temp_f"].Attributes["data"].Value;
    Flux::string temp_c = xf->Tags["xml_api_reply"].Tags["weather"].Tags["current_conditions"].Tags["temp_c"].Attributes["data"].Value;
    Flux::string humidity = xf->Tags["xml_api_reply"].Tags["weather"].Tags["current_conditions"].Tags["humidity"].Attributes["data"].Value;
    Flux::string windy = xf->Tags["xml_api_reply"].Tags["weather"].Tags["current_conditions"].Tags["wind_condition"].Attributes["data"].Value;

    delete xf;

    if(city.strip().empty())
    {
      source.Reply("Weather information for \2%s\2 not found.", area.c_str());
      return;
    }
    int temp_k = static_cast<int>(temp_c) + 273; // Calculate degrees kelvin from degrees celsius
    c->SendMessage("%s Current Condition: %s, %s, %s, %s %cF %s %cC %iK", city.strip().c_str(), condition.strip().c_str(), humidity.strip().c_str(), windy.strip().c_str(), temp_f.c_str(), 0x00B0, temp_c.c_str(), 0x00B0, temp_k);

    Log(u, this) << "to get weather for area '" << area << "'";
  }