当前位置: 首页>>代码示例>>Python>>正文


Python IRCMessage.msg方法代码示例

本文整理汇总了Python中ircmessage.IRCMessage.msg方法的典型用法代码示例。如果您正苦于以下问题:Python IRCMessage.msg方法的具体用法?Python IRCMessage.msg怎么用?Python IRCMessage.msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ircmessage.IRCMessage的用法示例。


在下文中一共展示了IRCMessage.msg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pull

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def pull(self, ircMsg):
    user = ircMsg.user
    message = ircMsg.msg
    args = message.split() #self.split_args(ircMsg)
    userid = args[2]
    if len(args) > 3:
      index = int(args[3])
    else:
      index = 0

    m = IRCMessage()

    #m.msg = _("msgIdentiPost").format(user, post)

    try:
      self.oauth()
      self.api = tweepy.API(self.auth, host = self.host, api_root = self.api_root)
      timeline = self.api.user_timeline(userid)
      #TODO: add support to pull an specific index
      m.msg = u"@{0}: {1}".format(userid, timeline[index].text)
    except:
      import traceback
      traceback.print_exc()
      m.msg("msgIdentiFail")

    return m
开发者ID:killman,项目名称:bot,代码行数:28,代码来源:identica.py

示例2: get_user_track

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def get_user_track(self, ircMsg):
    """Gets the selected user track, returns an IRCMessage."""
    m = IRCMessage(user=ircMsg.user, channel=ircMsg.channel)
    user_s = ircMsg.msg.split(' ')[2]
    user = self.last.get_user(user_s)
    logging.info("Getting last.fm user {0}".format(user_s))
    try:
      recent_tracks = user.get_recent_tracks()
    except:
      m.msg = "No user with that name."
      return m

    try:
      last_track = user.get_now_playing()
      if not last_track:
        last_track = recent_tracks[0].track
    except:
      m.msg = "No tracks avaliable for that username."
      return m

    tags_string =  u" , ".join([tag[0].name for tag in last_track.get_top_tags(4)])

    m.msg = u'User {0} is listening to: {1} - {2}: tags [ {3} ]'.format(user_s, last_track.title,
      last_track.artist.name, tags_string)
    return m
开发者ID:miguelchuga,项目名称:tio_chema,代码行数:27,代码来源:lastfm.py

示例3: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
    def execute(self, ircMsg, userRole, *args, **kwargs):
        
        command = ircMsg.msg.split(' ')
        command_type = command[1]
        
        irc_msg = IRCMessage()
        irc_msg.channel = ircMsg.channel
        irc_msg.user = ircMsg.user
        irc_msg.directed = True
        
        try:
            args = command[2]
        
            func = self.function_dict[command_type]

            if args != '' or args is not None:
                print args;
                irc_msg.msg = func(args)

            else:
                irc_msg.msg = func('help')
                
        except:
            irc_msg.msg =  self.help(None)
            logging.error('Error processing commands')
            
        return irc_msg
开发者ID:latopas,项目名称:tio_chema,代码行数:29,代码来源:chaturbate.py

示例4: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def execute(self, ircMsg, userRole, *args, **kwargs):
    user = ircMsg.user
    m = IRCMessage()
    conn = kwargs["connection"]
    m.msg = unicode()
    all_rows = conn.execute("select * from users").fetchall()
    choice = random.choice(all_rows)
    m.msg = "The selected user is {0}".format(choice[0])

    m.channel = ircMsg.channel
    m.user = user
    m.directed = True
    logging.debug("User: {0} hit the DB".format(user))
    return m
开发者ID:latopas,项目名称:tio_chema,代码行数:16,代码来源:db_test.py

示例5: get_tag_albums

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
 def get_tag_albums(self, ircMsg):
   """Gets the artists that match the tag, returns an IRCMessage."""
   m = IRCMessage(user=ircMsg.user, channel=ircMsg.channel)
   tag_s = " ".join(ircMsg.msg.split(' ')[2::])
   tag = self.last.get_tag(tag_s)
   logging.info("Getting last.fm tag {0}".format(tag_s))
   try:
     tag_albums = tag.get_top_albums()[:4:]
   except:
     m.msg = "No tag with that name"
     return m
   tag_albums_s = u", ".join(map(lambda a: a[0].get_name(), tag_albums))
   m.msg = u"Albums that match the tag {0} are: {1}".format(tag.get_name().decode("utf-8"), tag_albums_s)
   return m
开发者ID:miguelchuga,项目名称:tio_chema,代码行数:16,代码来源:lastfm.py

示例6: get_artist_tracks

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
 def get_artist_tracks(self, ircMsg):
   """Gets the selected user track, returns an IRCMessage"""
   m = IRCMessage(user=ircMsg.user, channel=ircMsg.channel)
   artist_s = " ".join(ircMsg.msg.split(' ')[2::])
   artist = self.last.get_artist(artist_s)
   logging.info("Getting last.fm artist {0}".format(artist_s))
   try:
     similar_artists = artist.get_similar(limit = 5)
   except:
     m.msg = "No artist with that name."
     return m
   similar_artists_s = u", ".join(map(lambda a: a[0].get_name(), similar_artists))
   m.msg = u"Artists similar to {0} are: {1}".format(artist.get_name().decode("utf-8"), similar_artists_s)
   return m
开发者ID:miguelchuga,项目名称:tio_chema,代码行数:16,代码来源:lastfm.py

示例7: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def execute(self, ircMsg, userRole, *args, **kwargs):
      user = ircMsg.user
      m = IRCMessage()
      term = ' '.join(ircMsg.arguments)

      try:
        temblo = self.get_quake(term)
      except Exception as e:
        ircMsg.msg = e.args[0]
        return ircMsg

      ## Converting UNIX timestamp to human readable time.
      date_t = datetime.fromtimestamp(temblo['properties']['time'] / 1000)
      date = date_t.isoformat()

      response_string = "Quake in: {0} | Magnitude: {1} | Time: {2} | URI: {3}".format(
          temblo[ 'properties' ][ 'place' ],
          temblo[ 'properties' ][ 'mag' ],
          date,
          temblo[ 'properties' ][ 'url' ]
        )
      m.msg = response_string
      m.channel = ircMsg.channel
      m.user = user
      m.directed = True
      return m
开发者ID:latopas,项目名称:tio_chema,代码行数:28,代码来源:temblor.py

示例8: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def execute(self, ircMsg, userRole, *args, **kwargs):
      user = ircMsg.user
      m = IRCMessage()
      definiciones = []
      message = ' '.join(ircMsg.msg.split())
      term = re.sub('^!temblor ', '', message)
      url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson"
      f = requests.get( url )
      data = json.loads(f.text)

      for feature in data['features']:
        cadena = feature['properties']['place']
        
        if cadena.upper().find( term.upper() ) != -1 :
          definiciones.append( feature )

      size = len( definiciones )
      temblo = definiciones[ randint( 0, size ) ]
      fecha_t = datetime.fromtimestamp( temblo[ 'properties' ][ 'time' ] / 1000 )
      fecha = fecha_t.strftime( '%d/%M/%Y %H:%m:%s')
      
      respuesta = '' + str( temblo[ 'properties' ][ 'mag' ] ) + ' | ' + temblo[ 'properties' ][ 'place' ] +  ' | ' + fecha + ' | '+ temblo[ 'properties' ][ 'url' ] 
      m.msg = respuesta
      m.channel = ircMsg.channel
      m.user = user
      m.directed = True
      return m
开发者ID:miguelchuga,项目名称:tio_chema,代码行数:29,代码来源:temblor.py

示例9: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
 def execute(self, ircMsg, userRole, *args, **kwargs):
     user = ircMsg.user
     m = IRCMessage()
     definiciones = []
     message = ' '.join(ircMsg.msg.split())
     
     cal = subprocess.Popen( [ 'calendar' ], stdout=subprocess.PIPE )
     wc = subprocess.Popen( [ 'wc', '-l' ], stdin=cal.stdout, stdout=subprocess.PIPE )
     num = wc.communicate()
     numero = int( num[0] )
     numero = randint( 0, numero )
     cal = subprocess.Popen( [ 'calendar'], stdout=subprocess.PIPE )
     head = subprocess.Popen( [ 'head', '-' + str( numero ) ], stdin=cal.stdout, stdout=subprocess.PIPE )
     tail = subprocess.Popen( [ 'tail', '-1' ], stdin=head.stdout, stdout=subprocess.PIPE )
     resp = tail.communicate();
     if len( resp ) > 0 :
       respuesta = resp[ 0 ]
     else:
       respuesta = ''
     #calendar | wc -l ; calendar | head -rand | tail -1
     m.msg = '' + respuesta
     m.channel = ircMsg.channel
     m.user = user
     m.directed = True
     return m
开发者ID:latopas,项目名称:tio_chema,代码行数:27,代码来源:calendar.py

示例10: testEquality

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def testEquality(self):
    n = IRCMessage(self.channel, "---", self.user, True)
    self.assertEquals(self.m, n)
    n.msg = "!-"
    self.assertNotEquals(self.m, n)
    n.msg = self.m.msg
    n.channel = "#"
    self.assertNotEquals(self.m, n)

    ## A fake directed should not be equal.
    n = IRCMessage(self.channel, "---", self.user, False)
    self.m.directed = True
    self.assertNotEquals(self.m, n)

    n.msg = "{0}: {1}".format(n.user, n.msg)
    self.assertNotEquals(self.m, n)
开发者ID:killman,项目名称:bot,代码行数:18,代码来源:ircmessage_test.py

示例11: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def execute(self, ircMsg, userRole, *args, **kwargs):
      user = ircMsg.user
      m = IRCMessage()
      definiciones = []
      message = ' '.join(ircMsg.msg.split())
      term = re.sub('^!urbano ', '', message)

      payload = {'term': term  }
      url = "http://www.urbandictionary.com/define.php?"    

      f = requests.get( url, params=payload)
      data = f.text

      soup = BeautifulSoup( data )
      tag = soup.find_all('div', attrs={'class' : 'definition' } )

      for tagita in tag:
        if type(tagita.string) != types.NoneType :
          definiciones.append( tagita.string.strip() )

      respuesta = definiciones[ randint( 0, len( definiciones ) - 1 ) ]

      m.msg = respuesta
      m.channel = ircMsg.channel
      m.user = user
      m.directed = True
      return m
开发者ID:miguelchuga,项目名称:tio_chema,代码行数:29,代码来源:urbano.py

示例12: post

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def post(self, ircMsg):
    user = ircMsg.user
    message = ' '.join(ircMsg.msg.split())

    post = re.sub('^!identica post ', '', message)
    m = IRCMessage()

    m.msg = _("msgIdentiPost").format(user, post)

    try:
      self.oauth()
      self.api = tweepy.API(self.auth, host = self.host, api_root = self.api_root)
      #self.api.update_status(post[:140])
    except:
      m.msg("msgIdentiFail")
      return m
开发者ID:killman,项目名称:bot,代码行数:18,代码来源:identica.py

示例13: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
  def execute(self, ircMsg, userRole):
    user = ircMsg.user
    if user == self.last_user:
      self.counter += 1
    else:
      self.counter = 0
      self.last_user = user

    m = IRCMessage()
    if self.counter > self.threshold:
      #TODO: localize
      m.msg = "yarr, it's the {0} time you've called me!".format(self.counter)
    else:
      m.msg = "pong"
    m.channel = ircMsg.channel
    m.user = user
    m.directed = True
    return m
开发者ID:kmels,项目名称:tio_chema,代码行数:20,代码来源:ping.py

示例14: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
    def execute(self, ircMsg, userRole, regex_groups):
        try:
            url = regex_groups[0][0]
            msg = IRCMessage()
            msg.channel = ircMsg.channel
            msg.msg = WebTitle.get_title(url)
        except:
            logging.error(":(")

        return msg
开发者ID:tian2992,项目名称:tio_chema,代码行数:12,代码来源:webtitle.py

示例15: execute

# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import msg [as 别名]
    def execute(self, ircMsg, userRole, *args, **kwargs):

        command = ircMsg.msg.split(' ')
        command_type = command[1]

        irc_msg = IRCMessage()
        irc_msg.channel = ircMsg.channel
        irc_msg.user = ircMsg.user
        irc_msg.directed = True

        try:

            func = self.func_dict[command_type]
            irc_msg.msg = func(command)

        except:
            irc_msg.msg = self.help(None)
            logging.error("Error processing commands")
            logging.debug(sys.exc_info()[1])
        return irc_msg
开发者ID:noahfx,项目名称:tio_chema,代码行数:22,代码来源:tuiter.py


注:本文中的ircmessage.IRCMessage.msg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。