~singpolyma/biboumi

77a84fd2d99bcffd562f09c8235e5bcd365accb1 — Florent Le Coz 9 years ago 6ebb586
NOTICE from channels are displayed in the channel, with a green "[notice]"
2 files changed, 20 insertions(+), 1 deletions(-)

M src/irc/irc_client.cpp
M src/irc/irc_client.hpp
M src/irc/irc_client.cpp => src/irc/irc_client.cpp +15 -0
@@ 235,6 235,21 @@ void IrcClient::forward_server_message(const IrcMessage& message)
  this->bridge->send_xmpp_message(this->hostname, from, body);
}

void IrcClient::on_notice(const IrcMessage& message)
{
  std::string from = message.prefix;
  const std::string to = message.arguments[0];
  const std::string body = message.arguments[1];

  if (to == this->current_nick)
    this->bridge->send_xmpp_message(this->hostname, from, body);
  else
    {
      IrcMessage modified_message(std::move(from), "PRIVMSG", {to, std::string("\u000303[notice]\u0003 ") + body});
      this->on_channel_message(modified_message);
    }
}

void IrcClient::on_isupport_message(const IrcMessage& message)
{
  const size_t len = message.arguments.size();

M src/irc/irc_client.hpp => src/irc/irc_client.hpp +5 -1
@@ 148,6 148,10 @@ public:
   */
  void on_channel_message(const IrcMessage& message);
  /**
   * A notice is received
   */
  void on_notice(const IrcMessage& message);
  /**
   * Save the topic in the IrcChannel
   */
  void on_topic_received(const IrcMessage& message);


@@ 282,7 286,7 @@ private:
typedef void (IrcClient::*irc_callback_t)(const IrcMessage&);

static const std::unordered_map<std::string, irc_callback_t> irc_callbacks = {
  {"NOTICE", &IrcClient::forward_server_message},
  {"NOTICE", &IrcClient::on_notice},
  {"002", &IrcClient::forward_server_message},
  {"003", &IrcClient::forward_server_message},
  {"005", &IrcClient::on_isupport_message},