/_acotes_/irc/phergie/Phergie/Plugin/Edgard.php

https://bitbucket.org/pombredanne/spip-zone-treemap · PHP · 159 lines · 109 code · 8 blank · 42 comment · 6 complexity · e6e30d7d884fc02038dba36bb715d788 MD5 · raw file

  1. <?php
  2. /**
  3. * Phergie
  4. *
  5. * PHP version 5
  6. *
  7. * LICENSE
  8. *
  9. * This source file is subject to the new BSD license that is bundled
  10. * with this package in the file LICENSE.
  11. * It is also available through the world-wide-web at this URL:
  12. * http://phergie.org/license
  13. *
  14. * @category Phergie
  15. * @package Phergie_Plugin_Daddy
  16. * @author Phergie Development Team <team@phergie.org>
  17. * @copyright 2008-2011 Phergie Development Team (http://phergie.org)
  18. * @license http://phergie.org/license New BSD License
  19. * @link http://pear.phergie.org/package/Phergie_Plugin_Daddy
  20. */
  21. /**
  22. * Simply responds to messages addressed to the bot that contain the phrase
  23. * "Who's your daddy?" and related variations.
  24. *
  25. * @category Phergie
  26. * @package Phergie_Plugin_Daddy
  27. * @author Phergie Development Team <team@phergie.org>
  28. * @license http://phergie.org/license New BSD License
  29. * @link http://pear.phergie.org/package/Phergie_Plugin_Daddy
  30. */
  31. class Phergie_Plugin_Edgard extends Phergie_Plugin_Abstract
  32. {
  33. public $datas = array();
  34. public $reloaded = false;
  35. /**
  36. * Charger les donnees du fichier texte
  37. *
  38. * @return void
  39. */
  40. public function onLoad()
  41. {
  42. $fp1 = file_get_contents("http://edgard.spip.net/spip.php?page=edgard&var_mode=recalcul");
  43. $fp2 = file_get_contents("http://edgard.spip.net/spip.php?page=mafaq&var_mode=recalcul");
  44. if ($fp1 AND $fp2)
  45. $this->reloaded = true;
  46. if ($fichier = fopen("/var/www/edgard.spip.net/public_html/tmp/edgard.txt", "r")) {
  47. while (!feof($fichier)) {
  48. $ligne = fgets($fichier);
  49. if (strlen($ligne)>2) {
  50. list($key, $value) = explode(';', $ligne);
  51. $this->datas[$key] = $value;
  52. }
  53. }
  54. fclose($fichier);
  55. }
  56. }
  57. /**
  58. * Checks messages for the question to which it should respond and sends a
  59. * response when appropriate
  60. *
  61. * @return void
  62. */
  63. public function onPrivmsg()
  64. {
  65. $config = $this->getConfig();
  66. $prefix = $config['command.prefix'];
  67. $event = $this->getEvent();
  68. $text = $event->getArgument(1);
  69. $target = $event->getNick();
  70. $source = $event->getSource();
  71. $trouve = false;
  72. //commençons par (^#\d{2,4}\b);http://core.spip.org/issues/
  73. $pattern = '/' . preg_quote($prefix) .
  74. '\#([0-9]+)/iAD';
  75. if (!$trouve AND preg_match($pattern, $text, $m)) {
  76. $msg = 'Ok ' . $target . " c'est par ici : http://core.spip.org/issues/" . $m[1];
  77. $this->doPrivmsg($source, $msg);
  78. $trouve = true;
  79. }
  80. // http://core.spip.org/projects/spip/repository/revisions/18395
  81. $pattern = '/' . preg_quote($prefix) .
  82. '^c([0-9]+)/iAD';
  83. if (!$trouve AND preg_match($pattern, $text, $m)) {
  84. $msg = 'Ok ' . $target . " le commit c'est par ici : http://core.spip.org/projects/spip/repository/revisions/" . $m[1];
  85. $this->doPrivmsg($source, $msg);
  86. $trouve = true;
  87. }
  88. // http://core.spip.org/projects/spip/repository/revisions/18395
  89. $pattern = '/' . preg_quote($prefix) .
  90. '^z([0-9]+)/iAD';
  91. if (!$trouve AND preg_match($pattern, $text, $m)) {
  92. $msg = 'Ok ' . $target . " le commit c'est par ici : http://zone.spip.org/trac/spip-zone/changeset/" . $m[1];
  93. $this->doPrivmsg($source, $msg);
  94. $trouve = true;
  95. }
  96. // @?
  97. $pattern = '/' . preg_quote($prefix) .
  98. '^@\?([^?]+)/iAD';
  99. if (!$trouve AND preg_match($pattern, $text, $m)) {
  100. $m[1] = urlencode(trim($m[1]));
  101. $msg = "Hop http://edgard.spip.net/questions/" . $m[1];
  102. $this->doPrivmsg($source, $msg);
  103. $trouve = true;
  104. }
  105. // @unzip toto
  106. $pattern = '/' . preg_quote($prefix) .
  107. '^@unzip ([^ ]+)/iAD';
  108. if (!$trouve AND preg_match($pattern, $text, $m)) {
  109. $msg = "Un zip ? http://zone.spip.org/trac/spip-zone/changeset/latest/$m[1]?old_path=/&format=zip ";
  110. $this->doPrivmsg($source, $msg);
  111. $trouve = true;
  112. }
  113. // @function()
  114. $pattern = '/' . preg_quote($prefix) .
  115. '^@([a-z0-9_]{3,})\(\)/iAD';
  116. if (!$trouve AND preg_match($pattern, $text, $m)) {
  117. $m[1] = urlencode(trim($m[1]));
  118. $msg = "Hop http://doc.spip.org/@" . $m[1] . " - Hop (sinon) http://doc.spip.org/spip.php?page=recherche&recherche=" . $m[1];
  119. $this->doPrivmsg($source, $msg);
  120. $trouve = true;
  121. }
  122. // chercher une entrée dans les datas du wiki
  123. if (!$trouve) {
  124. foreach ($this->datas as $key => $value) {
  125. $pattern = '~' . preg_quote($prefix) . $key . '~iAD';
  126. if (preg_match($pattern, $text, $m)) {
  127. $this->doPrivmsg($source, $value);
  128. $trouve = true;
  129. break;
  130. }
  131. }
  132. }
  133. // demande de reload ?
  134. $pattern = '/' . preg_quote($prefix) .
  135. '^Edgard:/iAD';
  136. if (!$trouve AND preg_match($pattern, $text, $m)) {
  137. $this->onLoad();
  138. if ($this->reloaded)
  139. $this->doPrivmsg($source, "Et voila je suis en phase avec moi");
  140. else
  141. $this->doPrivmsg($source, "Ah probleme au rechargement");
  142. }
  143. }
  144. }