| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /* vcc/plugins/robot/robot.c
- *
- * This file is part of vcc.
- *
- * vcc is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * vcc is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with vcc. If not, see <https://www.gnu.org/licenses/>
- */
- #include <stdio.h>
- #include <string.h>
- #include <arpa/inet.h>
- #include <vcc/vcc.h>
- #include <vcc/pretty.h>
- #include <vcc/plugin.h>
- #include <vcc/version.h>
- #include <vcc/interfaces.h>
- static int robot_plg_init(void);
- static char *do_robot_cmd(char *s);
- struct cmdtable robot_cmdtab[] = {
- { NULL, NULL, NULL }
- };
- struct plugin plg_robot = {
- .state = 0,
- .name = "robot",
- .descr = "The robot plugin. ",
- .cmdtab = robot_cmdtab,
- .init = robot_plg_init,
- };
- static struct cmdtable commands[] = {
- { NULL, NULL, NULL }
- };
- #define this_plg (&plg_robot)
- char *robot_hook(struct hook_info *hi) {
- if (strncmp(hi->msg, "robot, ", 7))
- return 0;
- return do_robot_cmd(hi->msg);
- }
- typedef int (* fptr_t) (char *);
- fptr_t execute_in(struct cmdtable *, char *, int);
- static char *do_robot_cmd(char *msg) {
- fptr_t f;
- int len;
- char *p;
-
- p = msg += 7;
- for (len = 0; *p && *p != '\n'; p++, len++)
- ;
- if (!(f = execute_in(commands, msg, len))) {
- send_msg("Are you calling me? I don't know what's your meaning. \n", "robot");
- return 0;
- }
- return f(msg) ? HOOK_IGNORE : HOOK_FAILED;
- }
- static int robot_plg_init(void) {
- register_hook(HOOK_RECV, robot_hook);
- return 0;
- }
|