This repository was archived by the owner on Feb 9, 2018. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathPlugIRC_Core.php
More file actions
109 lines (84 loc) · 2.82 KB
/
Copy pathPlugIRC_Core.php
File metadata and controls
109 lines (84 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
class PlugIRC_Core{
const PLUGIN_NAME = "Untitled.";
const PLUGIN_VERSION = '1.0';
const PLUGIN_DESC = "No description set.";
// Added for Help plugin.
protected $requireConfig = false;
protected $AigisIRC;
protected $ConnIRC;
protected $PlugIRC;
protected $UserIRC = null;
protected $triggers = array();
protected $prefixes = array();
protected $configFile = array();
public function __construct(AigisIRC $AigisIRC){
$this->AigisIRC = $AigisIRC;
$this->ConnIRC = $AigisIRC->getAigisVar("ConnIRC");
$this->PlugIRC = $AigisIRC->getAigisVar("PlugIRC");
$this->UserIRC = $AigisIRC->getAigisVar("UserIRC");
$this->prefixes = $this->PlugIRC->getDefaultPrefixes();
$this->loadConfig();
}
public function triggerParse(MessIRC $MessIRC){
if(!$MessIRC->parseCommand($this->prefixes)) return;
$triggers = $this->triggers;
$command = strtolower($MessIRC->command());
if($help = $this->PlugIRC->getPlugin("Help")){
$full = $help->getFullCommand($command);
if($this->PlugIRC->getPermission($MessIRC, "command.$full") !== 2)
return;
}
if(isset($triggers[$command]) and method_exists($this, $triggers[$command])){
try{
call_user_func(array($this, $triggers[$command]), $MessIRC);
}catch(Exception $e){
$this->exceptionParse($e, $MessIRC);
}
}
}
public function exceptionParse(Exception $e, MessIRC $MessIRC){
$reply = $e->getMessage();
if(preg_match('/^([^:]+)::([^:]+): (.+)/', $reply, $match))
$reply = $match[3];
if($reply == "")
return;
if(get_class($e) == "NoticeException")
$this->ConnIRC->notice($MessIRC->getNick(), $reply);
else{
if($MessIRC->inChannel())
$reply = $MessIRC->getNick() . ": " . $reply;
$this->ConnIRC->msg($MessIRC->getReplyTarget(), $reply);
}
}
protected function loadConfig(){
// ~/.config file
$confile = PLUGIRC_HOMECFG.'/'.get_class($this).'.ini';
if(file_exists($confile))
$this->configFile = parse_ini_file($confile, true);
// Hardcoded config file.
elseif(file_exists(PLUGIRC_CONFIG.'/'.get_class($this).'.ini'))
$this->configFile = parse_ini_file(PLUGIRC_CONFIG.'/'.get_class($this).'.ini', true);
// Throw exception if config file required.
elseif($this->requireConfig == TRUE)
throw new Exception("Config file is needed!");
}
public function getPrefixes(){
return $this->prefixes;
}
public function consoleSend($message, $type = 'info'){
consoleSend(get_class($this) . ": " . $message, "PlugIRC", $type);
}
public function privmsg(MessIRC $MessIRC){
$this->triggerParse($MessIRC);
}
public function raw(MessIRC $MessIRC) {}
public function ctcp(MessIRC $MessIRC) {}
public function notice(MessIRC $MessIRC) {}
public function error(MessIRC $MessIRC) {}
public function ping(MessIRC $MessIRC) {}
public function nick(MessIRC $MessIRC) {}
public function quit(MessIRC $MessIRC) {}
public function join(MessIRC $MessIRC) {}
public function part(MessIRC $MessIRC) {}
}