-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroombot.php
146 lines (131 loc) · 4.08 KB
/
roombot.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* A simple betting bot
* Verison: 0.1
*
* Install:
* 0. Download and Install JAXL packege from the bloody "Google" here: http://code.google.com/p/jaxl/
* 1. Put this file into /usr/share/php/jaxl/app/betbot
* 2. run jaxl roombot.php
*
* How it works:
* 0.The bot is listening in a chat room for matching 'I bet [something]'
* 1.It saves this string into a file and notify the author for that action
* 2.!show shows all active bets
*
* Future releases:
* 0.The user should be able to read all bets and to take a part with '+' or '-'
* 1. Save the result into DB/WebPage/Wiki
* 2. We may use fakeDB or event NoSQL for saving the result
* 3. !beer - should bring me a beer :)
*
* Author: @bogomil <[email protected]>
*
* Contributor(s):
*
* LICENSE:
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2004 Sam Hocevar <[email protected]>
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*
*/
// initialize Jaxl instance
$jaxl = new JAXL(array(
'user' => '', //jabber username just username
'pass' => '', //plaintext password
'host' => '', //jabber host
'domain' => '', //jabber domain (or just leave it empty)
'port' => 5222 //port (5222 is default)
));
// Include the required components
jaxl_require(array(
'JAXL0085',
'JAXL0092',
'JAXL0203' ,
'JAXL0045'
), $jaxl);
//set some conf details
define('ROOM',"[email protected]/Bet waiter");
define('PATH',"/usr/share/php/jaxl/app/echobot/bets.txt");
class betbot {
function startStream()
{
global $jaxl;
$jaxl->startStream();
}
function doAuth($mechanism) {
global $jaxl;
switch(TRUE) {
case in_array("ANONYMOUS",$mechanism):
$jaxl->auth("ANONYMOUS");
break;
case in_array("DIGEST-MD5",$mechanism):
$jaxl->auth("DIGEST-MD5");
break;
case in_array("PLAIN",$mechanism):
$jaxl->auth("PLAIN");
break;
default:
die("No prefered auth method exists...");
break;
}
}
function postAuth()
{
global $jaxl;
//Join the Conference room
$jaxl->JAXL0045('joinRoom', $jaxl->jid, ROOM, 0, 'seconds');
}
function getMessage($payloads) {
global $jaxl;
foreach($payloads as $payload) {
if($payload['offline'] != JAXL0203::$ns
&& (!$payload['chatState'] || $payload['chatState'] = 'active')
) {
if(strlen($payload['body']) > 0) {
//Read the message and react
if(preg_match('/I bet/', $payload['body']))
{
$this->betEngine($payload['body']);
$from = explode('/',$payload['from']);
$jaxl->sendMessage($payload['from'], $from[1]." you are on",'','broadcast');
}
if(preg_match('/!show/',$payload['body']))
{
$f=file('/usr/share/php/jaxl/app/echobot/bets.txt');
for($i=0;$i<count($f);$i++)
{
$jaxl->sendMessage($payload['from'], $i.":".$f[$i],'','broadcast');
}
}
}
}
}
}
function betEngine($sentence)
{
$fp = fopen(PATH, "a+");
fwrite($fp, $sentence.'
');
fclose($fp);
}
function getPresence($payloads) {}
}
$betbot = new betbot();
// Add callbacks on various xmpp events (#4)
JAXLPlugin::add('jaxl_post_connect', array($betbot, 'startStream'));
JAXLPlugin::add('jaxl_get_auth_mech', array($betbot, 'doAuth'));
JAXLPlugin::add('jaxl_post_auth', array($betbot, 'postAuth'));
JAXLPlugin::add('jaxl_get_message', array($betbot, 'getMessage'));
JAXLPlugin::add('jaxl_get_presence', array($betbot, 'getPresence'));
?>