The Battle for Wesnoth  1.19.5+dev
chat_command_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
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"
24 
25 namespace events {
26 
28 {
29  return !(c.has_flag('A') && !mp::logged_in_as_moderator());
30 }
31 
32 void chat_command_handler::print(const std::string& title, const std::string& message)
33 {
34  chat_handler_.add_chat_message(std::time(nullptr), title, 0, message);
35 }
36 
38 {
40 }
41 
43 {
45 }
46 
48 {
50 }
51 
53 {
54  if (get_data(1).empty()) return command_failed_need_arg(1);
56 }
57 
59 {
60  if (get_data(1).empty()) return command_failed_need_arg(1);
61  if (get_data(2).empty()) return command_failed_need_arg(2);
64 }
65 
67 {
69 }
70 
72 {
73  if (get_arg(1).empty()) {
74  do_display();
75  }
76  else {
77  utils::string_map symbols;
78  symbols["nick"] = get_arg(1);
79 
80  if (prefs::get().add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
81  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
83  }
84  else {
85  command_failed(VGETTEXT("Invalid username: $nick", symbols));
86  }
87  }
88 }
89 
91 {
92  if (get_arg(1).empty()) {
93  do_display();
94  }
95  else {
96  utils::string_map symbols;
97  symbols["nick"] = get_arg(1);
98 
99  if (prefs::get().add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
100  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
102  }
103  else {
104  command_failed(VGETTEXT("Invalid username: $nick", symbols));
105  }
106  }
107 }
108 
110 {
111  for (int i = 1;!get_arg(i).empty();i++) {
114  utils::string_map symbols;
115  symbols["nick"] = get_arg(i);
116  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
117  }
118 }
119 
121 {
122  gui2::dialogs::preferences_dialog::display(pref_constants::VIEW_FRIENDS);
123 }
124 
126  print(_("version"), game_config::revision);
127 }
128 
130  if (get_data(1).empty()) return command_failed_need_arg(1);
131 
132  config data;
133  config& nickserv = data.add_child("nickserv");
134 
135  nickserv.add_child("info")["name"] = get_data(1);
136  utils::string_map symbols;
137  symbols["nick"] = get_arg(1);
138  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
139 
141 }
142 
145 }
146 
148  std::string report_text;
149  gui2::dialogs::mp_report::execute(report_text);
150 
151  if(!report_text.empty()) {
152  do_network_send(report_text);
153  }
154 }
155 
156 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
config & add_child(config_key_type key)
Definition: config.cpp:440
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:42
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:82
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)
static prefs & get()
bool remove_acquaintance(const std::string &nick)
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
std::size_t i
Definition: function.cpp:1028
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _(const char *str)
Definition: gettext.hpp:93
Handling of system events.
const std::string revision
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
std::map< std::string, t_string > string_map
std::string_view data
Definition: picture.cpp:178
mock_char c