By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

passing input to running loop

P: n/a
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'

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 27 Mar 2005 17:51:03 -0800, st*********@gmail.com
<st*********@gmail.com> wrote:
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.


I am not sure if you want to write the program completely from scratch.
If not, you could perhaps use the Twisted IRC module to do most of your work :)
http://twistedmatrix.com/documents/c...ocols.irc.html

Regards,
--
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.