From zothar at freenetproject.org Mon Feb 5 00:36:44 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 5 Feb 2007 00:36:44 +0000 (UTC) Subject: [Pyfreenet] r11678 - trunk/apps/pyFreenet Message-ID: <20070205003644.19EA120AFA1@emu.freenetproject.org> Author: zothar Date: 2007-02-05 00:36:43 +0000 (Mon, 05 Feb 2007) New Revision: 11678 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Add option to trade refs with humans only by private message. Change setup to not ask for a noderef url if configured to trade refs only with bots. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-02-04 17:05:24 UTC (rev 11677) +++ trunk/apps/pyFreenet/refbot.py 2007-02-05 00:36:43 UTC (rev 11678) @@ -39,7 +39,7 @@ ident = 'FreenetRefBot' -current_config_version = 2 +current_config_version = 3 obscenities = ["fuck", "cunt", "shit", "asshole", "fscking", "wank"] reactToObscenities = False @@ -133,7 +133,6 @@ # get local attribs self.nodenick = opts['usernick'] self.refs = opts['refs'] - self.refurl = opts['refurl'] if(self.config_version < 1 and (not opts.has_key('bot2bot') or (opts.has_key('bot2bot') and opts['bot2bot'] == 'y'))): self.setup_bot2bot( opts ) if(opts.has_key('bot2bot')): @@ -180,6 +179,20 @@ if(not self.bot2bot_trades_enabled and self.bot2bot_trades_only_enabled): print "bot2bot ref trading is disabled, but trading with other bots only is enabled. This does not make sense. Quitting." my_exit( 1 ); + if(self.config_version < 3 and (not opts.has_key('privmsg_only') or (opts.has_key('privmsg_only') and opts['privmsg_only'] == 'y'))): + self.setup_privmsg_only( opts ) + self.refurl = opts['refurl'] + if('' == self.refurl and not self.bot2bot_trades_only_enabled): + print "configured to trade with humans using a noderef url, but we don't know a noderef url. This does not make sense. Quitting." + my_exit( 1 ); + if(opts.has_key('privmsg_only')): + if( opts['privmsg_only'] == 'y' ): + self.privmsg_only_enabled = True + else: + self.privmsg_only_enabled = False + else: + self.privmsg_only_enabled = True + needToSave = True if(opts.has_key('ircchannel')): self.chan = opts['ircchannel'] else: @@ -323,6 +336,8 @@ self.api_options.append( "bot2bot_trades" ); if(self.bot2bot_trades_only_enabled): self.api_options.append( "bot2bot_trades_only" ); + if(self.privmsg_only_enabled): + self.api_options.append( "privmsg_only" ); #@-node:__init__ #@+node:setup @@ -332,6 +347,8 @@ opts = {} + opts['config_version'] = current_config_version + print print "** You will need to be sure to register your IRC nick with freenode" print "** so that someone else can't /msg your bot and shut it down" @@ -352,7 +369,6 @@ print "** register this password with freenode 'nickserv', and" print "** on subsequent runs, will identify with this password" opts['password'] = self.prompt("Enter a new password") - opts['refurl'] = self.prompt("URL of your noderef") opts['ircchannel'] = self.prompt("IRC channel to join", "#freenet-refs") opts['irchost'] = self.prompt("Hostname of IRC server", "irc.freenode.net") @@ -388,6 +404,11 @@ #self.setup_bot2bot_announce( opts ) **FIXME** Not implemented yet self.setup_bot2bot_trades( opts ) self.setup_bot2bot_trades_only( opts ) + if( 'y' != opts['bot2bot_trades_only'] ): + opts['refurl'] = self.prompt("URL of your noderef") + else: + opts['refurl'] = ''; + self.setup_privmsg_only( opts ) opts['greetinterval'] = 1800 opts['spaminterval'] = 7200 @@ -453,6 +474,21 @@ opts['bot2bot_trades_only'] = 'n'; #@-node:setup_bot2bot_trades_only + #@+node:setup_privmsg_only + def setup_privmsg_only(self, opts): + """ + """ + if( 'y' != opts['bot2bot_trades_only'] ): + while 1: + opts['privmsg_only'] = self.prompt("Should we only allow ref trades by private message?", "y") + opts['privmsg_only'] = opts['privmsg_only'].lower(); + if( opts['privmsg_only'] in [ 'y', 'n' ] ): + break; + print "Invalid option '%s' - must be 'y' for yes or 'n' for no" % opts['privmsg_only'] + else: + opts['privmsg_only'] = 'y'; + + #@-node:setup_privmsg_only #@+node:save def save(self): @@ -492,6 +528,10 @@ f.write(fmt % ("bot2bot_trades_only", repr('y'))) else: f.write(fmt % ("bot2bot_trades_only", repr('n'))) + if(self.privmsg_only_enabled): + f.write(fmt % ("privmsg_only", repr('y'))) + else: + f.write(fmt % ("privmsg_only", repr('n'))) f.close() @@ -637,13 +677,19 @@ if( self.bot2bot_trades_only_enabled ): self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to only trade with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot. (%d ref%s to go)" \ + "Hi, I'm %s's noderef swap bot. I'm configured to only trade with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot. (%d ref%s to go)" \ % ( self.nodenick, refs_to_go, refs_plural_str ) ) + elif( self.privmsg_only_enabled ): + self.privmsg( + self.channel, + "Hi, I'm %s's noderef swap bot. I'm configured to only trade refs with humans via private message (requires registering with nickserv, i.e. /ns register ). To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ + % ( self.nodenick, refs_to_go, refs_plural_str ) + ) else: self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ + "Hi, I'm %s's noderef swap bot. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ % ( self.nodenick, self.nick, refs_to_go, refs_plural_str ) ) if(self.greet_interval > 0 and not self.bot2bot_trades_only_enabled): @@ -1146,7 +1192,10 @@ if(cmd.startswith("http://")): if( self.bot.bot2bot_trades_only_enabled ): replyfunc("Sorry, I'm configured to only trade refs with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot.") - return True; + return True + if( self.bot.privmsg_only_enabled and not is_from_privmsg ): + replyfunc("Sorry, I'm configured to only trade refs using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") + return True if(cmd == self.bot.refurl): self.privmsg("error - already have my own ref <%s>" % (cmd)) return True @@ -1177,6 +1226,9 @@ if( self.bot.bot2bot_trades_only_enabled ): replyfunc("Sorry, I'm configured to only trade refs with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot.") return + if( self.bot.privmsg_only_enabled and not is_from_privmsg ): + replyfunc("Sorry, I'm configured to only trade refs using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") + return if len(args) != 1: self.privmsg( "Invalid argument count", @@ -1284,6 +1336,9 @@ if( self.bot.bot2bot_trades_only_enabled ): replyfunc("Sorry, I'm configured to only trade refs with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot.") return + if( self.bot.privmsg_only_enabled and not is_from_privmsg ): + replyfunc("Sorry, I'm configured to only trade refs using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") + return replyfunc("My ref is at %s" % self.bot.refurl) #@-node:cmd_getref @@ -1293,6 +1348,9 @@ if( self.bot.bot2bot_trades_only_enabled and not self.bot.bots.has_key( self.peernick )): replyfunc("Sorry, I'm configured to only trade refs with other bots. Send me the \"help\" command to learn how to run your own ref swapping bot.") return + if( self.bot.privmsg_only_enabled and not is_from_privmsg ): + replyfunc("Sorry, I'm configured to only trade refs using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") + return nodeRefKeys = self.bot.nodeRef.keys() nodeRefKeys.sort() # Spread out the lines of the ref so we don't trigger the babbler detector of a receiving refbot From zothar at freenetproject.org Fri Feb 9 23:42:12 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 9 Feb 2007 23:42:12 +0000 (UTC) Subject: [Pyfreenet] r11726 - trunk/apps/pyFreenet Message-ID: <20070209234212.F020D9BC21@emu.freenetproject.org> Author: zothar Date: 2007-02-09 23:42:11 +0000 (Fri, 09 Feb 2007) New Revision: 11726 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py Log: refbot: Log versions on startup. Explicitly flush the output when logging. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2007-02-09 23:39:04 UTC (rev 11725) +++ trunk/apps/pyFreenet/minibot.py 2007-02-09 23:42:11 UTC (rev 11726) @@ -942,7 +942,8 @@ #@-node:class PrivateChat #@+node:log def log(msg): - print "%s: %s" % (time.strftime("%Y%m%d-%H%M%S"), msg) + sys.stdout.write("%s: %s\n" % (time.strftime("%Y%m%d-%H%M%S"), msg)) + sys.stdout.flush() #@-node:log #@+node:main @@ -959,6 +960,7 @@ #@-node:main #@+node:my_exit def my_exit( exit_status ): + log("Closing program with an exit status of %s" % ( exit_status )) if( not has_platform_module or ( has_platform_module and "Windows" == platform.system())): raw_input( "Hit Enter or Return to continue..." ); sys.exit( exit_status ); Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-02-09 23:39:04 UTC (rev 11725) +++ trunk/apps/pyFreenet/refbot.py 2007-02-09 23:42:11 UTC (rev 11726) @@ -72,6 +72,8 @@ self.bots = {} self.botIdentities = {} + log("Starting refbot with the following file versions: refbot.py: r%s minibot.py: r%s fcp/node.py: r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision, fcp.FCPNode.svnRevision)) + # check that we've got an updated fcp/node.py try: fcpnodepy_revision = fcp.FCPNode.svnRevision; From zothar at freenetproject.org Sun Feb 25 14:57:27 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 25 Feb 2007 14:57:27 +0000 (UTC) Subject: [Pyfreenet] r11914 - trunk/apps/pyFreenet Message-ID: <20070225145727.3AE539BFEB@emu.freenetproject.org> Author: zothar Date: 2007-02-25 14:57:26 +0000 (Sun, 25 Feb 2007) New Revision: 11914 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Better fcp shutdown handling. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-02-25 13:52:00 UTC (rev 11913) +++ trunk/apps/pyFreenet/refbot.py 2007-02-25 14:57:26 UTC (rev 11914) @@ -1597,7 +1597,8 @@ except Exception, msg: self.status = -3 self.error_msg = msg - f.shutdown(); + if(f != None): + f.shutdown(); return try: @@ -1624,7 +1625,6 @@ note_text = "%s bot2bot traded via refbot.py with %s@%s at %s" % ( ref_fieldset[ "myName" ], self.sender_irc_nick, self.irc_host, time.strftime( "%Y%m%d-%H%M%S", time.localtime() ) ) encoded_note_text = base64.encodestring( note_text ).replace( "\r", "" ).replace( "\n", "" ); f.modifypeernote( NodeIdentifier = ref_fieldset[ "identity" ], PeerNoteType = fcp.node.PEER_NOTE_PRIVATE_DARKNET_COMMENT, NoteText = encoded_note_text ) - f.shutdown(); except Exception, msg: # We'll just not have added a private peer note if we get an exception here pass @@ -1665,7 +1665,8 @@ except Exception, msg: self.status = -1 self.status_msg = msg - f.shutdown(); + if(f != None): + f.shutdown(); return #@-node:class CheckIdentityWithNode @@ -1701,7 +1702,8 @@ f = fcp.FCPNode( host = fcp_host, port = fcp_port ) returned_peerlist = f.listpeers( WithVolatile = True ) except Exception, msg: - f.shutdown() + if(f != None): + f.shutdown() return { "status" : -1, "status_msg" : msg, "cpeers" : None, "tpeers" : None } try: f.shutdown(); From zothar at freenetproject.org Sun Feb 25 14:58:50 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 25 Feb 2007 14:58:50 +0000 (UTC) Subject: [Pyfreenet] r11915 - trunk/apps/pyFreenet Message-ID: <20070225145851.576439BFEB@emu.freenetproject.org> Author: zothar Date: 2007-02-25 14:58:49 +0000 (Sun, 25 Feb 2007) New Revision: 11915 Modified: trunk/apps/pyFreenet/minibot.py Log: refbot: Handle MemoryError exception better. Better PING/PONG processing. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2007-02-25 14:57:26 UTC (rev 11914) +++ trunk/apps/pyFreenet/minibot.py 2007-02-25 14:58:49 UTC (rev 11915) @@ -144,6 +144,10 @@ except TimeToQuit: self._keepRunning = False + except MemoryError: + log("Got MemoryError exception; Terminating.") + self._keepRunning = False + except NotReceiving: self.sock.close() self.hasIdentified = False @@ -242,7 +246,9 @@ """ Handles messages from server """ - if typ not in [ '353', '409' ]: + if typ == 'PONG': + pass + elif typ not in [ '353', '409' ]: log("** server: %s %s" % (repr(typ), msg)) if "End of /MOTD" in msg: if(not self.hasIdentified): @@ -432,7 +438,7 @@ sender = parts[0] sender = sender[1:] - if sender.endswith(".freenode.net"): + if sender.endswith(".freenode.net") or sender == self.host: sender = "$server$" else: sender = self.stripNickSpecialChars(sender.split("!")[0]) @@ -455,12 +461,14 @@ self.on_server_msg(typ, msg) return - if typ == "NOTICE": - self.on_notice(sender, msg) - elif typ == 'JOIN': + if typ == 'JOIN': self.on_join(sender, target) + elif typ == 'MODE': + self.on_mode(msg) elif typ == 'NICK': self.on_nick(sender, target) + elif typ == "NOTICE": + self.on_notice(sender, msg) elif typ == 'PART': self.on_part(sender, target, msg) elif typ == 'PRIVMSG': @@ -489,8 +497,6 @@ else: quit_msg = '' self.on_quit(sender, quit_msg) - elif typ == 'MODE': - self.on_mode(msg) else: log("?? sender=%s typ=%s target=%s msg=%s" % ( repr(sender), repr(typ), repr(target), repr(msg))) @@ -667,7 +673,7 @@ if self.txqueue: msg = self.txqueue.pop(0) - if 0 or msg != 'PING': + if 0 or not msg.startswith( "PING" ): log("** SEND: %s" % msg) self.sock.send(msg + "\n") @@ -696,7 +702,7 @@ #@+node:_pinger def _pinger(self): - self.sendline("PING") + self.sendline("PING %s %s" % ( self.nick, self.host )) self.after(42, self._pinger) #@-node:_pinger