Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
46f22770
Commit
46f22770
authored
Nov 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
irc bot example
parent
060784ad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
154 additions
and
0 deletions
+154
-0
Bot.php
tools/Bot.php
+154
-0
No files found.
tools/Bot.php
0 → 100644
View file @
46f22770
<?php
// Read Unix Time and put into a variable for uptime logging
$starttime
=
time
();
// Prevent PHP from stopping the script after 30 sec
set_time_limit
(
0
);
require_once
'../Doctrine/trunk/lib/Doctrine.php'
;
spl_autoload_register
(
array
(
'Doctrine'
,
'autoload'
));
class
DBot
{
protected
$_options
=
array
(
'server'
=>
'irc.freenode.net'
,
'port'
=>
6667
,
'username'
=>
'Doctrine'
,
'hostname'
=>
'phpdoctrine.net'
,
'servername'
=>
'Doctrine'
,
'realname'
=>
'Doctrine bot'
,
'nick'
=>
'Doctrine'
,
'channels'
=>
array
(
'#doctrine-test'
));
protected
$_socket
;
public
function
connect
()
{
// Open the socket to the IRC server
$this
->
_socket
=
fsockopen
(
$this
->
_options
[
'server'
],
$this
->
_options
[
'port'
]);
unlink
(
'log.txt'
);
sleep
(
1
);
Doctrine_Manager
::
connection
(
'sqlite::memory:'
);
// Send auth info
$this
->
execute
(
'USER '
.
$this
->
_options
[
'username'
]
.
' '
.
$this
->
_options
[
'hostname'
]
.
' '
.
$this
->
_options
[
'servername'
]
.
' :'
.
$this
->
_options
[
'realname'
]
.
"
\n
"
);
$this
->
execute
(
'NICK '
.
$this
->
_options
[
'nick'
]
.
"
\n
"
);
foreach
(
$this
->
_options
[
'channels'
]
as
$channel
)
{
$this
->
execute
(
'JOIN '
.
$channel
.
"
\n
"
);
}
}
public
function
execute
(
$command
)
{
fputs
(
$this
->
_socket
,
$command
);
$this
->
log
(
'>>> '
.
$command
);
}
public
function
log
(
$command
)
{
$fp
=
fopen
(
'log.txt'
,
'a+'
);
fwrite
(
$fp
,
$command
);
fclose
(
$fp
);
}
public
function
disconnect
()
{
$this
->
execute
(
'QUIT'
.
"
\n
"
);
fclose
(
$this
->
_socket
);
}
// IRC Functions [BEGIN]
// Joins channel
public
function
join
(
$channel
)
{
$this
->
execute
(
'JOIN '
.
$channel
.
"
\r\n
"
);
}
// Leaves the channel
public
function
part
(
$channel
){
$this
->
execute
(
'PART '
.
$channel
.
"
\r\n
"
);
}
// send message to channel/user
public
function
say
(
$to
,
$msg
){
$this
->
execute
(
'PRIVMSG '
.
$to
.
' :'
.
$msg
.
"
\r\n
"
);
}
// modes: +o, -o, +v, -v, etc.
public
function
setMode
(
$user
,
$mode
){
$this
->
execute
(
'MODE '
.
$this
->
channel
.
' '
.
$mode
.
' '
.
$user
.
"
\r\n
"
);
}
// kicks user from the channel
public
function
kick
(
$user
,
$from
,
$reason
=
""
)
{
$this
->
execute
(
'KICK '
.
$from
.
' '
.
$user
.
' :'
.
$reason
.
"
\r\n
"
);
}
// changes the channel topic
public
function
topic
(
$channel
,
$topic
)
{
$this
->
execute
(
'TOPIC '
.
$channel
.
' :'
.
$topic
.
"
\r\n
"
);
}
public
function
run
()
{
$this
->
connect
();
// Force an endless while
while
(
!
feof
(
$this
->
_socket
))
{
// Continue the rest of the script here
$data
=
fgets
(
$this
->
_socket
,
4096
);
print
$data
.
"<br>"
;
// Separate all data
$ex
=
explode
(
' '
,
$data
);
// Send PONG back to the server
if
(
$ex
[
0
]
==
'PING'
)
{
$this
->
execute
(
'PONG '
.
$ex
[
1
]
.
"
\n
"
);
}
//$this->log($data);
// Say something in the channel
$command
=
str_replace
(
array
(
chr
(
10
),
chr
(
13
)),
''
,
$ex
[
3
]);
// strip out ':'
$command
=
substr
(
$command
,
1
);
array_shift
(
$ex
);
array_shift
(
$ex
);
$scope
=
array_shift
(
$ex
);
array_shift
(
$ex
);
$argsStr
=
implode
(
' '
,
$ex
);
//$this->log($command . ' ' . $scope);
switch
(
$command
)
{
case
'!shutdown'
:
$this
->
disconnect
();
exit
;
break
;
case
'!native-expr'
:
$portableExpr
=
$ex
[
0
];
break
;
}
}
}
}
$bot
=
new
Dbot
();
$bot
->
run
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment