PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/utils/modes.php

http://phpbobot.googlecode.com/
PHP | 48 lines | 41 code | 7 blank | 0 comment | 18 complexity | eb6d7b982d37301c133e35f3a3b97ed4 MD5 | raw file
  1. <?php
  2. function modes($socket, $channel, $sender, $msg, $infos)
  3. {
  4. global $registered, $auth, $db, $users, $user_name, $translations;
  5. if((isset($registered[$sender]) && !$registered[$sender]) && (isset($auth[$sender]) && !$auth[$sender])) {
  6. sendmsg($socket, $translations->bot_gettext("utils-usernotallowed"), $channel); //"Tu vuoi cosa? Per fare che?"
  7. return;
  8. }
  9. $_users = explode(" ", $infos[1]);
  10. $userscount = count($_users);
  11. for($i = 0; $i < $userscount; $i++) {
  12. $user = $_users[$i];
  13. if(!preg_match("/\b([\+%&$~\@])*{$user}\b/", implode(" ", $users[$channel]))) {
  14. sendmsg($socket, sprintf($translations->bot_gettext("utils-usernotinchan-%s"), $user), $channel); //"$user non c'?ยจ!!"
  15. unset($_users[$i]);
  16. }
  17. }
  18. $_users = array_values($_users);
  19. $userscount = count($_users);
  20. if($userscount <= 0)
  21. return;
  22. $iduser = $db->check_user($sender);
  23. $idchan = $db->check_chan($channel);
  24. $result = $db->select(array("enter"), array("modes"), array(""), array("chan_IDChan", "user_IDUser"), array("=", "="), array($idchan, $iduser));
  25. if(preg_match("/^de/", $infos[0]))
  26. $mode = "-";
  27. else
  28. $mode = "+";
  29. if(preg_match("/halfop (.+)$/", $infos[0]) && (preg_match("/h|o/", $result[0]["modes"]) || getUserPrivileges($sender, $channel) <= UserLevels::HALFOP_LEVEL || is_bot_op($sender)))
  30. $mode .= str_repeat("h", $userscount);
  31. elseif(preg_match("/voice (.+)$/", $infos[0]) && preg_match("/v|h|o/", $result[0]["modes"] || is_bot_op($sender)))
  32. $mode .= str_repeat("v", $userscount);
  33. elseif(preg_match("/op (.+)/", $infos[0]) || getUserPrivileges($sender, $channel) <= UserLevels::OPER_LEVEL || is_bot_op($sender))
  34. $mode .= str_repeat("o", $userscount);
  35. if(strlen($mode) > 1) {
  36. send($socket, "MODE $channel $mode " . implode(" ", $_users) . "\n");
  37. } else {
  38. sendmsg($socket, $translations->bot_gettext("utils-usernotallowed"), $channel); //"Tu vuoi cosa? Per fare che?"
  39. }
  40. }
  41. ?>