1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?php include_once('Net/SmartIRC.php'); class weatherbot { function weather(&$irc, &$data) { $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Yeah, weather'); } } $host = "localhost"; $port = 6667; $nick = "weather"; $chan = "#weather"; $bot = &new weatherbot( ); $irc = &new Net_SmartIRC( ); $irc->setUseSockets( TRUE ); $irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '^weather', $bot, 'weather' ); $irc->connect( $host, $port ); $irc->login( $nick, 'Weather bot', 0, $nick ); $irc->join( array( $chan ) ); $irc->listen( ); $irc->disconnect( ); ?> |
1 | C:\ircd> php ircbot.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?php include_once('Net/SmartIRC.php'); include_once('Services/Weather.php'); $weather = new Services_Weather(); $wdc = $weather->service( "Weatherdotcom" ); class weatherbot { function weather(&$irc, &$data) { global $wdc; $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Yeah, weather'); $fc = $wdc->getForecast( 94587, 1 ); foreach( $fc['days'] as $day ) { $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Condition: ".$day['day'][ 'condition' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "High: ".$day[ 'temperatureHigh' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Low: ".$day[ 'temperatureLow' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Wind: ".$day['day'][ 'wind' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Wind Degrees: ".$day['day'][ 'windDegrees' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Wind Direction: ".$day['day'][ 'windDirection' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Precipitation: ".$day['day'][ 'precipitation' ] ); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Humidity: ".$day['day'][ 'humidity' ] ); } } } $host = "localhost"; $port = 6667; $nick = "weather"; $chan = "#weather"; $bot = &new weatherbot( ); $irc = &new Net_SmartIRC( ); $irc->setUseSockets( TRUE ); $irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '^weather', $bot, 'weather' ); $irc->connect( $host, $port ); $irc->login( $nick, 'Weather bot', 0, $nick ); $irc->join( array( $chan ) ); $irc->listen( ); $irc->disconnect( ); ?> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |