Dalexhd

Poke admins with pw

Aug 18th, 2018
547
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.98 KB | None | 0 0
  1. //Config
  2. 'poke_admins' => array
  3. (
  4.     'enabled' => true,
  5.     'admins_groups' => array(9,12,13), //important in `sinusbot` function
  6.     'ignored_groups' => array(),
  7.     'ignored_channels' => array(0),     //channels where bot doesn't poke admins
  8.     'show_client_link' => true,     //show client link ([url])
  9.     'info_to_admin' => 'pw',  //Info to client | 'poke' / 'pw' // <--Added this line
  10.     'with_command' => true,     //poke admins only after command !admin
  11.     'poke_once' => true,            //send one poke to admin (true) or more (false)
  12.     'poking_interval' => array('weeks' => 0,'days' => 0,'hours' => 0,'minutes' => 0,'seconds' => 15),   //Only if poke_once = true
  13. ),
  14.  
  15. //Function
  16. <?php
  17.     /********************************
  18.  
  19.     Author: Tymoteusz `Razor Meister` Bartnik
  20.  
  21.     Contact: [email protected]
  22.  
  23.     Function: poke_admins()
  24.  
  25.     ********************************/
  26.  
  27. class poke_admins
  28. {
  29.     public static $clear = 1;
  30.     private static $name;
  31.     private static $cfg;
  32.    
  33.     static public function construct($event_name)
  34.     {
  35.         global $cfg;
  36.         self::$cfg = $cfg[$event_name];
  37.         self::$name = $event_name;
  38.     }
  39.  
  40.     static public function reset_cache()
  41.     {
  42.         global $clients, $cache_client_poke;
  43.        
  44.         if($cache_client_poke == NULL)
  45.             return;
  46.  
  47.         foreach($clients as $client)
  48.             if(in_array($client['clid'], array_keys($cache_client_poke)) && $client['cid'] != $cache_client_poke[$client['clid']])
  49.                 unset($cache_client_poke[$client['clid']]);
  50.     }
  51.  
  52.     static private function admin_on_channel($cid, $admin_rangs)
  53.     {
  54.         global $clients, $cache_client_poke;
  55.  
  56.         foreach($clients as $client)
  57.             if($client['client_database_id'] != 1 && $client['cid'] == $cid)
  58.                 foreach(explode(",", $client['client_servergroups']) as $client_group) 
  59.                     if(in_array($client_group, $admin_rangs))
  60.                     {
  61.                         foreach($cache_client_poke as $cache_clid => $cache_cid)   
  62.                             if($cache_cid == $cid)
  63.                                 unset($cache_client_poke[$cache_clid]);
  64.  
  65.                         return true;   
  66.                     }  
  67.  
  68.         return false;
  69.     }
  70.  
  71.     static private function client_is_on_channel($cid, $cldbid)
  72.     {
  73.         global $clients, $cache_client_poke;
  74.  
  75.         foreach($clients as $client)
  76.         {
  77.             if($client['client_database_id'] != 1 && $client['cid'] == $cid)
  78.             {
  79.                 if($client['client_database_id'] == $cldbid)
  80.                 {
  81.                     foreach($cache_client_poke as $cache_clid => $cache_cid)   
  82.                         if($cache_cid == $cid)
  83.                             unset($cache_client_poke[$cache_clid]);
  84.  
  85.                     return true;   
  86.                 }  
  87.             }
  88.         }
  89.         return false;
  90.     }
  91.  
  92.     static public function main($client_info)
  93.     {
  94.         global $query, $server_info, $clients, $cache_client_poke, $language, $xbot, $logs_manager;
  95.  
  96.         $lang = $language['function']['poke_admins'];
  97.         $admins = array();
  98.  
  99.         if(self::$cfg['kick_if_away'])
  100.         {
  101.             $msg = "";
  102.            
  103.             if($client_info['client_away'])
  104.                 $msg = $lang['away'];
  105.             elseif($client_info['client_input_muted'])
  106.                 $msg = $lang['input'];
  107.             elseif($client_info['client_output_muted'])
  108.                 $msg = $lang['output'];
  109.            
  110.             if($msg != "")
  111.             {
  112.                 $query->clientPoke($client_info['clid'], $msg);
  113.                 $query->clientKick($client_info['clid'], 'channel');
  114.                 return;
  115.             }
  116.         }
  117.        
  118.         if($xbot::has_group($client_info['client_servergroups'], self::$cfg['ignored_group_if_on_channel']))
  119.             return;
  120.        
  121.         if(self::$cfg['inform_admin_once'] && isset($cache_client_poke[$client_info['clid']]) && $cache_client_poke[$client_info['clid']] == $client_info['cid'])
  122.             return;
  123.        
  124.         foreach(self::$cfg['info'] as $channel => $admins_group)
  125.         {
  126.             if($client_info['cid'] == $channel)
  127.             {
  128.                 if(gettype($admins_group) == 'array' && !self::admin_on_channel($channel, $admins_group))
  129.                 {
  130.                     $count = 0;
  131.                     foreach($admins_group as $admin_group)
  132.                     {
  133.                         $clients_from_group = $query->serverGroupClientList($admin_group);
  134.                        
  135.                         if(!$clients_from_group['success'])
  136.                         {
  137.                             $logs_manager::set_error("#Gr1:".$admin_group, self::$name);
  138.                             continue;
  139.                         }
  140.                         else
  141.                             $clients_from_group = $clients_from_group['data'];
  142.  
  143.                         foreach($clients_from_group as $client_from_group)
  144.                         {
  145.                             if(isset($client_from_group['cldbid']) && $client_from_group['cldbid'] != 1)
  146.                             {
  147.                                 foreach($clients as $client)
  148.                                 {
  149.                                     if($client['client_database_id'] != 1 && $client['client_database_id'] == $client_from_group['cldbid'] && !$xbot::has_group($client['client_servergroups'], self::$cfg['ignored_groups']))
  150.                                     {
  151.                                         $count++;
  152.                                         array_push($admins, array('name' => $client['client_nickname']));
  153.                                         if(!in_array($client['cid'], self::$cfg['ignored_channels']))
  154.                                         {
  155.                                             if(self::$cfg['show_client_link'])
  156.                                             {
  157.                                                 if (self::$cfg['info_to_client'] == "poke") {
  158.                                                     $query->clientPoke($client['clid'], "[b][url=client://1/".$client_info['client_unique_identifier']."]".$client_info['client_nickname']."[/url][/b]");
  159.                                                     $query->clientPoke($client['clid'], "[color=red]".$lang['wants_help']."[/color]");
  160.                                                 }elseif (self::$cfg['info_to_client'] == "pw") {
  161.                                                     $query->sendMessage(1, $client['clid'], "[b][url=client://1/".$client_info['client_unique_identifier']."]".$client_info['client_nickname']."[/url][/b]");
  162.                                                     $query->sendMessage(1, $client['clid'], "[color=red]".$lang['wants_help']."[/color]");
  163.                                                 }
  164.                                             }
  165.                                             else
  166.                                             {
  167.                                                 $query->clientPoke($client['clid'], "[color=red][b]".$client_info['client_nickname']."[/b][/color] ".$lang['wants_help']);
  168.                                                 $query->sendMessage(1, $client['clid'], "[color=red][b]".$client_info['client_nickname']."[/b][/color] ".$lang['wants_help']);
  169.                                             }
  170.                                         }
  171.                                     }
  172.                                 }
  173.                             }
  174.                         }
  175.                     }
  176.                
  177.                     if($cache_client_poke == NULL || !array_key_exists($client_info['clid'], $cache_client_poke))
  178.                     {
  179.                         $message_for_client = "\n".$lang['hi']." [b]".$client_info['client_nickname']."[/b]\n";
  180.                         if($count > 0)
  181.                         {
  182.                             $message_for_client .= $lang['in_this_moment']."[b]".$count."[/b]\n";
  183.    
  184.                             foreach($admins as $admin)
  185.                                 $message_for_client .= "[u]".$admin['name']."[/u]\n";
  186.  
  187.                             $message_for_client .= "[color=green]".$lang['help']."[/color]";
  188.                         }
  189.                         else
  190.                             $message_for_client .= $lang['no_admins']." :)\n";
  191.  
  192.                         $query->sendMessage(1, $client_info['clid'], $message_for_client);
  193.                         $cache_client_poke[$client_info['clid']] = $client_info['cid'];
  194.                        
  195.                         $xbot::set_action(self::$name, array('client' => $client_info));
  196.                     }
  197.                 }
  198.                 elseif(gettype($admins_group) != 'array' && !self::client_is_on_channel($channel, $admins_group))
  199.                 {
  200.                     foreach($clients as $client)
  201.                         if($client['client_database_id'] == $admins_group && !$xbot::has_group($client['client_servergroups'], self::$cfg['ignored_groups']))
  202.                         {
  203.                             if(self::$cfg['show_client_link'])
  204.                             {
  205.                                 $query->clientPoke($client['clid'], "[b][url=client://1/".$client_info['client_unique_identifier']."]".$client_info['client_nickname']."[/url][/b]");
  206.                                 $query->clientPoke($client['clid'], "[color=red]".$lang['wants_help']."[/color]");
  207.                             }
  208.                             else
  209.                                 $query->clientPoke($client['clid'], "[color=red][b]".$client_info['client_nickname']."[/b][/color] ".$lang['wants_help']);
  210.  
  211.                             if(self::$cfg['informing_about_channel'])
  212.                             {
  213.                                 $channel = $query->getElement('data', $query->channelInfo($client_info['cid']));
  214.                                 $query->clientPoke($client['clid'],  $lang['on_channel']."[u][color=blue]".$channel['channel_name']."[/color][/u]");
  215.                             }
  216.  
  217.                             break;
  218.                         }
  219.  
  220.                     if($cache_client_poke == NULL || !array_key_exists($client_info['clid'], $cache_client_poke))
  221.                     {
  222.                         $message_for_client = "\n".$lang['hi']." [b]".$client_info['client_nickname']."[/b]\n";
  223.                         $message_for_client .= $client['client_nickname']." ".$lang['informed'];
  224.    
  225.                         $query->sendMessage(1, $client_info['clid'], $message_for_client);
  226.                         $cache_client_poke[$client_info['clid']] = $client_info['cid'];
  227.                        
  228.                         $xbot::set_action(self::$name, array('client' => $client_info));
  229.                     }
  230.                 }
  231.             }
  232.         }
  233.     }
  234. }
  235. ?>
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment