Okay, so yet another post here due to my utter confusion with this language...in all honesty, this isn't a question about threading, per say, lemme just demonstrate what I mean.
class RevoiceThread( threading.Thread ): def run (self): print "Remember to replace this line with the actual code"
is the code for a thread I want to run, the print line I wish to replace with this(well, I want to replace it with something more complex, but this would be a proof of concept)
time.sleep(10) self.connection.mode(channel + " +v", vname)
That would be wrong, however, because the variables in there (as well as the whole "mode" function, so the self.connection is wrong too...) are in a separate class (see the full code below). Is there a simple way to implement what I'm trying to do here, or should I try re-thinking how to do this? (I'd honestly prefer to avoid threading, but there isn't really any other way to do this I can think of)
Full source code, for reference:
import ircbot import time import irclib import threading print "Mehbot v0.0.2 - August 18, 2010" #network info network = 'irc.geekshed.net' port = 6667 channel = '#meh' nick = 'Tarkbot' name = 'The Meh' #making the log file (opening it, rather) logFile = open ( 'log.txt', 'a' ) #more sketcy work #class forcepingThread ( threading.Thread ): class RevoiceThread( threading.Thread ): def run (self): print "Remember to replace this line with the actual code" #make bot class class MehBot ( ircbot.SingleServerIRCBot ): #join channel after connecting def on_welcome ( self, connection, event): connection.join ( channel ) #these are reactions to text in the channel the bot is in. def on_pubmsg ( self, connection, event ): #log messages from channel source = event.source().split ( '!' ) [ 0 ] text = event.arguments() [ 0 ] logFile.write ( "[" + time.strftime("%m/%d/%Y %H:%M", time.gmtime()) + "] " + source + ": " + text + "\n" ) #temp statement to quit bot if event.arguments() [ 0 ] == "die": self.die() #here be sketchyworkythingies. If user is de-voiced, revoices them (need timer) def on_mode ( self, connection, event ): if event.arguments() [ 0 ] == "-v": vname = event.arguments() [ 1 ] self.connection.mode(channel + " +v", vname) #create bot bot = MehBot ( [( network, port )], nick, name ) bot.start()
Edited 6 Years Ago by Tarkenfire: Forgot a colon.