-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRoll.php
More file actions
29 lines (24 loc) · 873 Bytes
/
Roll.php
File metadata and controls
29 lines (24 loc) · 873 Bytes
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
<?php
namespace plugin;
use phqagent\plugin\PluginBase;
use phqagent\message\Message;
use phqagent\console\MainLogger;
class Roll extends PluginBase{
public function onLoad(){
MainLogger::info('roll骰子插件已加载!');
}
private function getRandom($arg){
$min = 1;
$max = is_numeric($arg) ? $arg < 1 ? 1 : $arg : 100;
return mt_rand($min, $max);
}
public function onMessageReceive(Message $message){
if(strstr($message->getContent(), '!roll')){
MainLogger::info($message->getUser()->getCard() . ' : ' . $message);
$arg = explode('!roll ', $message->getContent());
$arg = isset($arg[1]) ? $arg[1] : '';
$random = $this->getRandom($arg);
new Message($message, $message->getUser()->getCard() . " rolled $random point(s)", true);
}
}
}