浏览代码

IRCClient: Add support for /HOP and /TOPIC commands

Brendan Coles 5 年之前
父节点
当前提交
2de2f49abc
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. 20 0
      Applications/IRCClient/IRCClient.cpp
  2. 1 0
      Applications/IRCClient/IRCClient.h

+ 20 - 0
Applications/IRCClient/IRCClient.cpp

@@ -312,6 +312,11 @@ void IRCClient::add_server_message(const String& text, Color color)
     m_server_subwindow->did_add_message();
 }
 
+void IRCClient::send_topic(const String& channel_name, const String& text)
+{
+    send(String::format("TOPIC %s :%s\r\n", channel_name.characters(), text.characters()));
+}
+
 void IRCClient::send_privmsg(const String& target, const String& text)
 {
     send(String::format("PRIVMSG %s :%s\r\n", target.characters(), text.characters()));
@@ -676,6 +681,21 @@ void IRCClient::handle_user_command(const String& input)
             part_channel(parts[1]);
         return;
     }
+    if (command == "/HOP") {
+        if (parts.size() >= 2) {
+            part_channel(parts[1]);
+            join_channel(parts[1]);
+        }
+        return;
+    }
+    if (command == "/TOPIC") {
+        if (parts.size() < 3)
+            return;
+        auto channel = parts[1];
+        auto topic = input.view().substring_view_starting_after_substring(channel);
+        send_topic(channel, topic);
+        return;
+    }
     if (command == "/QUERY") {
         if (parts.size() >= 2) {
             auto& query = ensure_query(parts[1]);

+ 1 - 0
Applications/IRCClient/IRCClient.h

@@ -133,6 +133,7 @@ private:
     void send_pong(const String& server);
     void send_privmsg(const String& target, const String&);
     void send_notice(const String& target, const String&);
+    void send_topic(const String& channel_name, const String&);
     void send_whois(const String&);
     void process_line(ByteBuffer&&);
     void handle_join(const Message&);