lcn.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* vcc/plugins/robot/lcn.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc 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 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <dirent.h>
  21. #include <arpa/inet.h>
  22. #include <vcc/vcc.h>
  23. #include <vcc/pretty.h>
  24. #include <vcc/plugin.h>
  25. #include <vcc/version.h>
  26. #define LCN_PATH "/root/lcn-articles/"
  27. int send_msg(char *, char *);
  28. struct cmdtable lcn_cmdtab[] = {
  29. { NULL, 0, 0 }
  30. };
  31. struct plugin plg_lcn = {
  32. .state = 0,
  33. .name = "lcn",
  34. .descr = "The lcn plugin: read lcn articles online. ",
  35. .cmdtab = lcn_cmdtab
  36. };
  37. #define this_plg (&plg_lcn)
  38. int robot_lslcn(char *s) {
  39. DIR *dir;
  40. struct dirent *dirent;
  41. char p[MSG_SIZE];
  42. (void) s;
  43. if (!(dir = opendir(LCN_PATH))) {
  44. send_msg("Oops! There are something wrong when I tried to finish my work...\n", "robot");
  45. return 1;
  46. }
  47. while ((dirent = readdir(dir))) {
  48. if (dirent->d_type == DT_REG) {
  49. memset(p, 0, MSG_SIZE);
  50. sprintf(p, "%s\n", dirent->d_name);
  51. send_msg(p, "robot");
  52. }
  53. }
  54. closedir(dir);
  55. return 0;
  56. }