コード例 #1
0
ファイル: cs_fantasy_top.cpp プロジェクト: bonnedav/anope
	void DoTop(CommandSource &source, const std::vector<Anope::string> &params, bool is_global, int limit = 1)
	{

		Anope::string channel;
		if (!params.empty())
			channel = params[0];
		else if (source.c && source.c->ci)
			channel = source.c->ci->GetName();

		if (!is_global && channel.empty())
			is_global = true;

		try
		{
			SQL::Query query;
			query = "SELECT nick, letters, words, line, actions,"
				"smileys_happy+smileys_sad+smileys_other as smileys "
				"FROM `" + prefix + "chanstats` "
				"WHERE `nick` != '' AND `chan` = @channel@ AND `type` = 'total' "
				"ORDER BY `letters` DESC LIMIT @limit@;";
			query.SetValue("limit", limit, false);

			if (is_global)
				query.SetValue("channel", "");
			else
				query.SetValue("channel", channel.c_str());

			SQL::Result res = this->RunQuery(query);

			if (res.Rows() > 0)
			{
				source.Reply(_("Top %i of %s"), limit, (is_global ? "Network" : channel.c_str()));
				for (int i = 0; i < res.Rows(); ++i)
				{
					source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
						i+1, res.Get(i, "nick").c_str(), res.Get(i, "letters").c_str(),
						res.Get(i, "words").c_str(), res.Get(i, "line").c_str(),
						res.Get(i, "smileys").c_str(), res.Get(i, "actions").c_str());
				}
			}
			else
				source.Reply(_("No stats for %s."), is_global ? "Network" : channel.c_str());
		}
		catch (const SQL::Exception &ex)
		{
			Log(LOG_DEBUG) << ex.GetReason();
		}
	}
コード例 #2
0
	void DoStats(CommandSource &source, const bool is_global, const std::vector<Anope::string> &params)
	{
		Anope::string display, channel;

		/*
		 * possible parameters are:
		 *   stats [channel] [nick]
		 *   stats [channel]
		 *   stats [nick]
		 *   stats
		 */

		switch (params.size())
		{
			case 2:
				channel = params[0];
				display = params[1];
				break;
			case 1:
				if (params[0][0] == '#')
					channel = params[0];
				else
				{
					if (NickAlias *na = NickAlias::Find(params[0]))
						display = na->nc->display;
					else
					{
						source.Reply(_("%s not found."), params[0].c_str());
						return;
					}
				}
				break;
		}

		if (display.empty())
			display = source.nc->display;

		try
		{
			SQL::Query query;
			query = "SELECT letters, words, line, smileys_happy+smileys_sad+smileys_other as smileys,"
				"actions FROM `" + prefix + "chanstats` "
				"WHERE `nick` = @nick@ AND `chan` = @channel@ AND `type` = 'total';";
			if (is_global || channel.empty())
				query.SetValue("channel", "");
			else
				query.SetValue("channel", channel);
			query.SetValue("nick", display);
			SQL::Result res = this->RunQuery(query);

			if (res.Rows() > 0)
			{
				if (is_global)
					source.Reply(_("Network stats for %s:"), display.c_str());
				else
					source.Reply(_("Channel stats for %s on %s:"), display.c_str(), channel.c_str());

				source.Reply(_("letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
						res.Get(0, "letters").c_str(), res.Get(0, "words").c_str(),
						res.Get(0, "line").c_str(), res.Get(0, "smileys").c_str(),
						res.Get(0, "actions").c_str());
			}
			else
				source.Reply(_("No stats for %s."), display.c_str());
		}
		catch (const SQL::Exception &ex)
		{
			Log(LOG_DEBUG) << ex.GetReason();
		}

	}