forked from TorbenKoehn/php-irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
96 lines (65 loc) · 2.2 KB
/
index.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
<?php
ini_set( 'max_execution_time', 0 );
//Autoload bootstrap
set_include_path( implode( PATH_SEPARATOR, array(
__DIR__.'/library',
__DIR__.'/plugins',
get_include_path()
) ) );
spl_autoload_register( function( $class ) {
$path = str_replace( '\\', '/', $class ).'.php';
include $path;
return class_exists( $class, false );
});
//The real thing.
$bot = new Irc\Bot( 'TestBot', 'irc.devmonks.net' );
//When we started connecting
$bot->on( 'connecting', function() {
echo "Connecting...\n";
} )
//When we connected successfully (But didn't send the login yet!)
->on( 'connected', function() {
echo "Connected!\n";
} )
//When we send a message
->on( 'send', function( $e ) {
echo "Sending $e->message\n";
} )
//When we received a message
->on( 'message', function( $e ) {
echo "Received $e->message\n";
} )
//When we're authenticated and the server welcomes us
->on( 'welcome', function( $e, $bot ) {
//We list all the channels. This will trigger the 'list' event
$bot->listChannels();
} )
//This triggers once for the 'list' event
->once( 'list', function( $e, $bot ) {
//Once the 'list' event is triggered, join all channels that have been listed
$bot->join( array_keys( $e->list ) );
} )
//When WE joined a channel
->on( 'join:TestBot', function( $e, $bot ) {
$bot->chat( $e->channel, 'What\'s up?' );
} )
//When there was a 'NAMES' request (Retrieve channel user infos)
->on( 'names', function( $e, $bot ) { } )
//When someone writes in some channel
->on( 'chat', function( $e, $bot ) {
echo "CHAT($e->channel): $e->from: $e->text\n";
} )
//When someone writes us a PM
->on( 'pm', function( $e, $bot ) {
echo "PM($e->to): $e->from: $e->text\n";
} )
//When someone writes a notice
->on( 'notice', function( $e, $bot ) {
echo "NOTICE($e->to): $e->from: $e->text\n";
} )
//When we retrieved the server options
->on( 'options', function( $e, $bot ) {
echo "Received server options.\n";
} )
//Now finally connect that thing.
->connect();