mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:17:45 +00:00
IRCClient: Add ability to send query messages.
You can't open a query yet, but if someone starts one with you, you can respond at least.
This commit is contained in:
parent
7e3673f710
commit
08c15be0ca
5 changed files with 21 additions and 3 deletions
|
@ -9,7 +9,7 @@ IRCAppWindow::IRCAppWindow()
|
||||||
: GWindow()
|
: GWindow()
|
||||||
, m_client("127.0.0.1", 6667)
|
, m_client("127.0.0.1", 6667)
|
||||||
{
|
{
|
||||||
set_title(String::format("IRC Client: %s:%d", m_client.hostname().characters(), m_client.port()));
|
set_title(String::format("IRC Client: %s@%s:%d", m_client.nickname().characters(), m_client.hostname().characters(), m_client.port()));
|
||||||
set_rect(200, 200, 600, 400);
|
set_rect(200, 200, 600, 400);
|
||||||
setup_client();
|
setup_client();
|
||||||
setup_widgets();
|
setup_widgets();
|
||||||
|
@ -25,10 +25,18 @@ void IRCAppWindow::setup_client()
|
||||||
m_client.join_channel("#test");
|
m_client.join_channel("#test");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_client.on_channel_message = [this] (const String& channel_name) {
|
||||||
|
ensure_window(IRCClientWindow::Channel, channel_name);
|
||||||
|
};
|
||||||
|
|
||||||
m_client.on_join = [this] (const String& channel_name) {
|
m_client.on_join = [this] (const String& channel_name) {
|
||||||
ensure_window(IRCClientWindow::Channel, channel_name);
|
ensure_window(IRCClientWindow::Channel, channel_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_client.on_query_message = [this] (const String& name) {
|
||||||
|
ensure_window(IRCClientWindow::Query, name);
|
||||||
|
};
|
||||||
|
|
||||||
m_client.connect();
|
m_client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,6 +253,7 @@ void IRCClient::handle_user_input_in_query(const String& query_name, const Strin
|
||||||
{
|
{
|
||||||
if (input.is_empty())
|
if (input.is_empty())
|
||||||
return;
|
return;
|
||||||
|
ensure_query(query_name).say(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRCClient::handle_user_input_in_server(const String& input)
|
void IRCClient::handle_user_input_in_server(const String& input)
|
||||||
|
@ -307,7 +308,7 @@ void IRCClient::handle_privmsg(const Message& msg)
|
||||||
auto& query = ensure_query(sender_nick);
|
auto& query = ensure_query(sender_nick);
|
||||||
query.add_message(sender_prefix, sender_nick, msg.arguments[1]);
|
query.add_message(sender_prefix, sender_nick, msg.arguments[1]);
|
||||||
if (on_query_message)
|
if (on_query_message)
|
||||||
on_query_message(target);
|
on_query_message(sender_nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRCQuery& IRCClient::ensure_query(const String& name)
|
IRCQuery& IRCClient::ensure_query(const String& name)
|
||||||
|
@ -336,7 +337,7 @@ void IRCClient::handle_ping(const Message& msg)
|
||||||
{
|
{
|
||||||
if (msg.arguments.size() < 0)
|
if (msg.arguments.size() < 0)
|
||||||
return;
|
return;
|
||||||
m_log->add_message(0, "", String::format("Ping? Pong! %s\n", msg.arguments[0].characters()));
|
m_log->add_message(0, "Server", "Ping? Pong!");
|
||||||
send_pong(msg.arguments[0]);
|
send_pong(msg.arguments[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ class GNotifier;
|
||||||
|
|
||||||
class IRCClient {
|
class IRCClient {
|
||||||
friend class IRCChannel;
|
friend class IRCChannel;
|
||||||
|
friend class IRCQuery;
|
||||||
public:
|
public:
|
||||||
IRCClient(const String& address, int port = 6667);
|
IRCClient(const String& address, int port = 6667);
|
||||||
~IRCClient();
|
~IRCClient();
|
||||||
|
|
|
@ -30,3 +30,9 @@ void IRCQuery::add_message(char prefix, const String& name, const String& text)
|
||||||
log().add_message(prefix, name, text);
|
log().add_message(prefix, name, text);
|
||||||
dump();
|
dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRCQuery::say(const String& text)
|
||||||
|
{
|
||||||
|
m_client.send_privmsg(m_name, text);
|
||||||
|
add_message(' ', m_client.nickname(), text);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
const IRCLogBuffer& log() const { return *m_log; }
|
const IRCLogBuffer& log() const { return *m_log; }
|
||||||
IRCLogBuffer& log() { return *m_log; }
|
IRCLogBuffer& log() { return *m_log; }
|
||||||
|
|
||||||
|
void say(const String&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IRCQuery(IRCClient&, const String& name);
|
IRCQuery(IRCClient&, const String& name);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue