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


Python Bot.call方法代码示例

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


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

示例1: __init__

# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import call [as 别名]
class Session:

	def __init__(self, backend, user, legacyName, extra, db):
		self.logger = logging.getLogger(self.__class__.__name__)
		self.logger.info("Created: %s", legacyName)

		self.db = db
		self.backend = backend
		self.user = user
		self.legacyName = legacyName

		self.status = protocol_pb2.STATUS_NONE
		self.statusMessage = ''

		self.groups = {}
		self.presenceRequested = []
		self.offlineQueue = []
		self.groupOfflineQueue = { }

		self.timer = None
		self.password = None
		self.initialized = False

		self.buddies = BuddyList(legacyName, db)
		self.frontend = YowsupConnectionManager()

		self.bot = Bot(self)

		# Events
		self.listen("auth_success", self.onAuthSuccess)
		self.listen("auth_fail", self.onAuthFailed)
		self.listen("disconnected", self.onDisconnected)

		self.listen("contact_typing", self.onContactTyping)
		self.listen("contact_paused", self.onContactPaused)

		self.listen("presence_updated", self.onPrecenceUpdated)
		self.listen("presence_available", self.onPrecenceAvailable)
		self.listen("presence_unavailable", self.onPrecenceUnavailable)

		self.listen("message_received", self.onMessageReceived)
		self.listen("image_received", self.onMediaReceived)
		self.listen("video_received", self.onMediaReceived)
		self.listen("audio_received", self.onMediaReceived)
		self.listen("location_received", self.onLocationReceived)
		self.listen("vcard_received", self.onVcardReceived)

		self.listen("group_messageReceived", self.onGroupMessageReceived)
		self.listen("group_gotInfo", self.onGroupGotInfo)
		self.listen("group_gotParticipants", self.onGroupGotParticipants)
		self.listen("group_subjectReceived", self.onGroupSubjectReceived)

		self.listen("notification_groupParticipantAdded", self.onGroupParticipantAdded)
		self.listen("notification_groupParticipantRemoved", self.onGroupParticipantRemoved)
		self.listen("notification_contactProfilePictureUpdated", self.onContactProfilePictureUpdated)
		self.listen("notification_groupPictureUpdated", self.onGroupPictureUpdated)

	def __del__(self): # handleLogoutRequest
		self.logout()

	def call(self, method, args = ()):
		args = [str(s) for s in args]
		self.logger.debug("%s(%s)", method, ", ".join(args))
		self.frontend.methodInterface.call(method, args)

	def listen(self, event, callback):
		self.frontend.signalInterface.registerListener(event, callback)

	def logout(self):
		self.call("disconnect", ("logout",))

	def login(self, password):
		self.password = utils.decodePassword(password)
		self.call("auth_login", (self.legacyName, self.password))

	def updateRoomList(self):
		rooms = []
		for room, group in self.groups.iteritems():
			rooms.append([room, group.subject])

		self.backend.handleRoomList(rooms)

	# spectrum RequestMethods
	def sendTypingStarted(self, buddy):
		if buddy != "bot":
			self.logger.info("Started typing: %s to %s", self.legacyName, buddy)
			self.call("typing_send", (buddy + "@s.whatsapp.net",))

	def sendTypingStopped(self, buddy):
		if buddy != "bot":
			self.logger.info("Stopped typing: %s to %s", self.legacyName, buddy)
			self.call("typing_paused", (buddy + "@s.whatsapp.net",))

	def sendMessageToWA(self, sender, message):
		self.logger.info("Message sent from %s to %s: %s", self.legacyName, sender, message)
		message = message.encode("utf-8")

		if sender == "bot":
			self.bot.parse(message)
		elif "-" in sender: # group msg
#.........这里部分代码省略.........
开发者ID:vitalyster,项目名称:transwhat,代码行数:103,代码来源:session.py

示例2: Bot

# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import call [as 别名]
#coding=utf-8

from datetime import date
import time
import simplejson
from bot import Bot
from trackingData import TrackingData
import sys
from pageParser import MZATrainsListParser
import pageChecker
import urllib2


bot = Bot()
res = bot.call('''{ "id":1, "jsonrpc":2, "method":"getTrainsList", "params": ["Санкт-Петербург", "Москва", 1305839921]}''')
print res
sys.exit(0)

request = urllib2.Request(url="http://www.mza.ru/?exp=1", data="""ScheduleRoute_DepDate=20.05.2011
                                                             &ScheduleRoute_StationFrom=САНКТ-ПЕТЕРБУРГ
                                                             &ScheduleRoute_StationTo=МОСКВА
                                                             &spr=ScheduleRoute
                                                             &submit=Показать
                                                             &ScheduleRoute_ArvTimeFrom=
                                                             &ScheduleRoute_ArvTimeTo=
                                                             &ScheduleRoute_DepTimeFrom=
                                                             &ScheduleRoute_DepTimeTo=""")
response = urllib2.urlopen(request)
checker = pageChecker.MZAErrorChecker()
page = response.read()
res = checker.CheckPage(page)
开发者ID:appach22,项目名称:rzd_bot,代码行数:33,代码来源:test.py


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