本文整理汇总了Python中ircmessage.IRCMessage.directed方法的典型用法代码示例。如果您正苦于以下问题:Python IRCMessage.directed方法的具体用法?Python IRCMessage.directed怎么用?Python IRCMessage.directed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ircmessage.IRCMessage
的用法示例。
在下文中一共展示了IRCMessage.directed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例2: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例3: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例4: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例5: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例6: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
message = ' '.join(ircMsg.msg.split())
lista_articulos = self.devolver_lista_de(self.baseurl)
hp=randint(0,len(lista_articulos)-1)
m.msg=''+lista_articulos[hp][2][:228] + '...... publicado el: ' + lista_articulos[hp][3] + ' en la seccion ' + lista_articulos[hp][9]
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例7: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
definiciones = []
message = ' '.join(ircMsg.msg.split())
topic = re.sub('^!preguntar ', '', message)
respuesta = self.get_question( topic )
m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例8: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例9: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
definiciones = []
message = ' '.join(ircMsg.msg.split())
p = subprocess.Popen(["fortune", "-a", "-n", "160", "-s"], stdout=subprocess.PIPE)
output, err = p.communicate()
#TODO manejar err
m.msg = output
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例10: testIsInitialized
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def testIsInitialized(self):
self.assertTrue(self.m.is_initialized())
q = IRCMessage()
self.assertFalse(q.is_initialized())
## Message with no channel should be false.
q.channel = "#"
q.msg = "notempty"
self.assertFalse(q.is_initialized())
## Adding directed testing.
q.channel = self.channel
q.directed = True
self.assertFalse(q.is_initialized())
q.user = self.user
self.assertTrue(q.is_initialized())
示例11: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
message = ' '.join(ircMsg.msg.split())
numero = re.sub('^!xkcd ', '', message)
if numero.isdigit():
respuesta = self.get_comic( numero )
else:
respuesta = self.get_current()
m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例12: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
url = 'http://feeds.reuters.com/reuters/topNews'
req = requests.get(url)
tree = ETree.fromstring(req.text.encode("UTF-8"))
tag_list = tree.findall("./channel/item")
tagita = choice(tag_list)
respuesta = u"{} | {}".format(tagita.find("title").text, tagita.find("link").text)
m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例13: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
url = 'http://hosted2.ap.org/atom/APDEFAULT/3d281c11a96b4ad082fe88aa0db04305'
f = requests.get( url )
data = f.text
soup = BeautifulSoup( data )
tag = soup.find_all( 'entry' )
tagita = tag[ randint( 0, len( tag ) -1 ) ]
respuesta = tagita.title.string.encode( 'utf8') + ' | ' + tagita.link[ 'href' ].encode( 'utf8' )
m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
示例14: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [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
示例15: execute
# 需要导入模块: from ircmessage import IRCMessage [as 别名]
# 或者: from ircmessage.IRCMessage import directed [as 别名]
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
if user == self.last_user:
self.counter += 1
else:
self.counter = 0
self.last_user = user
self.db.put_ping(unicode(user), ircMsg.t)
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
logging.debug("User: {0} pinged".format(user))
return m