#pragma warning (disable:4786)
#include "../PluginImpl.h"

/*
	To write a plugin-class, derive from either Plugin or PluginImpl.
	The difference is that PluginImpl implements connectToBot(),
	run(). you task is to override the interesting events.
*/

class PongServer : public PluginImpl {
public:
	PongServer() {
	}

// simple auto-op implementation:
	virtual void onJoin(const std::string nick, const std::string channel) {
		m_bot->send(("MODE "+channel+" +o "+nick+"\n").c_str());
	}

// onPing receives a PING from the server. here we incorrectly return just "PONG\n", which should be enough for anyone
	virtual void onPing(const std::string nick,const std::string pingednick) {
		using namespace std;
		m_bot->send("PONG\n");
	}

// onPrivMsg is called when a PRIVMSG is received from the server. Here we handle all messages as commands, check
// if if starts with "exec", and in that case send the rest of the line back to the server
	virtual void onPrivMsg(const std::string nick, const std::list<std::string*> receivers, const std::string message) {
		if (message.substr(0, 4)=="exec") {
			m_bot->send(message.substr(5).c_str());
		}
	}
};

int main() {
	PongServer pong;
	if (!pong.connectToBot())
		return -1;
	pong.run();
	return 0;
}
