The Battle for Wesnoth  1.17.23+dev
chat_command_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2023
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "chat_command_handler.hpp"
16 
17 #include "chat_events.hpp"
19 #include "game_version.hpp"
22 #include "map_command_handler.hpp"
23 #include "preferences/display.hpp"
24 #include "preferences/game.hpp"
25 
26 namespace events {
27 
29 {
30  return !(c.has_flag('A') && !mp::logged_in_as_moderator());
31 }
32 
33 void chat_command_handler::print(const std::string& title, const std::string& message)
34 {
35  chat_handler_.add_chat_message(std::time(nullptr), title, 0, message);
36 }
37 
39 {
41 }
42 
44 {
46 }
47 
49 {
51 }
52 
54 {
55  if (get_data(1).empty()) return command_failed_need_arg(1);
57 }
58 
60 {
61  if (get_data(1).empty()) return command_failed_need_arg(1);
62  if (get_data(2).empty()) return command_failed_need_arg(2);
65 }
66 
68 {
70 }
71 
73 {
74  if (get_arg(1).empty()) {
75  do_display();
76  }
77  else {
78  utils::string_map symbols;
79  symbols["nick"] = get_arg(1);
80 
81  if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
82  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
84  }
85  else {
86  command_failed(VGETTEXT("Invalid username: $nick", symbols));
87  }
88  }
89 }
90 
92 {
93  if (get_arg(1).empty()) {
94  do_display();
95  }
96  else {
97  utils::string_map symbols;
98  symbols["nick"] = get_arg(1);
99 
100  if (preferences::add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
101  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
103  }
104  else {
105  command_failed(VGETTEXT("Invalid username: $nick", symbols));
106  }
107  }
108 }
109 
111 {
112  for (int i = 1;!get_arg(i).empty();i++) {
115  utils::string_map symbols;
116  symbols["nick"] = get_arg(i);
117  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
118  }
119 }
120 
122 {
123  gui2::dialogs::preferences_dialog::display(preferences::VIEW_FRIENDS);
124 }
125 
127  print(_("version"), game_config::revision);
128 }
129 
131  if (get_data(1).empty()) return command_failed_need_arg(1);
132 
133  config data;
134  config& nickserv = data.add_child("nickserv");
135 
136  nickserv.add_child("info")["name"] = get_data(1);
137  utils::string_map symbols;
138  symbols["nick"] = get_arg(1);
139  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
140 
142 }
143 
146 }
147 
149  std::string report_text;
150  gui2::dialogs::mp_report::execute(report_text);
151 
152  if(!report_text.empty()) {
153  do_network_send(report_text);
154  }
155 }
156 
157 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
config & add_child(config_key_type key)
Definition: config.cpp:445
void do_info()
Request information about a user from the server.
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
void print(const std::string &title, const std::string &message)
virtual void clear_messages()=0
virtual void user_relation_changed(const std::string &name)
Called when a processed command results in a relation (friend/ignore) change for a user whose name is...
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
void change_logging(const std::string &data)
Change the log level of a log domain.
Definition: chat_events.cpp:45
virtual void send_chat_message(const std::string &message, bool allies_only=false)=0
virtual void send_whisper(const std::string &receiver, const std::string &message)
virtual void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, MESSAGE_TYPE type=MESSAGE_PRIVATE)=0
virtual void send_to_server(const config &cfg)=0
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:85
virtual std::string get_arg(unsigned argn) const
virtual std::string get_data(unsigned argn=1) const
void command_failed(const std::string &message, bool=false)
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
std::size_t i
Definition: function.cpp:968
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _(const char *str)
Definition: gettext.hpp:93
Handling of system events.
Definition: manager.hpp:43
const std::string revision
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:241
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:227
std::map< std::string, t_string > string_map
std::string_view data
Definition: picture.cpp:199
mock_char c