Government Security
Network Security Resources

Jump to content

Photo

Python IRC bot help...

- - - - - network python
  • Please log in to reply
4 replies to this topic

#1 fellixombc

fellixombc

    Private

  • Members
  • 1 posts

Posted 11 June 2009 - 12:50 PM

[list=1][*]import socket[*][*]## IRC Details, change these[*]irc_network = 'irc.moparisthebest.com'[*]bot_owner = 'fellix_bot'[*]irc_channel = '#bots'[*]irc_port = 6667[*][*]irc_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)[*]irc_sock.connect((irc_network, irc_port))[*][*]irc_sock.send('NICK Testbot1\r\n')[*]irc_sock.send('User Test Test Test :Python\r\n')[*]irc_sock.send('PRIVMSG :MSG NickServ IDENTIFY password\r\n')[*]irc_sock.send('JOIN ' + irc_channel +'\r\n')[*][*]while True:[*]		irc_data = str(irc_sock.recv(1024))[*][*]		print irc_data[*]		if irc_data.find('!hi') and irc_data[irc_data.find(':') + 1:irc_data.find('!')] == bot_owner:[*]				irc_sock.send('PRIVMSG ' + irc_channel + ' hi\r\n')[/list]

whenever i talk, it says after i did !hi, it will always say 'hi' to whatever i say. Help?

#2 webdevil

webdevil

    Retired GSO General

  • Sergeant Major
  • 1,195 posts

Posted 12 June 2009 - 04:14 AM

Align your code properly with the code tags.
A bit more explanation on what you need...

#3 meathive

meathive

    Staff Sergeant

  • Sergeant Major
  • 254 posts

Posted 12 June 2009 - 06:48 AM

import socket

## IRC Details, change these
irc_network = 'irc.moparisthebest.com'
bot_owner = 'fellix_bot'
irc_channel = '#bots'
irc_port = 6667

irc_sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
irc_sock.connect( ( irc_network, irc_port ) )

irc_sock.send( 'NICK Testbot1\r\n' )
irc_sock.send( 'User Test Test Test :Python\r\n' )
irc_sock.send( 'PRIVMSG :MSG NickServ IDENTIFY password\r\n' )
irc_sock.send( 'JOIN ' + irc_channel +'\r\n' )

while True:
  irc_data = str( irc_sock.recv( 1024 ) )
  
  print irc_data
  if irc_data.find( '!hi' ) and irc_data[irc_data.find( ':' ) + 1:irc_data.find( '!' )] == bot_owner:
	irc_sock.send( 'PRIVMSG ' + irc_channel + ' hi\r\n' )

There's only one command written into the damned thing so far, dude. There could be other errors here that I don't see since I don't read Python
...oO oO oO kinqpinz.info Oo Oo Oo...
---------------------------------------------------------
# angelheaded hipsters
## burning for the ancient heavenly connection
### to the starry dynamo
#### in the machinery of night.

#4 bonarez

bonarez

    Retired GSO Second Lieutenant

  • Sergeant Major
  • 1,252 posts

Posted 12 June 2009 - 09:52 AM

wrote an irc bot once, looong time ago even before I joined here, was in TCL > don't read any python either..

anywayz:

if irc_data.find( '!hi' ) and irc_data[irc_data.find( ':' ) + 1:irc_data.find( '!' )] == bot_owner:
	irc_sock.send( 'PRIVMSG ' + irc_channel + ' hi\r\n' )

if input is not hi (! is not in a few languages, though I could be wrong cause it is between ' ') AND ( ":" concatenate "sender" is NOT (! again) == the bot owner
send "hi" newline

does pretty much what it's supposed to do imho

Give TCL a try if you like to write an IRC bot, or if you really like complex code write it in Malbolge

hxxp://www.tcl.tk/man/tcl8.5/tutorial/Tcl0.html
hxxp://en.wikipedia.org/wiki/Malbolge
"Ask the right question and you will receive the right answer. I'm just very sensitive about the right syntax"

Read the rules before you post

#5 SL4Y3R

SL4Y3R

    Private

  • Members
  • 10 posts

Posted 22 July 2009 - 03:55 PM

Absolutely no reason to use another language. Python is perfectly capable. PM me with your code.





Also tagged with one or more of these keywords: network, python