Ejemplo n.º 1
0
 def __init__( self, name ):
   Processor.__init__( self, name )
   self.s = LEDSign()
Ejemplo n.º 2
0
 def __init__(self, name):
     Processor.__init__(self, name)
     self.s = LEDSign()
Ejemplo n.º 3
0
class Sign( Processor ):

  usage = u'!sign <message>'

  feature = ('sign',)

  addressed = False

  old_status = 0

  def __init__( self, name ):
    Processor.__init__( self, name )
    self.s = LEDSign()

  @handler
  def handle( self, event ):
    print "I am handling this event: " + repr(event)

  @match(r'^!sign\s(.*)$', version='deaddressed')
  def sign( self, event, message ):
    try:
      p = subprocess.Popen( beepdisc["SIGN"] )
      p.wait()
      self.s.print_message( 0, ''.join(["From: ", event.sender['nick'], datetime.datetime.today().strftime(" %d%b %H:%m") ] ) )
      self.s.print_message( 1, message )
      event.addresponse( True )
    except Exception:
      event.addresponse( "I can't see the sign. Are you sure it's plugged in? Have you tried turning it off and on again?" )

  @match(r'^!status$')
  def status( self, event ):
    try:
      status = self.s.get_status()
      if status:
        event.addresponse("open")
      else:
        event.addresponse("closed")
    except Exception:
      event.addresponse( "I can't see the sign. Are you sure it's plugged in? Have you tried turning it off and on again?" )

  @periodic( interval = 1, initial_delay = 1 )
  def update_status( self, event ):
    
    status = self.s.get_status()

    if( status != self.old_status ):
      topic = ibid.sources['freenode'].proto.get_topic( lab_channel )
      topic_parts = topic.split( u"//" )
      topiclen = len( topic_parts )
      if topiclen >= 3 :
        pos = -2
      elif topiclen == 2 or topiclen == 1:
        pos = -1
      else:
        pos = 0
        topic_parts.append("")

      topic_parts[ pos ] = " Lab status: OPEN " if status else " Lab status: CLOSED "
        
      event.addresponse( u"//".join( topic_parts ), topic = True, target = lab_channel, address = False, source = u"freenode" )

      self.old_status = status
      
      alert = "SECRET" if status else "OCARINA" 

      p = subprocess.Popen(beepdisc[alert])
      p.wait()
Ejemplo n.º 4
0
class Sign(Processor):

    usage = u'!sign <message>'

    feature = ('sign', )

    addressed = False

    old_status = 0

    def __init__(self, name):
        Processor.__init__(self, name)
        self.s = LEDSign()

    @handler
    def handle(self, event):
        print "I am handling this event: " + repr(event)

    @match(r'^!sign\s(.*)$', version='deaddressed')
    def sign(self, event, message):
        try:
            p = subprocess.Popen(beepdisc["SIGN"])
            p.wait()
            self.s.print_message(
                0, ''.join([
                    "From: ", event.sender['nick'],
                    datetime.datetime.today().strftime(" %d%b %H:%m")
                ]))
            self.s.print_message(1, message)
            event.addresponse(True)
        except Exception:
            event.addresponse(
                "I can't see the sign. Are you sure it's plugged in? Have you tried turning it off and on again?"
            )

    @match(r'^!status$')
    def status(self, event):
        try:
            status = self.s.get_status()
            if status:
                event.addresponse("open")
            else:
                event.addresponse("closed")
        except Exception:
            event.addresponse(
                "I can't see the sign. Are you sure it's plugged in? Have you tried turning it off and on again?"
            )

    @periodic(interval=1, initial_delay=1)
    def update_status(self, event):

        status = self.s.get_status()

        if (status != self.old_status):
            topic = ibid.sources['freenode'].proto.get_topic(lab_channel)
            topic_parts = topic.split(u"//")
            topiclen = len(topic_parts)
            pos = 0
            while pos < topiclen:
                if "Lab status: " in topic_parts[pos]:
                    break
                pos += 1

            if pos == topiclen:
                topic_parts.append("")

            topic_parts[
                pos] = " Lab status: OPEN " if status else " Lab status: CLOSED "

            event.addresponse(u"//".join(topic_parts),
                              topic=True,
                              target=lab_channel,
                              address=False,
                              source=u"freenode")

            self.old_status = status

            alert = "SECRET" if status else "OCARINA"

            p = subprocess.Popen(beepdisc[alert])
            p.wait()