-
Notifications
You must be signed in to change notification settings - Fork 300
Mod Quick Reply to Private Message
Philip Nicolcev edited this page Nov 3, 2013
·
1 revision
This patch was provided by @shermdog https://github.com/shermdog for v0.8.6
I have added the function /r to reply to the last private message received.
As with most of my patches it's a little quick and dirty.
lib/class/CustomAJAXChat.php
function parseCustomCommands($text, $textParts) {
global $db_prefix;
case '/r':
if(count($textParts) == 1) {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error MissingText'
);
return true;
} else {
if($this->isAllowedToSendPrivateMessage()) {
$uid = $this->getUserID();
$sql = 'SELECT
userID, userName
FROM
'.$db_prefix.'ajaxchat_messages
WHERE
channel = '.$this->getPrivateMessageID($uid).'
AND NOT (userid = '.$uid.' OR userid = '.$this->getConfig('chatBotID').')
AND dateTime > DATE(NOW()-INTERVAL 4 HOUR)
ORDER BY
id
DESC
LIMIT 1;';
// Create a new SQL query:
$result = $this->db->sqlQuery($sql);
// Stop if an error occurs:
if($result->error()) {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error Database '.$result->getError()
);
return true;
}
if($result->numRows() > 0){
while($row = $result->fetch()) {
$userID = $row['userID'];
$userName = $row['userName'];
}
// Copy of private message to current User:
$this->insertCustomMessage(
$this->getUserID(),
$this->getUserName(),
$this->getUserRole(),
$this->getPrivateMessageID(),
'/privmsgto '.$userName.' '.implode(' ', array_slice($textParts, 1))
);
// Private message to requested User:
$this->insertCustomMessage(
$uid,
$this->getUserName(),
$this->getUserRole(),
$this->getPrivateMessageID($userID),
'/privmsg '.implode(' ', array_slice($textParts, 1))
);
return true;
}
else {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error MissingUserName'
);
return true;
}
}
else {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error PrivateMessageNotAllowed'
);
return true;
}
}
default:
return false;
}
}
js/chat.js - needed to update to retain style
assignFontColorToCommandMessage: function(text, textParts) {
switch(textParts[0]) {
case '/msg':
case '/describe':
if(textParts.length > 2) {
return textParts[0]+' '+textParts[1]+' '
+ '[color='+this.settings['fontColor']+']'
+ textParts.slice(2).join(' ')
+ '[/color]';
}
break;
case '/me':
case '/action':
if(textParts.length > 1) {
return textParts[0]+' '
+ '[color='+this.settings['fontColor']+']'
+ textParts.slice(1).join(' ')
+ '[/color]';
}
break;
case '/r':
if(textParts.length > 1) {
return textParts[0]+' '
+ '[color='+this.settings['fontColor']+']'
+ textParts.slice(1).join(' ')
+ '[/color]';
}
break;
}
return text;
},