PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/core.php

https://github.com/cooper/php-fox-bot
PHP | 753 lines | 753 code | 0 blank | 0 comment | 0 complexity | 9e83b69db2dbca0ed3dc4ac9c9a4faa8 MD5 | raw file
  1. <?php
  2. error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  3. set_time_limit(0);
  4. echo(" __ _ _ \r\n");
  5. echo(" / _| | | | | \r\n");
  6. echo(" | |_ ___ __ __| |__ ___ | |_ \r\n");
  7. echo(" | _/ _ \\\\ \\/ /| '_ \\ / _ \\| __|\r\n");
  8. echo(" | || (_) |> < | |_) | (_) | |_ \r\n");
  9. echo(" |_| \___//_/\_\|_.__/ \___/ \__|\r\n");
  10. echo("A poorly-coded PHP bot!\r\n");
  11. class fox {
  12. var $socket;
  13. var $ex = array();
  14. function __construct()
  15. {
  16. global $config;
  17. $this->connect();
  18. $this->sql_connect();
  19. $this->b = "\002";
  20. $this->o = "\002";
  21. $this->main();
  22. }
  23. function main()
  24. {
  25. global $config;
  26. while (true)
  27. {
  28. $this->date = date("n j Y g i s a");
  29. if (!$this->socket || !$this->mysql) {
  30. die("Fail server or fail mysql\r\n");
  31. }
  32. $data = fgets($this->socket, 4096);
  33. echo("[~R] ".$data);
  34. flush();
  35. $this->ex = explode(' ', $data);
  36. foreach ($this->ex as &$trim)
  37. {
  38. $trim = trim($trim);
  39. }
  40. if ($this->ex[0] == 'PING')
  41. {
  42. $this->send_data('PONG', $this->ex[1]);
  43. }
  44. if ($this->ex[1] == '376' || $this->ex[1] == '422')
  45. {
  46. $this->idandjoin();
  47. }
  48. // PRIVMSG ~~~~~~~~~~~~
  49. if ($this->ex[1] == 'PRIVMSG') {
  50. preg_match("/^:(.*?)!(.*?)@(.*?)[\s](.*?)[\s](.*?)[\s]:(.*?)$/", $data, $rawdata);
  51. $this->nick[$data] = $rawdata[1];
  52. $this->ident[$data] = $rawdata[2];
  53. $this->host[$data] = $rawdata[3];
  54. $this->h[$this->nick[$data]] = $this->host[$data];
  55. $msg_type[$data] = $rawdata[4];
  56. $this->channel[$data] = $rawdata[5];
  57. $this->args[$data] = trim($rawdata[6]);
  58. if (!$this->ignore[$this->h[$this->nick[$data]]]) {
  59. if (strtolower($this->ex[3]) == ":.ignore") {
  60. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  61. if ($this->ex[4]) {
  62. if ($this->h[$this->ex[4]]) {
  63. $this->ignore[$this->h[$this->ex[4]]] = true;
  64. $this->privmsg($this->channel[$data], $this->b."*!*@".$this->h[$this->ex[4]].$this->o." was added to the ignore list.");
  65. } else { $this->privmsg($this->channel[$data], "I do not recognize ".$this->b.$this->ex[4].$this->o."."); }
  66. } else { $this->notice($this->nick[$data], "Incorrect syntax. ".$this->b.".ignore <nick>"); }
  67. } else { $this->notice($this->nick[$data], "You are not a fox admin."); }
  68. }
  69. elseif (strtolower($this->ex[3]) == ":.unignore") {
  70. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  71. if ($this->ex[4]) {
  72. if ($this->h[$this->ex[4]]) {
  73. unset($this->ignore[$this->h[$this->ex[4]]]);
  74. $this->privmsg($this->channel[$data], $this->b."*!*@".$this->h[$this->ex[4]].$this->o." was removed from the ignore list.");
  75. } else { $this->privmsg($this->channel[$data], "I do not recognize ".$this->b.$this->ex[4].$this->o."."); }
  76. } else { $this->notice($this->nick[$data], "Incorrect syntax. ".$this->b.".ignore <nick>"); }
  77. } else { $this->notice($this->nick[$data], "You are not a fox admin."); }
  78. }
  79. elseif (strtolower($this->ex[3]) == ":.assign") {
  80. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  81. if ($this->ex[4]) {
  82. $this->assign(trim($this->ex[4]), $this->channel[$data], $this->nick[$data]);
  83. } else { $this->notice($this->nick[$data], "Incorrect syntax. ".$this->b.".assign <channel>"); }
  84. }
  85. else { $this->notice($this->nick[$data], "You are not a fox admin."); }
  86. }
  87. elseif (strtolower($this->ex[3]) == ":.unassign") {
  88. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  89. if ($this->ex[4]) {
  90. $this->unassign(trim($this->ex[4]), $this->channel[$data], $this->nick[$data]);
  91. } else { $this->notice($this->nick[$data], "Incorrect syntax. ".$this->b.".unassign <channel>"); }
  92. }
  93. else { $this->notice($this->nick[$data], "You are not a fox admin."); }
  94. }
  95. elseif (strtolower($this->ex[3]) == ":.clear") {
  96. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  97. if ($this->ex[4] == "quotes") {
  98. mysql_query("delete from quotes");
  99. $this->privmsg($this->channel[$data], "All quotes have been deleted.");
  100. } elseif ($this->ex[4] == "pics") {
  101. mysql_query("delete from pics");
  102. $this->privmsg($this->channel[$data], "All pictures have been deleted.");
  103. } else {
  104. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".clear quotes|pics");
  105. }
  106. } else { $this->notice($this->nick[$data], "You are not a fox admin."); }
  107. }
  108. elseif (strtolower($this->ex[3]) == ":.eval") {
  109. if (strtolower($this->host[$data]) == strtolower($config->ownerhost)) {
  110. $eval = substr($this->args[$data], 6);
  111. $this->notice($this->nick[$data], $this->b."[Eval] ".$this->o.$eval);
  112. eval($eval);
  113. }
  114. }
  115. elseif (strtolower($this->ex[3]) == ":.help") {
  116. $this->privmsg($this->channel[$data], ".add <command> <response>".$this->b." | ".$this->o.".del <command>".$this->b." | ".$this->o.".info <command>".$this->b." | ".$this->o.".amnt".$this->b." | ".$this->o.".addme <command> <response>".$this->b." | ".$this->o.".addact <command> <response>".$this->b." | ".$this->o.".infoact <command>".$this->b." | ".$this->o.".addactme <command> <response>".$this->b." | ".$this->o.".delact <command>".$this->b." | ".$this->o.".q add|del|<id>"); $this->privmsg($this->channel[$data], ".pic add|del|<id>".$this->b." | ".$this->o.".eval <eval>".$this->b." | ".$this->o.".ignore <nick>".$this->b." | ".$this->o.".unignore <nick>".$this->b." | ".$this->o.".clear pics|quotes".$this->b." | ".$this->o.".assign <channel>".$this->b." | ".$this->o.".unassign <channel>".$this->b." | ".$this->o.".addwild <command> <response>".$this->b." | ".$this->o.".addwildme <command> <response>");
  117. }
  118. elseif (strtolower($this->ex[3]) == ":.invite") {
  119. if ($this->ex[4]) {
  120. $this->send_data("INVITE ".$this->ex[4]." ".$this->channel[$data]);
  121. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".invite <nick>."); }
  122. }
  123. elseif (strtolower($this->ex[3]) == ":.amnt") {
  124. $q = mysql_query("SELECT * FROM commands WHERE channel='".$this->channel[$data]."'");
  125. $num = mysql_num_rows($q);
  126. $this->privmsg($this->channel[$data], "I respond to ".$this->b.$num.$this->o." commands in ".$this->b.$this->channel[$data].$this->o.".");
  127. }
  128. elseif (strtolower($this->ex[3]) == ":.addact") {
  129. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  130. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", "\001ACTION ".addslashes($this->ex[4])."\001");
  131. if ($check) {
  132. if (!$check2['command']) {
  133. if ($this->ex[4] && $this->ex[5]) {
  134. $this->command[$data] = $this->ex[4];
  135. $this->command[$data] = str_replace("[]", " ", $this->command[$data]);
  136. $this->response[$data] = substr($this->args[$data], 9+strlen($this->ex[4]));
  137. $this->privmsg($this->channel[$data], "If someone acts \"".$this->b.$this->command[$data].$this->o."\", I will now respond with \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  138. $this->response[$data] = addslashes($this->response[$data]);
  139. $this->command[$data] = addslashes("\001ACTION ".$this->command[$data]."\001");
  140. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".addslashes($this->channel[$data])."','".$this->nick[$data]."','".$this->date."','false','false'");
  141. }
  142. else {
  143. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  144. }
  145. }
  146. else {
  147. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  148. }
  149. }
  150. else {
  151. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  152. }
  153. }
  154. elseif (strtolower($this->ex[3]) == ":.addactme") {
  155. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  156. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", "\001ACTION ".addslashes($this->ex[4])."\001");
  157. if ($check) {
  158. if (!$check2['command']) {
  159. if ($this->ex[4] && $this->ex[5]) {
  160. $this->command[$data] = $this->ex[4];
  161. $this->command[$data] = str_replace("[]", " ", $this->command[$data]);
  162. $this->response[$data] = substr($this->args[$data], 11+strlen($this->ex[4]));
  163. $this->privmsg($this->channel[$data], "If someone acts \"".$this->b.$this->command[$data].$this->o."\", I will now respond with the action \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  164. $this->response[$data] = addslashes("\001ACTION ".$this->response[$data]."\001");
  165. $this->command[$data] = addslashes("\001ACTION ".$this->command[$data]."\001");
  166. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."','false','false'");
  167. }
  168. else {
  169. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  170. }
  171. }
  172. else {
  173. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  174. }
  175. }
  176. else {
  177. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  178. }
  179. }
  180. elseif (strtolower($this->ex[3]) == ":.add") {
  181. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  182. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->ex[4]));
  183. if ($check) {
  184. if (!$check2['command']) {
  185. if ($this->ex[4] && $this->ex[5]) {
  186. $this->command[$data] = $this->ex[4];
  187. $this->command[$data] = str_replace("[]", " ", $this->command[$data]);
  188. $this->response[$data] = substr($this->args[$data], 6+strlen($this->ex[4]));
  189. $this->privmsg($this->channel[$data], "If someone says \"".$this->b.$this->command[$data].$this->o."\", I will now respond with \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  190. $this->response[$data] = addslashes($this->response[$data]);
  191. $this->command[$data] = addslashes($this->command[$data]);
  192. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."','false','false'");
  193. }
  194. else {
  195. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  196. }
  197. }
  198. else {
  199. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  200. }
  201. }
  202. else {
  203. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  204. }
  205. }
  206. elseif (strtolower($this->ex[3]) == ":.addwild") {
  207. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  208. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->ex[4]));
  209. if ($check) {
  210. if (!$check2['command']) {
  211. if ($this->ex[4] && $this->ex[5]) {
  212. $this->command[$data] = $this->ex[4];
  213. $this->response[$data] = substr($this->args[$data], 10+strlen($this->ex[4]));
  214. $this->privmsg($this->channel[$data], "If someone says \"".$this->b.$this->command[$data].$this->o."\" anywhere in their message, I will now respond with \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  215. $this->response[$data] = addslashes($this->response[$data]);
  216. $this->command[$data] = addslashes($this->command[$data]);
  217. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."','true','false'");
  218. }
  219. else {
  220. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  221. }
  222. }
  223. else {
  224. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  225. }
  226. }
  227. else {
  228. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  229. }
  230. }
  231. elseif (strtolower($this->ex[3]) == ":.addwildme") {
  232. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  233. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->ex[4]));
  234. if ($check) {
  235. if (!$check2['command']) {
  236. if ($this->ex[4] && $this->ex[5]) {
  237. $this->command[$data] = $this->ex[4];
  238. $this->response[$data] = substr($this->args[$data], 12+strlen($this->ex[4]));
  239. $this->privmsg($this->channel[$data], "If someone says \"".$this->b.$this->command[$data].$this->o."\" anywhere in their message, I will now respond with the action \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  240. $this->response[$data] = addslashes($this->response[$data]);
  241. $this->command[$data] = addslashes($this->command[$data]);
  242. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."','true','true'");
  243. }
  244. else {
  245. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  246. }
  247. }
  248. else {
  249. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  250. }
  251. }
  252. else {
  253. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  254. }
  255. }
  256. elseif (strtolower($this->ex[3]) == ":.addme") {
  257. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  258. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->ex[4]));
  259. if ($check) {
  260. if (!$check2['command']) {
  261. if ($this->ex[4] && $this->ex[5]) {
  262. $this->command[$data] = $this->ex[4];
  263. $this->command[$data] = str_replace("[]", " ", $this->command[$data]);
  264. $this->response[$data] = substr($this->args[$data], 8+strlen($this->ex[4]));
  265. $this->privmsg($this->channel[$data], "If someone says \"".$this->b.$this->command[$data].$this->o."\", I will now respond with the action \"".$this->b.$this->response[$data].$this->o."\" in ".$this->b.$this->channel[$data].$this->o.".");
  266. $this->response[$data] = addslashes($this->response[$data]);
  267. $this->command[$data] = addslashes($this->command[$data]);
  268. $this->sql_insert("commands", "'".$this->command[$data]."','".$this->response[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."','false','true'");
  269. }
  270. else {
  271. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".add <command> <response>");
  272. }
  273. }
  274. else {
  275. $this->privmsg($this->channel[$data], "I already respond to that in ".$this->b.$this->channel[$data].$this->o.".");
  276. }
  277. }
  278. else {
  279. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database."); $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  280. }
  281. }
  282. elseif (strtolower($this->ex[3]) == ":.del") {
  283. $this->command[$data] = substr($this->args[$data], 5);
  284. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  285. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  286. if ($this->ex[4]) {
  287. if ($check) {
  288. if ($check2['command']) {
  289. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." was deleted from the ".$this->b.$this->channel[$data].$this->o." command list.");
  290. $this->sql_delete("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  291. }
  292. else {
  293. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." does not exist in ".$this->b.$this->channel[$data].$this->o.".");
  294. }
  295. }
  296. else {
  297. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  298. }
  299. }
  300. else {
  301. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".del <command>");
  302. }
  303. }
  304. elseif (strtolower($this->ex[3]) == ":.delact") {
  305. $this->command[$data] = substr($this->args[$data], 8);
  306. $this->command[$data] = "\001ACTION ".$this->command[$data]."\001";
  307. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  308. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  309. if ($this->ex[4]) {
  310. if ($check) {
  311. if ($check2['command']) {
  312. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." was deleted from the ".$this->b.$this->channel[$data].$this->o." command list.");
  313. $this->sql_delete("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  314. }
  315. else {
  316. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." does not exist in ".$this->b.$this->channel[$data].$this->o.".");
  317. }
  318. }
  319. else {
  320. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  321. }
  322. }
  323. else {
  324. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".del <command>");
  325. }
  326. }
  327. elseif (strtolower($this->ex[3]) == ":.info") {
  328. $this->command[$data] = substr($this->args[$data], 6);
  329. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  330. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  331. if ($this->ex[4]) {
  332. if ($check) {
  333. if ($check2['command']) {
  334. $this->command[$data] = addslashes($this->command[$data]);
  335. $c = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", $this->command[$data]);
  336. $this->privmsg($this->channel[$data], "Command = \"".$this->b.$c['command'].$this->o."\" | Response = \"".$this->b.$c['response'].$this->o."\" | Added by ".$this->b.$c['nick'].$this->o." on ".$this->b.$this->convert_date($c['date']));
  337. } else {
  338. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." does not exist in ".$this->b.$this->channel[$data].$this->o.".");
  339. }
  340. }
  341. else {
  342. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  343. }
  344. }
  345. else {
  346. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".info <command>");
  347. }
  348. }
  349. elseif (strtolower($this->ex[3]) == ":.infoact") {
  350. $this->command[$data] = substr($this->args[$data], 9);
  351. $this->command[$data] = "\001ACTION ".$this->command[$data]."\001";
  352. $check = $this->sql_get("channels", "channel", "channel", $this->channel[$data]);
  353. $check2 = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->command[$data]));
  354. if ($this->ex[4]) {
  355. if ($check) {
  356. if ($check2['command']) {
  357. $c = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", $this->command[$data]);
  358. $this->privmsg($this->channel[$data], "Command = \"".$this->b.$c['command'].$this->o."\" | Response = \"".$this->b.$c['response'].$this->o."\" | Added by ".$this->b.$c['nick'].$this->o." on ".$this->b.$this->convert_date($c['date']));
  359. } else {
  360. $this->privmsg($this->channel[$data], $this->b.$this->command[$data].$this->o." does not exist in ".$this->b.$this->channel[$data].$this->o.".");
  361. }
  362. }
  363. else {
  364. $this->privmsg($this->channel[$data], $this->b.$this->channel[$data].$this->o." is not in my database.");
  365. }
  366. }
  367. else {
  368. $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".infoact <command>");
  369. }
  370. }
  371. elseif (strtolower($this->ex[3]) == ":.q") {
  372. if (strtolower($this->ex[4]) == "add") {
  373. if ($this->ex[5]) {
  374. $this->quote[$data] = substr($this->args[$data], 7);
  375. $n = mysql_query("select * from quotes");
  376. $quoteid = mysql_num_rows($n);
  377. if (intval($quoteid) != 0) { $quoteid++; } else { $quoteid = 1; }
  378. $this->privmsg($this->channel[$data], $this->b."Added quote #".$quoteid."/".$quoteid.": ".$this->o.$this->quote[$data]);
  379. $quote[$data] = str_replace("", "", $quote[$data]);
  380. $quote[$data] = addslashes($quote[$data]);
  381. $this->sql_insert("quotes", "'".$quoteid."','".$this->quote[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."'");
  382. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".quote add <quote>"); }
  383. }
  384. elseif (strtolower($this->ex[4]) == "del") {
  385. if ($this->ex[5]) {
  386. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".quote del <quote id>"); }
  387. }
  388. elseif (strtolower($this->ex[4]) == "rand") {
  389. $this->quote_rand($this->channel[$data]);
  390. }
  391. elseif (strtolower($this->ex[4]) == "amnt") {
  392. $this->quote_amnt($this->channel[$data]);
  393. }
  394. else {
  395. if ($this->ex[4]) {
  396. $this->quote_view($this->ex[4], $this->channel[$data]);
  397. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".quote add|del|rand|amnt <quote>|<quote id>"); }
  398. }
  399. }
  400. elseif (strtolower($this->ex[3]) == ":.pic") {
  401. if (strtolower($this->ex[4]) == "add") {
  402. if ($this->ex[5]) {
  403. $this->pic[$data] = substr($this->args[$data], 9);
  404. $n = mysql_query("select * from pics");
  405. $picid = mysql_num_rows($n);
  406. if (intval($picid) != 0) { $picid++; } else { $picid = 1; }
  407. $this->privmsg($this->channel[$data], $this->b."Added picture #".$picid."/".$picid.": ".$this->o.$this->pic[$data]);
  408. $pic[$data] = addslashes($pic[$data]);
  409. $this->sql_insert("pics", "'".$picid."','".$this->pic[$data]."','".$this->channel[$data]."','".$this->nick[$data]."','".$this->date."'");
  410. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".pic add <pic>"); }
  411. }
  412. elseif (strtolower($this->ex[4]) == "del") {
  413. if ($this->ex[5]) {
  414. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".pic del <pic id>"); }
  415. }
  416. elseif (strtolower($this->ex[4]) == "rand") {
  417. $this->pic_rand($this->channel[$data]);
  418. }
  419. elseif (strtolower($this->ex[4]) == "amnt") {
  420. $this->pic_amnt($this->channel[$data]);
  421. }
  422. else {
  423. if ($this->ex[4]) {
  424. $this->pic_view($this->ex[4], $this->channel[$data]);
  425. } else { $this->privmsg($this->channel[$data], "Incorrect syntax. ".$this->b.".pic add|del|rand|amnt <pic>|<pic id>"); }
  426. }
  427. }
  428. else {
  429. $fetch = $this->sql_fetch("commands", "channel", $this->channel[$data], "command", addslashes($this->args[$data]));
  430. if ($fetch['response'] && $fetch['wild'] == "false") {
  431. $this->response[$data] = str_replace("\$nick", $this->nick[$data], $fetch['response']);
  432. $this->response[$data] = str_replace("\$capsnick", strtoupper($this->nick[$data]), $this->response[$data]);
  433. $this->response[$data] = str_replace("\$ident", $this->ident[$data], $this->response[$data]);
  434. $this->response[$data] = str_replace("\$host", $this->host[$data], $this->response[$data]);
  435. $this->response[$data] = str_replace("\$sexuality", $this->sexuality($this->nick[$data]), $this->response[$data]);
  436. $this->response[$data] = str_replace("\$lol", $this->lol(), $this->response[$data]);
  437. $this->response[$data] = str_replace("\$rand", rand(1,99), $this->response[$data]);
  438. if ($fetch['me'] == "true") {
  439. $this->privmsg($this->channel[$data], "\001ACTION ".$this->response[$data]."\001");
  440. }
  441. else {
  442. $this->response[$data] = str_replace(" \$line ", "\nPRIVMSG ".$this->channel[$data]." :", $this->response[$data]);
  443. $this->privmsg($this->channel[$data], $this->response[$data]);
  444. }
  445. }
  446. $ex = explode(" ", $this->args[$data]);
  447. foreach ($ex as $word) { $this->wild($word, $this->channel[$data], $this->nick[$data], $this->ident[$data], $this->host[$data]); }
  448. }
  449. $this->clear();
  450. }
  451. } // end privmsg
  452. }
  453. }
  454. // mysql functions
  455. function sql_connect () {
  456. global $config;
  457. $this->mysql = mysql_connect($config->mysql['address'], $config->mysql['user'], $config->mysql['password']);
  458. mysql_select_db($config->mysql['database']);
  459. }
  460. function sql_fetch ($table, $a, $b, $c, $d) {
  461. if ($a && $b && $c && $d) {
  462. $q = mysql_query("SELECT * FROM ".$table." WHERE ".$a."='".$b."' AND ".$c."='".$d."'");
  463. return mysql_fetch_assoc($q);
  464. }
  465. elseif ($a && $b && !$c && !$d) {
  466. $q = mysql_query("SELECT * FROM ".$table." WHERE ".$a."='".$b."'");
  467. return mysql_fetch_assoc($q);
  468. }
  469. }
  470. function sql_get ($table, $a, $b, $c) {
  471. $q = mysql_query("SELECT * FROM ".$table." WHERE ".$b."='".$c."'");
  472. $qr = mysql_fetch_assoc($q);
  473. return ($qr[$a]);
  474. }
  475. function sql_delete ($table, $a, $b, $c, $d) {
  476. if ($a && $b && $c && $d) {
  477. $q = mysql_query("DELETE FROM ".$table." WHERE ".$a."='".$b."' AND ".$c."='".$d."'");
  478. return mysql_fetch_assoc($q);
  479. }
  480. elseif ($a && $b && !$c && !$d) {
  481. $q = mysql_query("DELETE FROM ".$table." WHERE ".$a."='".$b."'");
  482. return mysql_fetch_assoc($q);
  483. }
  484. }
  485. function sql_insert ($table, $args) {
  486. mysql_query("INSERT INTO ".$table." VALUES (".$args.")");
  487. }
  488. // main functions
  489. function wild ($word, $channel, $nick, $ident, $host) {
  490. $check = mysql_query("SELECT * FROM commands WHERE channel='".$channel."' AND command='".$word."' AND wild='true'");
  491. $cr = mysql_fetch_assoc($check);
  492. if ($cr['response']) {
  493. $response = str_replace("\$nick", $nick, $cr['response']);
  494. $response = str_replace("\$capsnick", strtoupper($nick), $response);
  495. $response = str_replace("\$ident", $ident, $response);
  496. $response = str_replace("\$host", $host, $response);
  497. $response = str_replace("\$sexuality", $this->sexuality($nick), $response);
  498. $response = str_replace("\$lol", $this->lol(), $response);
  499. $response = str_replace("\$rand", rand(1,99), $response);
  500. if ($cr['me'] == "false") {
  501. $response = str_replace(" \$line ", "\nPRIVMSG ".$channel." :", $response);
  502. $this->privmsg($channel, $response);
  503. } else {
  504. $this->privmsg($channel, "\001ACTION ".$response."\001");
  505. }
  506. }
  507. }
  508. function assign ($channel, $rchannel, $nick) {
  509. global $config;
  510. $c = mysql_fetch_assoc(mysql_query("SELECT * FROM channels WHERE channel='".addslashes($channel)."' AND network='".addslashes($config->network)."'"));
  511. $check = str_split($channel);
  512. if ($check[0] == "#") {
  513. if (!$c['channel']) {
  514. $this->join($channel);
  515. $this->privmsg($rchannel, $this->b.$channel.$this->o." has been added to my database.");
  516. $this->sql_insert("channels", "'".$channel."','".$this->date."','".$nick."','".$config->network."'");
  517. } else { $this->privmsg($rchannel, $this->b.$channel.$this->o." is already in my database."); }
  518. } else { $this->privmsg($rchannel, $this->b.$channel.$this->o." is not a valid channel name."); }
  519. }
  520. function unassign ($channel, $rchannel, $nick) {
  521. global $config;
  522. $c = $this->sql_fetch("channels", "channel", $channel, "network", $config->network);
  523. $check = str_split($channel);
  524. if ($check[0] == "#") {
  525. if ($c) {
  526. $this->part($channel);
  527. $this->privmsg($rchannel, $this->b.$channel.$this->o." has been removed from my database.");
  528. $this->sql_delete("channels", "channel", $channel);
  529. $this->sql_delete("commands", "channel", $channel);
  530. } else { $this->privmsg($rchannel, $this->b.$channel.$this->o." is not in my database."); }
  531. } else { $this->privmsg($rchannel, $this->b.$channel.$this->o." is not a valid channel name."); }
  532. }
  533. function quote_view ($quote, $channel) {
  534. $n = mysql_query("select * from quotes");
  535. $totalquotes = mysql_num_rows($n);
  536. if (intval($quote) != 0) {
  537. $q = $this->sql_fetch("quotes", "id", $quote);
  538. if ($q['quote']) {
  539. $this->privmsg($channel, $this->b."Quote #".$quote."/".$totalquotes.": ".$this->o.$q['quote']);
  540. }
  541. else { $this->privmsg($channel, "Quote ".$this->b."#".$quote.$this->o." does not exist."); }
  542. } else { $this->privmsg($channel, "The quote ID must be an integer."); }
  543. }
  544. function quote_rand ($channel) {
  545. $n = mysql_query("select * from quotes");
  546. $num = mysql_num_rows($n);
  547. $quoteid = rand(1, $num);
  548. $this->quote_view($quoteid, $channel);
  549. }
  550. function quote_amnt ($channel) {
  551. $n = mysql_query("select * from quotes");
  552. $num = mysql_num_rows($n);
  553. $this->privmsg($channel, "There are ".$this->b.$num.$this->o." quotes in my database.");
  554. }
  555. function pic_view ($quote, $channel) {
  556. if (intval($quote) != 0) {
  557. $n = mysql_query("select * from pics");
  558. $totalquotes = mysql_num_rows($n);
  559. $q = $this->sql_fetch("pics", "id", $quote);
  560. if ($q['pic']) {
  561. $this->privmsg($channel, $this->b."Picture #".$quote."/".$totalquotes.": ".$this->o.$q['pic']);
  562. }
  563. else { $this->privmsg($channel, "Picture ".$this->b."#".$quote.$this->o." does not exist."); }
  564. } else { $this->privmsg($channel, "The picture ID must be an integer."); }
  565. }
  566. function pic_rand ($channel) {
  567. $n = mysql_query("select * from pics");
  568. $num = mysql_num_rows($n);
  569. $quoteid = rand(1, $num);
  570. $this->pic_view($quoteid, $channel);
  571. }
  572. function pic_amnt ($channel) {
  573. $n = mysql_query("select * from pics");
  574. $num = mysql_num_rows($n);
  575. $this->privmsg($channel, "There are ".$this->b.$num.$this->o." pictures in my database.");
  576. }
  577. function mode ($a, $b) {
  578. $this->send_data("MODE ".$a." ".$b);
  579. }
  580. function join ($channel, $password) {
  581. $this->send_data("JOIN :".$channel." ".$password);
  582. }
  583. function quit ($msg) {
  584. $this->send_data("QUIT :".$msg);
  585. }
  586. function part ($channel, $msg) {
  587. if ($msg) {
  588. $this->send_data("PART ".$channel." :".$msg);
  589. }
  590. else {
  591. $this->send_data("PART ".$channel);
  592. }
  593. }
  594. function privmsg($a, $b) {
  595. $this->send_data("PRIVMSG ".$a." :".$b);
  596. }
  597. function notice($a, $b) {
  598. $this->send_data("NOTICE ".$a." :".$b);
  599. }
  600. function convert_date ($date) {
  601. // month, day, year, hour, minute, second, am/pm
  602. $d = explode(" ", $date);
  603. $month = $d[0];
  604. if (intval($month) == 1) { $month = "January"; }
  605. elseif (intval($month) == 2) { $month = "February"; }
  606. elseif (intval($month) == 3) { $month = "March"; }
  607. elseif (intval($month) == 4) { $month = "April"; }
  608. elseif (intval($month) == 5) { $month = "May"; }
  609. elseif (intval($month) == 6) { $month = "June"; }
  610. elseif (intval($month) == 7) { $month = "July"; }
  611. elseif (intval($month) == 8) { $month = "August"; }
  612. elseif (intval($month) == 9) { $month = "September"; }
  613. elseif (intval($month) == 10) { $month = "October"; }
  614. elseif (intval($month) == 11) { $month = "November"; }
  615. elseif (intval($month) == 12) { $month = "December"; }
  616. else { $month = "N/A"; }
  617. $date = $month." ".$d[1].", ".$d[2]." at ".$d[3].":".$d[4].":".$d[5]." ".strtoupper($d[6]).$this->o.".";
  618. return $date;
  619. }
  620. function idandjoin () {
  621. global $config;
  622. $this->send_data("PRIVMSG NickServ :IDENTIFY ".$config->serv_nickpass);
  623. sleep(1);
  624. $q = mysql_query("SELECT * FROM channels WHERE network='".$config->network."'");
  625. $channels = null;
  626. $b = 0;
  627. while ($c = mysql_fetch_assoc($q)) {
  628. $this->join($c['channel']);
  629. if ($channels != null) { $channels = $channels.",".$c['channel']; }
  630. else { $channels = $c['channel']; }
  631. $b++;
  632. }
  633. $this->join($channels);
  634. }
  635. function clear () {
  636. unset($this->command);
  637. unset($this->quote);
  638. unset($this->response);
  639. unset($this->channel);
  640. unset($this->nick);
  641. unset($this->ident);
  642. unset($this->host);
  643. unset($this->args);
  644. }
  645. function connect () {
  646. global $config;
  647. $this->socket = fsockopen($config->server, $config->serv_port);
  648. $this->send_data("USER", $config->serv_ident." * * :".$config->serv_realname);
  649. $this->send_data("NICK", $config->serv_nick);
  650. }
  651. function send_data($cmd, $msg = null)
  652. {
  653. fputs($this->socket, trim($cmd.' '.$msg)."\r\n");
  654. echo("[~S] ".trim($cmd.' '.$msg)."\r\n");
  655. }
  656. // other functions
  657. function truncate ($string, $chan, $order = null) {
  658. global $MaxStrlen;
  659. if (strlen($string) > $MaxStrlen){
  660. $msg1 = substr($string, 0, $MaxStrlen);
  661. $end = strrpos($msg1, " ");
  662. if($order == 1){ $msg1 = "..." . substr(trim($msg1), 0, $end); } else { $msg1 = substr($msg1, 0, $end); }
  663. $msg2 = substr($string, $end);
  664. $this->privmsg($chan." :".$msg1);
  665. } else {
  666. $this->privmsg($chan." :".$string);
  667. }
  668. if (strlen($msg2) > $MaxStrlen){
  669. $this->Truncate($msg2, $chan, 1);
  670. } elseif (!empty($msg2)) {
  671. $this->privmsg($chan, "..." . trim($msg2));
  672. }
  673. }
  674. function sexuality ($nick) {
  675. $s = rand(1, 4);
  676. if ($s == 1) {
  677. return "straight";
  678. }
  679. elseif ($s == 2) {
  680. return "gay";
  681. }
  682. elseif ($s == 3) {
  683. return "lesbian";
  684. }
  685. elseif ($s == 4) {
  686. return "bi";
  687. }
  688. }
  689. function lol () {
  690. $s = rand(1, 6);
  691. if ($s == 1) {
  692. return "hoe";
  693. }
  694. elseif ($s == 2) {
  695. return "hooker";
  696. }
  697. elseif ($s == 3) {
  698. return "whore";
  699. }
  700. elseif ($s == 4) {
  701. return "bitch";
  702. }
  703. elseif ($s == 5) {
  704. return "slut";
  705. }
  706. elseif ($s == 6) {
  707. return "pimp";
  708. }
  709. }
  710. }
  711. $fox = new fox();
  712. ?>