def main(): if len(argv) < 3: print notify('!','r',"Usage: %s <name> <shakespeare_play(s)>"%argv[0]) print notify('i','y',"<name> - character name, 'will' for all chars") print notify('i','y',"<play(s)> - 1+ plays (on shakespeare.mit.edu)") exit(1) if not DOMAIN or ROOM_TYPE != 'MUC': print notify('!','r',"Error: Only MUC rooms are supported") exit(2) # use 'will' to grab all characters nick = argv[1] pages = (urlopen('http://shakespeare.mit.edu/%s/full.html'%play.lower()) \ for play in argv[2:]) jidname = getuser()+'@'+DOMAIN mucroombot.setup_localization() mk_bot = lambda: ShakespeareClient(JID(jidname),getpass(),pages,nick) while mucroombot.main(mk_bot): pass
stream = c.get_stream() if not stream: break act = stream.loop_iter(0.5) if not act: rr,_,_ = select([sys.stdin],[],[],0) if len(rr) == 0: c.idle() else: print "\r", # carriage return c.muc_state.send_message(rr[0].readline().rstrip()) #c.got_char(rr[0].read(1)) if len(sys.argv) == 1: nick = getuser() print notify('!','y',"Assuming you are %s\nIf this is wrong, pass your nick as the first parameter"%nick) else: nick = sys.argv[1] if ROOM_TYPE == 'MUC': jidname = nick+'@'+DOMAIN else: sys.exit(notify('!','r',"%s is not supported yet"%ROOM_TYPE)) while True: c = CLIClient(JID(jidname),getpass(),nick) print "Connecting..." c.connect() try: loop(c)
if not stream: break act = stream.loop_iter(0.5) if not act: rr, _, _ = select([sys.stdin], [], [], 0) if len(rr) == 0: c.idle() else: print "\r", # carriage return c.muc_state.send_message(rr[0].readline().rstrip()) #c.got_char(rr[0].read(1)) if len(sys.argv) == 1: nick = getuser() print notify( '!', 'y', "Assuming you are %s\nIf this is wrong, pass your nick as the first parameter" % nick) else: nick = sys.argv[1] if ROOM_TYPE == 'MUC': jidname = nick + '@' + DOMAIN else: sys.exit(notify('!', 'r', "%s is not supported yet" % ROOM_TYPE)) while True: c = CLIClient(JID(jidname), getpass(), nick) print "Connecting..." c.connect() try:
def message(self, stanza): body = stanza.get_body() frm = stanza.get_from().as_utf8().split('@')[0] if stanza.get_type() == "headline": return True print colorize('g', frm + ':'), body response = self.autorespond(body) return Message(to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=stanza.get_subject(), body=response) #end class if len(sys.argv) != 2: print notify('!', 'r', "Usage: %s <nick_to_clone>" % sys.argv[0]) sys.exit(1) nick = sys.argv[1] if ROOM_TYPE == 'MUC': jidname = nick + '@' + DOMAIN else: sys.exit(notify('!', 'r', "%s is not supported yet" % ROOM_TYPE)) jidname = getuser() + '@' + DOMAIN mucroombot.setup_localization() while mucroombot.main(lambda: CloneClient(JID(jidname), getpass(), nick)): pass # vi: sts=4 et sw=4
subject=stanza.get_subject(), body=response) class IrcEvalClient(ircbot.ChatClient): def room_msg(self, frm, msg): self.send(evalmsg(msg)) def priv_msg(self, frm, msg): self.send(evalmsg(msg), frm) #end class if len(sys.argv) != 2: print notify('!', 'r', "Usage: %s <language>" % sys.argv[0]) sys.exit(1) print notify( '!', 'y', "WARNING: this evalbot is NOT SECURE. Arbitrary code \ *will* be executed!") lang = sys.argv[1] BOT_NAME = lang + '_bot' def runpipe(exe, input_str): p = subprocess.Popen(exe, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
default=BOT_NAME, help='bot nickname, default=' + BOT_NAME) opts, args = op.parse_args() return opts def main_muc(opts): jid = JID(opts.username + '@' + DOMAIN) mkbot = lambda: MucClient(jid, getpass(), opts.nick, opts.log) while mucroombot.main(mkbot): pass def main_irc(opts): mkbot = lambda: IrcChatBot(opts.nick, log=opts.log) while ircbot.main(mkbot): pass if __name__ == '__main__': mucroombot.setup_localization() opts = parse_args() if ROOM_TYPE == 'MUC': main_muc(opts) elif ROOM_TYPE == 'IRC': main_irc(opts) else: print notify('!', 'r', "Invalid ROOM_TYPE: '%s'" % ROOM_TYPE) # vi: sts=4 et sw=4
if not 'DOMAIN' in globals() or not DOMAIN: op.error("Must supply a domain, edit 'config' to set up") op.add_option('-u', '--username', default=getuser(), help='default='+getuser()) op.add_option('-l', '--log', action='store_true', help='turn on logging') op.add_option('-n', '--nick', default=BOT_NAME, help='bot nickname, default='+BOT_NAME) opts, args = op.parse_args() return opts def main_muc(opts): jid = JID(opts.username+'@'+DOMAIN) mkbot = lambda: MucClient(jid, getpass(), opts.nick, opts.log) while mucroombot.main(mkbot): pass def main_irc(opts): mkbot = lambda: IrcChatBot(opts.nick, log=opts.log) while ircbot.main(mkbot): pass if __name__ == '__main__': mucroombot.setup_localization() opts = parse_args() if ROOM_TYPE == 'MUC': main_muc(opts) elif ROOM_TYPE == 'IRC': main_irc(opts) else: print notify('!','r',"Invalid ROOM_TYPE: '%s'"%ROOM_TYPE) # vi: sts=4 et sw=4
response = evalmsg(body) return Message(to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=stanza.get_subject(), body=response) class IrcEvalClient(ircbot.ChatClient): def room_msg(self,frm,msg): self.send(evalmsg(msg)) def priv_msg(self,frm,msg): self.send(evalmsg(msg),frm) #end class if len(sys.argv) != 2: print notify('!','r',"Usage: %s <language>"%sys.argv[0]) sys.exit(1) print notify('!','y',"WARNING: this evalbot is NOT SECURE. Arbitrary code \ *will* be executed!") lang = sys.argv[1] BOT_NAME = lang+'_bot' def runpipe(exe,input_str): p = subprocess.Popen(exe,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.STDOUT,shell=True) return p.communicate(input_str)[0].rstrip() def evalmsg(msg): m = re.match("%s(?:_bot)?[>:\-,]\s+(.+)"%lang,msg) if not m: return
if stanza.get_type() == "headline": return True print colorize("g", frm + ":"), body response = self.autorespond(body) return Message( to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=stanza.get_subject(), body=response, ) # end class if len(sys.argv) != 2: print notify("!", "r", "Usage: %s <nick_to_clone>" % sys.argv[0]) sys.exit(1) nick = sys.argv[1] if ROOM_TYPE == "MUC": jidname = nick + "@" + DOMAIN else: sys.exit(notify("!", "r", "%s is not supported yet" % ROOM_TYPE)) jidname = getuser() + "@" + DOMAIN mucroombot.setup_localization() while mucroombot.main(lambda: CloneClient(JID(jidname), getpass(), nick)): pass # vi: sts=4 et sw=4