Created
September 20, 2013 12:44
-
-
Save msjyoo/6636915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
__PocketMine Plugin__ | |
name=ChatGuard | |
description=ChatGuard | |
version=1.1.0 | |
author=sekjun9878 | |
class=ChatGuard | |
apiversion=8,9,10,11,12,13,14 | |
*/ | |
class ChatGuard implements Plugin{ | |
private $api; | |
private $server; | |
private $config = array(); | |
public function __construct(ServerAPI $api, $server = false){ | |
$this->api = $api; | |
$server = ServerAPI::request(); | |
} | |
public function init(){ | |
$this->api->console->register("chatguard", "Chat Guard v1.0.0", array($this, "commandHandler")); | |
$this->api->addHandler("player.chat", array($this, "eventHandler"), 100); | |
$this->api->schedule(1200, array($this, "minuteSchedule"), array(), true); | |
$this->config['config'] = new Config($this->api->plugin->configPath($this)."config.yml", CONFIG_YAML, array( | |
"mode" => "comprehensive", | |
)); | |
$trim = explode("\n", Utils::curl_get("http://www.bannedwordlist.com/lists/swearWords.txt")); | |
$this->config['blockwords'] = array(); | |
foreach($trim as $p) | |
{ | |
$this->config['blockwords'][] = trim($p); | |
} | |
} | |
public function eventHandler($data, $event) | |
{ | |
switch($event) | |
{ | |
case "player.chat": | |
//$this->api->chat->send($data['player'], $this->attatchChatPrefix($data['player'], $data['message'])); | |
if($this->checkSpam($data['message'], "comprehensive") === true) | |
{ | |
$this->api->chat->send($data['player'], $data['message']); | |
} | |
else | |
{ | |
$data['player']->sendChat("[ChatGuard] Your chat message has been blocked."); | |
} | |
return false; | |
break; | |
} | |
} | |
private function checkSpam($string, $mode) | |
{ | |
if($mode == 'comprehensive') | |
{ | |
$string = preg_replace('/[^\da-z]/i', '', $string); | |
$string = preg_replace('/\s/', '', $string); | |
} | |
foreach($this->config['blockwords'] as $badword) | |
{ | |
if(strpos($string, $badword) !== false) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
public function minuteSchedule() | |
{ | |
//TODO:Add Stuff here | |
} | |
public function commandHandler($cmd, $params, $issuer, $alias){ | |
$output = ""; | |
if($cmd != "chatguard") | |
{ | |
$output .= "Called via wrong command. Exiting.."; | |
return $output; | |
} | |
if($issuer instanceof Player) | |
{ | |
$output .= "Command can only be run by console. Exiting..."; | |
return $output; | |
} | |
switch(array_shift($params)){ | |
} | |
return $output; | |
} | |
public function __destruct() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment