mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Improve phabot handling of private messages
Summary: When private messaged, the bot responds via private message to the sender, instead of sending a private message to itself. Test Plan: Mentioned tasks in public channels and private messages. Reviewers: btrahan, jungejason Reviewed By: btrahan CC: aran, btrahan Maniphest Tasks: T274 Differential Revision: https://secure.phabricator.com/D1350
This commit is contained in:
parent
2a29a51080
commit
b9cac3bcd1
3 changed files with 51 additions and 16 deletions
|
@ -47,6 +47,10 @@ abstract class PhabricatorIRCHandler {
|
|||
return $this->bot->getConfig('conduit.uri').$path;
|
||||
}
|
||||
|
||||
final protected function isChannelName($name) {
|
||||
return (strpos($name, '#') === 0);
|
||||
}
|
||||
|
||||
abstract public function receiveMessage(PhabricatorIRCMessage $message);
|
||||
|
||||
public function runBackgroundTasks() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -33,8 +33,8 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
|
||||
switch ($message->getCommand()) {
|
||||
case 'PRIVMSG':
|
||||
$channel = $message->getChannel();
|
||||
if (!$channel) {
|
||||
$reply_to = $message->getReplyTo();
|
||||
if (!$reply_to) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -164,23 +164,37 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
|
||||
foreach ($output as $phid => $description) {
|
||||
|
||||
// Don't mention the same object more than once every 10 minutes, so
|
||||
// we avoid spamming the chat over and over again for discsussions of
|
||||
// a specific revision, for example.
|
||||
$quiet_until = idx($this->recentlyMentioned, $phid, 0) + (60 * 10);
|
||||
if (time() < $quiet_until) {
|
||||
continue;
|
||||
}
|
||||
$this->recentlyMentioned[$phid] = time();
|
||||
// Don't mention the same object more than once every 10 minutes
|
||||
// in public channels, so we avoid spamming the chat over and over
|
||||
// again for discsussions of a specific revision, for example. In
|
||||
// direct-to-bot chat, respond to every object reference.
|
||||
|
||||
$this->write('PRIVMSG', "{$channel} :{$description}");
|
||||
if ($this->isChannelName($reply_to)) {
|
||||
if (empty($this->recentlyMentioned[$reply_to])) {
|
||||
$this->recentlyMentioned[$reply_to] = array();
|
||||
}
|
||||
|
||||
$quiet_until = idx(
|
||||
$this->recentlyMentioned[$reply_to],
|
||||
$phid,
|
||||
0) + (60 * 10);
|
||||
|
||||
if (time() < $quiet_until) {
|
||||
// Remain quiet on this channel.
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->recentlyMentioned[$reply_to][$phid] = time();
|
||||
}
|
||||
|
||||
$this->write('PRIVMSG', "{$reply_to} :{$description}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function handleSymbols(PhabricatorIRCMessage $message) {
|
||||
$channel = $message->getChannel();
|
||||
$reply_to = $message->getReplyTo();
|
||||
$text = $message->getMessageText();
|
||||
|
||||
$matches = null;
|
||||
|
@ -209,7 +223,7 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
$response = "No symbol '{$symbol}' found anywhere.";
|
||||
}
|
||||
|
||||
$this->write('PRIVMSG', "{$channel} :{$response}");
|
||||
$this->write('PRIVMSG', "{$reply_to} :{$response}");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -40,7 +40,24 @@ final class PhabricatorIRCMessage {
|
|||
return $this->command;
|
||||
}
|
||||
|
||||
public function getChannel() {
|
||||
public function getReplyTo() {
|
||||
switch ($this->getCommand()) {
|
||||
case 'PRIVMSG':
|
||||
$target = $this->getTarget();
|
||||
if ($target[0] == '#') {
|
||||
return $target;
|
||||
}
|
||||
|
||||
$matches = null;
|
||||
if (preg_match('/^:([^!]+)!/', $this->sender, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getTarget() {
|
||||
switch ($this->getCommand()) {
|
||||
case 'PRIVMSG':
|
||||
$matches = null;
|
||||
|
|
Loading…
Reference in a new issue