-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
42 lines (28 loc) 路 860 Bytes
/
bot.php
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
<?php
require_once './config.php';
require_once 'core/Bot.php';
class PingBot extends Bot {
const DEBUG = true;
protected function beforeExecute () {
$this->log('Before execute.');
}
protected function handleNotification ($notification) {
if ($notification['type'] !== 'comment_mention')
return false;
$this->log('Handling a mention notif...');
$comment = $this->devRant->getComment($notification['comment_id']);
preg_match('/.*?@devNews(.*)/si', $comment['body'], $matches);
if (trim($matches[1]) === 'ping') {
$this->log('Replying to ping...');
$this->devRant->postComment($comment['rant_id'], 'Pong!');
} else {
$this->log('Invalid Comment.');
}
return true;
}
protected function afterExecute () {
$this->log('After execute.');
}
}
$bot = new PingBot(DEVRANT_USERNAME, DEVRANT_PASSWORD);
$bot->execute();