Source

twistedbot / trtl.py

"""
            _____________________________________________
  ___      < trtl - TwistedBot REPL for Testing Libraries >_
 //_\\\\ _    ---------------------------------------------
/_|_|_('>  /
 "   "
"""
import os
import sys
import readline
import re
regex = re.compile("\x03(?:\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
sys.path.append("./modules/")

TO_LOAD = [filename[:-3] for dirname, dirnames, filenames in os.walk('./modules') for filename in filenames if filename[-3:] == ".py"]
MODULES = {}

from test.fake_tbot import TestedBot

TBOT = TestedBot()

for module in TO_LOAD:
    try:
        MODULES[module] = __import__(module)
        for function in dir(MODULES[module]):
            glob = MODULES[module].__dict__[function]
            if hasattr(glob, 'rule'):
                TBOT.register(glob)
    except:
        pass

USER = "[USER]"
CHANNEL = "[CHANNEL]"

print __doc__

while True:
    try:
        msg = raw_input("> ")
    except EOFError:
        print ""
        print "Bye!"
        sys.exit()
    except KeyboardInterrupt:
        print ""
        print "Bye!"
        sys.exit()
    if msg and msg[0] == "/":
        (command, value) = msg.split(" ", 1)
        if command == "/nick":
            USER = value
            print "(Nick has changed to '%s')" % USER
        elif command == "/j":
            CHANNEL = value
            print "(Channel has changed to '%s')" % CHANNEL
        else:
            print "(Not a recognised command)"
    else:
        TBOT.listen(USER, CHANNEL, msg)
        if [] != TBOT.bot_messages:
            print regex.sub('', "\n".join([x[1] for x in TBOT.bot_messages]))
            TBOT.bot_messages = []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.