cmdsnote.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * cmdsnote.c -- part of notes.mod
  3. * handles all notes interaction over the party line
  4. *
  5. */
  6. static void cmd_fwd(int idx, char *par)
  7. {
  8. if (!par[0]) {
  9. dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
  10. return;
  11. }
  12. struct userrec *u1 = get_user_by_handle(userlist, newsplit(&par));
  13. if (!u1) {
  14. dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
  15. return;
  16. }
  17. if ((u1->flags & USER_OWNER) && egg_strcasecmp(u1->handle, dcc[idx].nick)) {
  18. dprintf(idx, "%s\n", NOTES_FWD_OWNER);
  19. return;
  20. }
  21. if (!par[0]) {
  22. putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, u1->handle);
  23. dprintf(idx, NOTES_FWD_FOR, u1->handle);
  24. set_user(&USERENTRY_FWD, u1, NULL);
  25. return;
  26. }
  27. /* Thanks to vertex & dw */
  28. if (strchr(par, '@') == NULL) {
  29. dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
  30. return;
  31. }
  32. putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, u1->handle, par);
  33. dprintf(idx, NOTES_FWD_CHANGED, u1->handle, par);
  34. set_user(&USERENTRY_FWD, u1, par);
  35. }
  36. static void cmd_notes(int idx, char *par)
  37. {
  38. if (!par[0]) {
  39. dprintf(idx, "%s: notes index\n", NOTES_USAGE);
  40. dprintf(idx, " notes read <# or ALL>\n");
  41. dprintf(idx, " notes erase <# or ALL>\n");
  42. dprintf(idx, " %s\n", NOTES_MAYBE);
  43. dprintf(idx, " ex: notes erase 2-4;8;16-\n");
  44. return;
  45. }
  46. char *fcn = newsplit(&par);
  47. if (!egg_strcasecmp(fcn, "index"))
  48. notes_read(dcc[idx].nick, "", "+", idx);
  49. else if (!egg_strcasecmp(fcn, "read")) {
  50. if (!egg_strcasecmp(par, "all"))
  51. notes_read(dcc[idx].nick, "", "-", idx);
  52. else
  53. notes_read(dcc[idx].nick, "", par, idx);
  54. } else if (!egg_strcasecmp(fcn, "erase")) {
  55. if (!egg_strcasecmp(par, "all"))
  56. notes_del(dcc[idx].nick, "", "-", idx);
  57. else
  58. notes_del(dcc[idx].nick, "", par, idx);
  59. } else {
  60. dprintf(idx, "%s\n", NOTES_MUSTBE);
  61. return;
  62. }
  63. putlog(LOG_CMDS, "*", "#%s# notes %s %s", dcc[idx].nick, fcn, par);
  64. }
  65. static void cmd_note(int idx, char *par)
  66. {
  67. char handle[512] = "", *p = newsplit(&par);
  68. int echo;
  69. if (!par[0]) {
  70. dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
  71. return;
  72. }
  73. while ((*par == ' ') || (*par == '<') || (*par == '>'))
  74. par++; /* These are now illegal *starting* notes
  75. * characters */
  76. echo = (dcc[idx].status & STAT_ECHO);
  77. splitc(handle, p, ',');
  78. while (handle[0]) {
  79. rmspace(handle);
  80. add_note(handle, dcc[idx].nick, par, idx, echo);
  81. splitc(handle, p, ',');
  82. }
  83. rmspace(p);
  84. add_note(p, dcc[idx].nick, par, idx, echo);
  85. }
  86. static cmd_t notes_cmds[] =
  87. {
  88. {"fwd", "m", (Function) cmd_fwd, NULL},
  89. {"notes", "", (Function) cmd_notes, NULL},
  90. {"note", "", (Function) cmd_note, NULL},
  91. {NULL, NULL, NULL, NULL}
  92. };