holidays.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Copyright (C) All Rights Reserved
  2. ** Written by Gottem <support@gottem.nl>
  3. ** Website: https://gottem.nl/unreal
  4. ** License: https://gottem.nl/unreal/license
  5. */
  6. /*** <<<MODULE MANAGER START>>>
  7. module {
  8. documentation "https://gottem.nl/unreal/man/holidays";
  9. troubleshooting "In case of problems, check the FAQ at https://gottem.nl/unreal/halp or e-mail me at support@gottem.nl";
  10. min-unrealircd-version "5.*";
  11. //max-unrealircd-version "5.*";
  12. post-install-text {
  13. "The module is installed, now all you need to do is add a 'loadmodule' line to your config file:";
  14. "loadmodule \"third/holidays\";";
  15. "Then /rehash the IRCd.";
  16. "For usage information, refer to the module's documentation found at: https://gottem.nl/unreal/man/holidays";
  17. }
  18. }
  19. *** <<<MODULE MANAGER END>>>
  20. */
  21. // One include for all cross-platform compatibility thangs
  22. #include "unrealircd.h"
  23. // Command to override
  24. #define OVR_PRIVMSG "PRIVMSG"
  25. #define CheckAPIError(apistr, apiobj) \
  26. do { \
  27. if(!(apiobj)) { \
  28. config_error("A critical error occurred on %s for %s: %s", (apistr), MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle)); \
  29. return MOD_FAILED; \
  30. } \
  31. } while(0)
  32. // Quality fowod declarations
  33. char *replaceem(char *str, char *search, char *replace);
  34. CMD_OVERRIDE_FUNC(holidays_override);
  35. // Dat dere module header
  36. ModuleHeader MOD_HEADER = {
  37. "third/holidays", // Module name
  38. "2.0", // Version
  39. "HAPPY HOLIDAYS FROM MALFAJUR", // Description
  40. "Gottem", // Author
  41. "unrealircd-5", // Modversion
  42. };
  43. // Initialisation routine (register hooks, commands and modes or create structs etc)
  44. MOD_INIT() {
  45. MARK_AS_GLOBAL_MODULE(modinfo);
  46. return MOD_SUCCESS;
  47. }
  48. // Actually load the module here (also command overrides as they may not exist in MOD_INIT yet)
  49. MOD_LOAD() {
  50. CheckAPIError("CommandOverrideAdd(PRIVMSG)", CommandOverrideAdd(modinfo->handle, OVR_PRIVMSG, holidays_override));
  51. return MOD_SUCCESS; // We good
  52. }
  53. // Called on unload/rehash obv
  54. MOD_UNLOAD() {
  55. return MOD_SUCCESS; // We good
  56. }
  57. char *replaceem(char *str, char *search, char *replace) {
  58. char *tok = NULL;
  59. char *newstr = NULL;
  60. char *oldstr = NULL;
  61. char *head = NULL;
  62. if(search == NULL || replace == NULL)
  63. return str;
  64. newstr = strdup(str);
  65. head = newstr;
  66. while((tok = strstr(head, search))) {
  67. oldstr = newstr;
  68. newstr = malloc(strlen(oldstr) - strlen(search) + strlen(replace) + 1);
  69. if(newstr == NULL) {
  70. free(oldstr);
  71. return str;
  72. }
  73. memcpy(newstr, oldstr, tok - oldstr);
  74. memcpy(newstr + (tok - oldstr), replace, strlen(replace));
  75. memcpy(newstr + (tok - oldstr) + strlen(replace), tok + strlen(search), strlen(oldstr) - strlen(search) - (tok - oldstr));
  76. memset(newstr + strlen(oldstr) - strlen(search) + strlen(replace), 0, 1);
  77. head = newstr + (tok - oldstr) + strlen(replace);
  78. free(oldstr);
  79. }
  80. return newstr;
  81. }
  82. // Now for the actual override
  83. CMD_OVERRIDE_FUNC(holidays_override) {
  84. // Gets args: CommandOverride *ovr, Client *client, MessageTag *recv_mtags, int parc, char *parv[]
  85. char *search = "kys"; // Replace this
  86. char *replace = NULL; // With this
  87. Client *acptr; // Store /message target
  88. Channel *channel;
  89. time_t t; // Store time cuz we need to point to it latur
  90. struct tm dt; // Store time inf0z
  91. int i;
  92. int wday, day, month; // Only care about DMY, also wat week day
  93. if(BadPtr(parv[1]) || BadPtr(parv[2]) || !MyUser(client) || IsULine(client)) {
  94. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  95. return;
  96. }
  97. if(parv[1][0] != '#') {
  98. acptr = find_person(parv[1], NULL); // Attempt to find message target
  99. if(!acptr || IsULine(acptr)) {
  100. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  101. return;
  102. }
  103. }
  104. else {
  105. channel = find_channel(parv[1], NULL); // Attempt to find message target
  106. if(!channel) {
  107. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  108. return;
  109. }
  110. }
  111. t = TStime();
  112. dt = *localtime(&t);
  113. wday = dt.tm_wday;
  114. day = dt.tm_mday;
  115. month = dt.tm_mon + 1;
  116. //year = dt.tm_year + 1900;
  117. switch(month) {
  118. case 1:
  119. // New year's obv
  120. if(day == 1) replace = "happy new year";
  121. break;
  122. case 2:
  123. // Valentine's lol
  124. if(day == 14) replace = ">tfw no gf";
  125. break;
  126. case 3:
  127. if(day == 29) replace = "happy birthday Waza";
  128. break;
  129. //case 4:
  130. case 5:
  131. if(day == 22) replace = "happy birthday Synny";
  132. break;
  133. /*case 6:
  134. case 7:
  135. case 8:*/
  136. case 9:
  137. if(day == 1) replace = "happy birthday dubsman";
  138. else if(day == 4) replace = "happy birthday psycho";
  139. break;
  140. //case 10:
  141. case 11:
  142. // Thanksgiving
  143. if(wday == 4 && day > 20) replace = "happy gobble day";
  144. break;
  145. case 12:
  146. // Christmas
  147. if(day >= 19 && day <= 26) replace = "merry xmas";
  148. break;
  149. default:
  150. break;
  151. }
  152. // Ain't got nuffin
  153. if(!replace) {
  154. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  155. return;
  156. }
  157. for(i = 2; i < parc; i++)
  158. parv[i] = replaceem(parv[i], search, replace);
  159. CallCommandOverride(ovr, client, recv_mtags, parc, parv); // Run original function yo
  160. }