S
stealthwang
I'm still very new to Python, after decideding to learn a true
programming language (rather then a scripting language, i like to think
i'm a intermediate PHP user). I decided for my first project I would
try to make a IRCbot. It would run on the commandline with a frontend
for commands such as "reconnect", "quit", "changeserver", etc. My
problem is while I have the bot to a state where it connects to the
server (with the use of IRCLib), I don't know how to have the frontend
interface with the program while the irc connection loop is in the
background. My thoughts are that I could have each of the loops running
on a diffrent thread while events watch the channel for the bots
commands (!op etc.). Only problem I have no idea on how to implement
these ideas or even if this is the right way to go about it. So I'm
asking if anyone has a good threading or event tutorial, or if they
would show me the basics in a post. I'm also asking if I should be
going about this problem in this fashion at all.
Thanks for any help,
lotmr
Code for the client (not including irclib):
-note: im using 'pass' as a placeholder for future IRC commands
-note2: the code in comments is an example of how I would like the
frontend to work in the end. (except without pausing the loop which is
what happens right now as it waits for input).
#!usr/bin/python
#Filename: NIRC Core
import sys
import irc
def giveop(user):
pass
def ip():
pass
def uptime():
pass
def auth(user,password,ip):
pass
def kill(user):
pass
def mute(user):
pass
def servertest():
pass
NIRC=irc.IRC_Object( )
conn=NIRC.new_connection( )
s = raw_input('Enter Start Command : ')
if s == 'quit':
quit()
if s == 'ircstart':
conn.nick='Nilzirc'
conn.ident='nilzirc'
conn.server=('irc.deltaanime.net', 6667)
conn.realname='Noobwrangler McNeal'
print 'Connection Started'
while 1:
NIRC.main_loop( )
# n = raw_input('Enter Bot Commands : ')
# if n == 'quit':
# break
print 'Ending IRC communication'
programming language (rather then a scripting language, i like to think
i'm a intermediate PHP user). I decided for my first project I would
try to make a IRCbot. It would run on the commandline with a frontend
for commands such as "reconnect", "quit", "changeserver", etc. My
problem is while I have the bot to a state where it connects to the
server (with the use of IRCLib), I don't know how to have the frontend
interface with the program while the irc connection loop is in the
background. My thoughts are that I could have each of the loops running
on a diffrent thread while events watch the channel for the bots
commands (!op etc.). Only problem I have no idea on how to implement
these ideas or even if this is the right way to go about it. So I'm
asking if anyone has a good threading or event tutorial, or if they
would show me the basics in a post. I'm also asking if I should be
going about this problem in this fashion at all.
Thanks for any help,
lotmr
Code for the client (not including irclib):
-note: im using 'pass' as a placeholder for future IRC commands
-note2: the code in comments is an example of how I would like the
frontend to work in the end. (except without pausing the loop which is
what happens right now as it waits for input).
#!usr/bin/python
#Filename: NIRC Core
import sys
import irc
def giveop(user):
pass
def ip():
pass
def uptime():
pass
def auth(user,password,ip):
pass
def kill(user):
pass
def mute(user):
pass
def servertest():
pass
NIRC=irc.IRC_Object( )
conn=NIRC.new_connection( )
s = raw_input('Enter Start Command : ')
if s == 'quit':
quit()
if s == 'ircstart':
conn.nick='Nilzirc'
conn.ident='nilzirc'
conn.server=('irc.deltaanime.net', 6667)
conn.realname='Noobwrangler McNeal'
print 'Connection Started'
while 1:
NIRC.main_loop( )
# n = raw_input('Enter Bot Commands : ')
# if n == 'quit':
# break
print 'Ending IRC communication'