The Battle for Wesnoth  1.17.0-dev
chat_command_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2021
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"
21 #include "map_command_handler.hpp"
22 #include "preferences/display.hpp"
23 #include "preferences/game.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 {
49  if (get_data(1).empty()) return command_failed_need_arg(1);
51 }
52 
54 {
55  if (get_data(1).empty()) return command_failed_need_arg(1);
56  if (get_data(2).empty()) return command_failed_need_arg(2);
59 }
60 
62 {
64 }
65 
67 {
68  if (get_arg(1).empty()) {
69  do_display();
70  }
71  else {
72  utils::string_map symbols;
73  symbols["nick"] = get_arg(1);
74 
75  if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
76  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
78  }
79  else {
80  command_failed(VGETTEXT("Invalid username: $nick", symbols));
81  }
82  }
83 }
84 
86 {
87  if (get_arg(1).empty()) {
88  do_display();
89  }
90  else {
91  utils::string_map symbols;
92  symbols["nick"] = get_arg(1);
93 
94  if (preferences::add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
95  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
97  }
98  else {
99  command_failed(VGETTEXT("Invalid username: $nick", symbols));
100  }
101  }
102 }
103 
105 {
106  for (int i = 1;!get_arg(i).empty();i++) {
109  utils::string_map symbols;
110  symbols["nick"] = get_arg(i);
111  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
112  }
113 }
114 
116 {
117  gui2::dialogs::preferences_dialog::display(preferences::VIEW_FRIENDS);
118 }
119 
121  print(_("version"), game_config::revision);
122 }
123 
125  if (get_data(1).empty()) return command_failed_need_arg(1);
126 
127  config data;
128  config& nickserv = data.add_child("nickserv");
129 
130  nickserv.add_child("info")["name"] = get_data(1);
131  utils::string_map symbols;
132  symbols["nick"] = get_arg(1);
133  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
134 
136 }
137 
138 }
void command_failed(const std::string &message, bool=false)
void do_info()
Request information about a user from the server.
std::map< std::string, t_string > string_map
Interfaces for manipulating version numbers of engine, add-ons, etc.
virtual std::string get_data(unsigned argn=1) const
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
void print(const std::string &title, const std::string &message)
virtual std::string get_arg(unsigned argn) const
static std::string _(const char *str)
Definition: gettext.hpp:93
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:255
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
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)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:236
void change_logging(const std::string &data)
Change the log level of a log domain.
Definition: chat_events.cpp:45
std::size_t i
Definition: function.cpp:967
const std::string revision
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
config & add_child(config_key_type key)
Definition: config.cpp:514
Handling of system events.
Definition: manager.hpp:43
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
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...
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
mock_char c
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