<pre>
"""
This is the basic framework for writing a robot in Python.
"""
# this will work with any mud - these settings are for one where it's OK to run bots and mess around.
from telnetlib import Telnet #see [
docs.python.org]
host = 'pearachute.net'
port = 9998
t = Telnet()
"""
This bit is sort of advanced, and you don't really have to understand it - but
what it does, is when you launch this script, you can pass it an extra argument,
and it will try to import that argument and run the strings from the mud through that.
that way, you can write different bots/characters without rewriting this every time! :)
"""
import sys
try:
_foo = __import__(sys.argv[1],globals(),locals(),['proc','triggers'])
proc = _foo.proc
triggers = _foo.triggers
except Exception, e:
print e,'\n','print-only:'
def MAGIC(tuple):
sys.stdout.write( tuple[2])
triggers = ['\r\n']
#this is a convenience, it hits enter at the end of lines
def write(msg):
if msg: t.write(msg + '\n')
def main():
t.open(host,port)
while True:
write( MAGIC( t.expect(triggers)))
if __name__=='__main__': main()
"""
MAGIC is the magic in this program. It takes the data coming from the mud
and can (optionally) return a string, which will be sent to the mud.
I'll explain more in part 2! WALDO THE WANDERBOT!
;p
"""
</pre>