예제 #1
0
	void operator()(boost::system::error_code ec, std::size_t bytes_transfered)
	{
		pt::ptree	jsonobj;
		std::istream jsondata( m_buffer.get() );

		/**
		* Here, we got a json object like this:
		* {"retcode":0,"result":{"uiuin":"","account":615050000,"uin":954663841}}
		*
		*/
		//处理!
		try {
			pt::json_parser::read_json( jsondata, jsonobj );

			//TODO, group members
			if( jsonobj.get<int>( "retcode" ) == 0 ) {
				m_this_group->qqnum = jsonobj.get<std::string>( "result.account" );
				BOOST_LOG_TRIVIAL(debug) <<  "qq number of group " <<  console_out_str(m_this_group->name) << " is " <<  m_this_group->qqnum;
				// 写缓存
				pt::json_parser::write_json(std::string("cache/group_qqnumber") + m_this_group->gid, jsonobj);
				//start polling messages, 2 connections!
				BOOST_LOG_TRIVIAL(info) << "start polling messages";

				m_webqq->siggroupnumber(m_this_group);

				m_handler(boost::system::error_code());

				return ;
			}else{
				BOOST_LOG_TRIVIAL(error) << console_out_str("获取群的QQ号码失败");
				pt::json_parser::write_json(std::cerr, jsonobj);
			}
		} catch( const pt::ptree_error & jserr ) {
		}

		try{
		// 读取缓存
			pt::json_parser::read_json(std::string("cache/group_qqnumber") + m_this_group->gid, jsonobj);

			m_this_group->qqnum = jsonobj.get<std::string>( "result.account" );
			BOOST_LOG_TRIVIAL(debug) <<  "(cached) qq number of group" <<  console_out_str(m_this_group->name) << "is" <<  m_this_group->qqnum << std::endl;

			// 向用户报告一个 group 出来了.
			m_webqq->siggroupnumber(m_this_group);
			m_handler(boost::system::error_code());
			return;
		}catch (const pt::ptree_error & jserr){
			boost::delayedcallsec( m_webqq->get_ioservice() , 500 + boost::rand48()() % 100 ,
				boost::bind( &make_update_group_qqnumber_op, m_webqq, m_this_group, m_handler)
			);
		}
	}
예제 #2
0
파일: botctl.cpp 프로젝트: kikidong/avbot
static void handle_search_group(std::string groupqqnum, webqq::qqGroup_ptr group,
	bool needvc, const std::string & vc_img_data, boost::shared_ptr<webqq::webqq> qqclient,
	boost::function<void(std::string)> msg_sender)
{
	static webqq::qqGroup_ptr _group;

	if (needvc)
	{
		// 写入验证码.
		write_vcode(vc_img_data);
		// 向大家吵闹输入验证码.
		std::string msg = boost::str(
			boost::format("哎呀,查找群%s的过程中要输入验证码,"
				"请使用 .qqbot vc XXXX 输入。文件为 qqlog 目录下的 vercode.jpeg")
			% groupqqnum
		);

		std::cout <<  console_out_str(msg) <<  std::endl;
		msg_sender(msg);

		webqq::webqq::search_group_handler search_group_handler;
		search_group_handler = boost::bind(
			handle_search_group, groupqqnum, _1, _2, _3, qqclient, msg_sender
		);

		do_vc_code = boost::bind(
			&webqq::webqq::search_group, qqclient,
			groupqqnum,
			_1,
			search_group_handler
		);
	}
	else if (group)
	{
		// 很好,加入群吧!
		msg_sender("哈呀,验证码正确了个去的,申请加入ing");
		qqclient->join_group(
			group,
			"",
			boost::bind(handle_join_group, _1, _2, _3, qqclient, msg_sender)
		);
	}
	else
	{
		msg_sender("没找到没找到!");
	}
}
예제 #3
0
파일: botctl.cpp 프로젝트: kikidong/avbot
static void handle_join_group(webqq::qqGroup_ptr group, bool needvc,
	const std::string & vc_img_data, boost::shared_ptr<webqq::webqq> qqclient,
	boost::function<void(std::string)> msg_sender)
{
	if (needvc && group)
	{
		// 写入验证码.
		write_vcode(vc_img_data);
		std::string msg = boost::str(
			boost::format(
				"哎呀,加入群%s的过程中要输入验证码,请使用 .qqbot vc XXXX 输入。"
				"文件为 qqlog 目录下的 vercode.jpeg")
			% group->qqnum
		);

		std::cout << console_out_str(msg) <<  std::endl;
		msg_sender(msg);

		webqq::webqq::join_group_handler  join_group_handler;
		join_group_handler  = boost::bind(
			handle_join_group, _1, _2, _3, qqclient, msg_sender
		);

		do_vc_code = boost::bind(
			&webqq::webqq::join_group, qqclient,
			group, _1, join_group_handler
		);
	}
	else if (group && !needvc)
	{
		msg_sender("哎呦妈呀,群加入了呢~等待对方管理员通过\n记得修改 qqbotrc 将群添加到频道组哦~");
	}
	else
	{
		msg_sender("哎呦妈呀,群加不了!");
	}
}
예제 #4
0
파일: decode.cpp 프로젝트: AimuTran/avbot
int main( int argc, char *argv[] )
{
	std::string jsdati_username, jsdati_password;
	std::string hydati_key;
	std::string deathbycaptcha_username, deathbycaptcha_password;
	//http://api.dbcapi.me/in.php
	//http://antigate.com/in.php
	std::string antigate_key, antigate_host;
	bool use_avplayer_free_vercode_decoder(false);

	po::variables_map vm;
	po::options_description desc( "qqbot options" );
	desc.add_options()
	( "help,h", 	"produce help message" )

	( "jsdati_username", po::value<std::string>( &jsdati_username ),	console_out_str("联众打码服务账户").c_str() )
	( "jsdati_password", po::value<std::string>( &jsdati_password ),	console_out_str("联众打码服务密码").c_str() )

	( "hydati_key", po::value<std::string>( &hydati_key ),	console_out_str("慧眼答题服务key").c_str() )

	( "deathbycaptcha_username", po::value<std::string>( &deathbycaptcha_username ),	console_out_str("阿三解码服务账户").c_str() )
	( "deathbycaptcha_password", po::value<std::string>( &deathbycaptcha_password ),	console_out_str("阿三解码服务密码").c_str() )

	( "antigate_key", po::value<std::string>( &antigate_key ),	console_out_str("antigate解码服务key").c_str() )
	( "antigate_host", po::value<std::string>( &antigate_host )->default_value("http://antigate.com/"),	console_out_str("antigate解码服务器地址").c_str() )

	( "use_avplayer_free_vercode_decoder", po::value<bool>( &use_avplayer_free_vercode_decoder ), "don't use" )
	;

	po::store( po::parse_command_line( argc, argv, desc ), vm );
	po::notify( vm );

	if( vm.count( "help" ) ) {
		std::cerr <<  desc <<  std::endl;
		return 1;
	}

	boost::asio::io_service io_service;

	decaptcha::deCAPTCHA decaptcha(io_service);

	if(!hydati_key.empty())
	{
		decaptcha.add_decoder(
			decaptcha::decoder::hydati_decoder(
				io_service, hydati_key
			)
		);
	}

	if(!jsdati_username.empty() && !jsdati_password.empty())
	{
		decaptcha.add_decoder(
			decaptcha::decoder::jsdati_decoder(
				io_service, jsdati_username, jsdati_password
			)
		);
	}

	if (!deathbycaptcha_username.empty() && !deathbycaptcha_password.empty())
	{
		decaptcha.add_decoder(
			decaptcha::decoder::deathbycaptcha_decoder(
				io_service, deathbycaptcha_username, deathbycaptcha_password
			)
		);
	}

	if(!antigate_key.empty())
	{
		decaptcha.add_decoder(
			decaptcha::decoder::antigate_decoder(io_service, antigate_key, antigate_host)
		);
	}

	if(use_avplayer_free_vercode_decoder)
	{
		decaptcha.add_decoder(
			decaptcha::decoder::avplayer_free_decoder(io_service)
		);
	}

	decode_verify_code(io_service, "vercode.jpeg", decaptcha);

	avloop_run( io_service);
	return 0;
}
예제 #5
0
파일: decode.cpp 프로젝트: AimuTran/avbot
static void vc_code_decoded(boost::system::error_code ec, std::string provider, std::string vccode, boost::function<void()> reportbadvc)
{
	AVLOG_INFO << console_out_str("使用 ") <<  console_out_str(provider) << console_out_str(" 成功解码验证码!");

	AVLOG_INFO << console_out_str("验证码是 ") << vccode;
}