MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / route

Method route

src/dpp/commandhandler.cpp:182–298  ·  view source on GitHub ↗

Note that message based command routing relies on cache to resolve ping types (e.g. user, channel ping). * There isn't really a way around this for many things because there is no 'resolved' member for it. * We only get resolved information for the user issuing the command. */

Source from the content-addressed store, hash-verified

180 * We only get resolved information for the user issuing the command.
181 */
182void commandhandler::route(const struct dpp::message_create_t& event)
183{
184 std::string msg_content = event.msg.content;
185 if (string_has_prefix(msg_content)) {
186 /* Put the string into stringstream to parse parameters at spaces.
187 * We use stringstream as it handles multiple spaces etc nicely.
188 */
189 std::stringstream ss(msg_content);
190 std::string command;
191 ss >> command;
192 /* Prefixed command, the prefix was removed */
193 auto found_cmd = commands.find(lowercase(command));
194 if (found_cmd != commands.end()) {
195 /* Filter out guild specific commands that are not for the current guild */
196 if (found_cmd->second.guild_id && found_cmd->second.guild_id != event.msg.guild_id) {
197 return;
198 }
199
200 parameter_list_t call_params;
201
202 /* Command found; parse parameters */
203 for (auto& p : found_cmd->second.parameters) {
204 command_parameter param;
205
206 /* Check for end of stream */
207 if (!ss) {
208 /* If it's an optional param, we dont care */
209 if (!p.second.optional) {
210 /* Trigger missing parameter handler? */
211 }
212 break;
213 }
214
215 switch (p.second.type) {
216 case pt_string: {
217 std::string x;
218 ss >> x;
219 param = x;
220 }
221 break;
222 case pt_role: {
223 std::string x;
224 ss >> x;
225 if (x.length() > 4 && x[0] == '<' && x[1] == '&') {
226 snowflake rid = from_string<uint64_t>(x.substr(2, x.length() - 1));
227 role* r = dpp::find_role(rid);
228 if (r) {
229 param = *r;
230 }
231 }
232 }
233 break;
234 case pt_channel: {
235 std::string x;
236 ss >> x;
237 if (x.length() > 4 && x[0] == '<' && x[1] == '#') {
238 snowflake cid = from_string<uint64_t>(x.substr(2, x.length() - 1));
239 channel* c = dpp::find_channel(cid);

Callers 1

commandhandlerMethod · 0.95

Calls 5

lowercaseFunction · 0.85
get_parameterMethod · 0.80
findMethod · 0.45
endMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected