本文整理汇总了Python中messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager.process方法的典型用法代码示例。如果您正苦于以下问题:Python XmppCooldownManager.process方法的具体用法?Python XmppCooldownManager.process怎么用?Python XmppCooldownManager.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager
的用法示例。
在下文中一共展示了XmppCooldownManager.process方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessagesManager
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import process [as 别名]
class MessagesManager(ClientEventsHandler):
__slots__ = ('__msgFilters', '__chatSessions', '__receivedTags', '__pending')
def __init__(self):
super(MessagesManager, self).__init__()
self.__msgFilters = None
self.__chatSessions = _ChatSessions()
self.__isInited = False
self.__receivedTags = set()
self.__pending = []
self.__cooldown = XmppCooldownManager(MESSAGE_LIMIT.COOLDOWN)
self.channelsStorage.onRestoredFromCache += self.__cs_onChannelsRestoredFromCache
return
@storage_getter('channels')
def channelsStorage(self):
return None
def clear(self):
self.channelsStorage.onRestoredFromCache -= self.__cs_onChannelsRestoredFromCache
self.__clearData()
super(MessagesManager, self).clear()
def registerHandlers(self):
register = self.client().registerHandler
register(_EVENT.CONNECTED, self.__handleConnected)
register(_EVENT.DISCONNECTED, self.__handleDisconnected)
register(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived += self.__me_onUsersListReceived
events.onUserActionReceived += self.__me_onUserActionReceived
events.onUserStatusUpdated += self.__me_onUserStatusUpdated
def unregisterHandlers(self):
unregister = self.client().unregisterHandler
unregister(_EVENT.CONNECTED, self.__handleConnected)
unregister(_EVENT.DISCONNECTED, self.__handleDisconnected)
unregister(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived -= self.__me_onUsersListReceived
events.onUserActionReceived -= self.__me_onUserActionReceived
events.onUserStatusUpdated -= self.__me_onUserStatusUpdated
def setFilters(self, msgFilters):
self.__msgFilters = msgFilters
def isInCooldown(self):
return self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE)
@xmpp_query(QUERY_SIGN.DATABASE_ID, QUERY_SIGN.ACCOUNT_NAME)
def startChatSession(self, dbID, name):
self.__chatSessions.startSession(makeContactJID(dbID), name)
return (True, None)
def stopChatSession(self, jid):
self.__chatSessions.stopSession(ContactBareJID(jid))
def sendChatMessage(self, jid, body):
if self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE):
g_messengerEvents.onErrorReceived(ChatCoolDownError(CLIENT_ACTION_ID.SEND_MESSAGE, MESSAGE_LIMIT.COOLDOWN))
return
self.__chatSessions.sendMessage(ContactBareJID(jid), body)
self.__cooldown.process(CLIENT_ACTION_ID.SEND_MESSAGE)
def __clearData(self):
self.__chatSessions.clear()
self.__receivedTags.clear()
self.__pending = []
def __setChannelsState(self, isJoined):
channels = self.channelsStorage.getChannelsByCriteria(find_criteria.XMPPChannelFindCriteria())
for channel in channels:
channel.setJoined(isJoined)
def __handleConnected(self):
self.__setChannelsState(True)
def __handleDisconnected(self, reason, description):
self.__clearData()
self.__setChannelsState(False)
def __handleMessage(self, _, msgType, body, jid, pyGlooxTag):
if msgType == MESSAGE_TYPE.CHAT:
state, info, sentAt = ChatMessageHandler().handleTag(pyGlooxTag)
if info:
dbID = info['dbID']
name = info['name']
else:
LOG_ERROR('Can not find sender info', pyGlooxTag.getXml())
return
if body:
body = self.__msgFilters.chainIn(dbID, body)
if _REQUIRED_USER_TAGS.issubset(self.__receivedTags):
self.__chatSessions.onMessageReceived(jid, body, state, dbID, name, sentAt)
else:
self.__pending.insert(0, (msgType, (jid,
body,
state,
dbID,
name,
#.........这里部分代码省略.........
示例2: ContactsManager
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import process [as 别名]
#.........这里部分代码省略.........
subTo = contact.getSubscription()[0]
else:
jid = makeContactJID(dbID)
subTo = _SUB.OFF
error = self.__checkRosterSize()
if error:
return (False, error)
if itemType == XMPP_ITEM_TYPE.BLOCK_ITEM:
tasks.append(block_tasks.RemoveBlockItemTask(jid, name))
tasks.append(roster_tasks.AddRosterItemTask(jid, name, groups))
elif itemType == XMPP_ITEM_TYPE.ROSTER_BLOCK_ITEM:
tasks.append(block_tasks.RemoveBlockItemTask(jid, name))
task, exclude = None, set()
rosterGroups = contact.getItem().getRosterGroups()
for group in rosterGroups:
if self.usersStorage.isGroupEmpty(group):
exclude.add(group)
if groups:
if groups != exclude:
task = roster_tasks.ChangeRosterItemGroupsTask(jid, name, groups, exclude)
elif rosterGroups:
task = roster_tasks.ChangeRosterItemGroupsTask(jid, name, set(), exclude)
if task:
tasks.append(task)
elif itemType == XMPP_ITEM_TYPE.SUB_PENDING:
tasks.append(sub_tasks.ApproveSubscriptionTask(jid, name))
if groups:
tasks.append(roster_tasks.ChangeRosterItemGroupsTask(jid, name, groups))
else:
tasks.append(roster_tasks.AddRosterItemTask(jid, name, groups))
if subTo == _SUB.OFF:
tasks.append(sub_tasks.AskSubscriptionTask(jid))
self.__cooldown.process(CLIENT_ACTION_ID.ADD_FRIEND)
return self.__addTasks(CLIENT_ACTION_ID.ADD_FRIEND, jid, *tasks)
@xmpp_query(QUERY_SIGN.DATABASE_ID)
def removeFriend(self, dbID):
error = self.__checkCooldown(CLIENT_ACTION_ID.REMOVE_FRIEND)
if error:
return (False, error)
contact = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP)
if not contact:
return (False, ClientContactError(CONTACT_ERROR_ID.CONTACT_ITEM_NOT_FOUND))
if contact.getItemType() != XMPP_ITEM_TYPE.ROSTER_ITEM:
return (False, ClientContactError(CONTACT_ERROR_ID.ROSTER_ITEM_NOT_FOUND, contact.getFullName()))
jid = contact.getJID()
self.__cooldown.process(CLIENT_ACTION_ID.REMOVE_FRIEND)
return self.__addTasks(CLIENT_ACTION_ID.REMOVE_FRIEND, jid, roster_tasks.RemoveRosterItemTask(jid, contact.getName(), groups=contact.getGroups()))
@xmpp_query(QUERY_SIGN.DATABASE_ID, QUERY_SIGN.OPT_GROUP_NAME, QUERY_SIGN.OPT_GROUP_NAME)
def moveFriendToGroup(self, dbID, include = None, exclude = None):
error = self.__checkCooldown(CLIENT_ACTION_ID.CHANGE_GROUP)
if error:
return (False, error)
else:
contact = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP)
if not contact:
return (False, ClientContactError(CONTACT_ERROR_ID.CONTACT_ITEM_NOT_FOUND))
if contact.getItemType() != XMPP_ITEM_TYPE.ROSTER_ITEM:
return (False, ClientContactError(CONTACT_ERROR_ID.ROSTER_ITEM_NOT_FOUND, contact.getFullName()))
groups = contact.getGroups()
if include:
if not self.usersStorage.isGroupExists(include):
return (False, ClientContactError(CONTACT_ERROR_ID.GROUP_NOT_FOUND, include))
groups.add(include)
示例3: ChatSessionHistoryRequester
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import process [as 别名]
#.........这里部分代码省略.........
def release(self):
if self.__isSuspend:
self.__isSuspend = False
self.__doNextRequest()
def suspend(self):
if not self.__isSuspend:
self.__isSuspend = True
if self.__callbackID is not None:
BigWorld.cancelCallback(self.__callbackID)
self.__callbackID = None
self.__state = _HISTORY_RQ_STATE.FREE
self.__iqID = ''
self.__history = []
return
def clear(self):
if self.__callbackID is not None:
BigWorld.cancelCallback(self.__callbackID)
self.__callbackID = None
self.__iqID = ''
self.__pool = []
self.__state = _HISTORY_RQ_STATE.FREE
return
def request(self, jid):
if self.__state == _HISTORY_RQ_STATE.UNAVAILABLE:
self.__setChannelHistory(jid)
return
if jid not in self.__pool:
self.__pool.append(jid)
if self.__isSuspend:
return
if self.__state == _HISTORY_RQ_STATE.FREE:
self.__doNextRequest()
def cancel(self, jid):
if jid in self.__pool:
if jid == self.__pool[0]:
if self.__callbackID is not None:
BigWorld.cancelCallback(self.__callbackID)
self.__callbackID = None
self.__state = _HISTORY_RQ_STATE.FREE
self.__pool.pop(0)
self.__iqID = ''
self.__history = []
self.__doNextRequest()
else:
self.__pool.remove(jid)
return
def handleIQ(self, iqID, iqType, tag):
if iqID == self.__iqID:
if iqType == IQ_TYPE.RESULT:
self.__state = _HISTORY_RQ_STATE.RESULT
elif iqType == IQ_TYPE.ERROR:
self.__state = _HISTORY_RQ_STATE.UNAVAILABLE
error = errors.createServerActionIQError(CLIENT_ACTION_ID.RQ_HISTORY, tag)
if error:
g_messengerEvents.onErrorReceived(error)
while self.__pool:
self.__setChannelHistory(self.__pool.pop(0))
result = True
else:
result = False
return result
def addHistory(self, message):
if not self.__state == _HISTORY_RQ_STATE.RESULT:
raise AssertionError
if message.body:
self.__history.append(message)
message.isFinalInHistory and self.__setChannelHistory(self.__pool.pop(0))
self.__history = []
self.__state = _HISTORY_RQ_STATE.FREE
self.__doNextRequest()
def __setChannelHistory(self, jid):
channel = self.channelsStorage.getChannel(entities.XMPPChatChannelEntity(jid))
if channel:
g_messengerEvents.channels.onHistoryReceived(sorted(self.__history, key=operator.attrgetter('sentAt')), channel)
def __doNextRequest(self):
if self.__cooldown.isInProcess(CLIENT_ACTION_ID.RQ_HISTORY):
self.__state = _HISTORY_RQ_STATE.COOLDOWN
self.__callbackID = BigWorld.callback(self.__cooldown.getTime(CLIENT_ACTION_ID.RQ_HISTORY), self.__callback)
else:
if not self.__pool:
return
self.__state = _HISTORY_RQ_STATE.WAIT
self.__iqID = self.client().sendIQ(chat_ext.GetChatHistoryQuery(self.__pool[0], self.__limit))
self.__cooldown.process(CLIENT_ACTION_ID.RQ_HISTORY, 5.0)
def __callback(self):
self.__callbackID = None
self.__state = _HISTORY_RQ_STATE.FREE
self.__doNextRequest()
return
示例4: MessagesManager
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import process [as 别名]
class MessagesManager(ClientEventsHandler):
__slots__ = ('__msgFilters', '__limits', '__chatSessions', '__muc', '__receivedTags', '__pending', '__cooldown')
def __init__(self):
super(MessagesManager, self).__init__()
self.__msgFilters = None
self.__limits = _MessageLimits()
self.__chatSessions = ChatSessionsProvider(self.__limits)
self.__muc = MUCProvider()
self.__receivedTags = set()
self.__pending = []
self.__cooldown = XmppCooldownManager(self.__limits.getBroadcastCoolDown())
self.channelsStorage.onRestoredFromCache += self.__cs_onChannelsRestoredFromCache
return
@storage_getter('channels')
def channelsStorage(self):
return None
def clear(self):
self.channelsStorage.onRestoredFromCache -= self.__cs_onChannelsRestoredFromCache
self.__clearData()
super(MessagesManager, self).clear()
def registerHandlers(self):
register = self.client().registerHandler
register(_EVENT.DISCONNECTED, self.__handleDisconnected)
register(_EVENT.LOGIN, self.__handleLogin)
register(_EVENT.PRESENCE, self.__handlePresence)
register(_EVENT.PRESENCE_ERROR, self.__handlePresenceError)
register(_EVENT.IQ, self.__handleIQ)
register(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived += self.__me_onUsersListReceived
events.onUserActionReceived += self.__me_onUserActionReceived
events.onUserStatusUpdated += self.__me_onUserStatusUpdated
def unregisterHandlers(self):
unregister = self.client().unregisterHandler
unregister(_EVENT.DISCONNECTED, self.__handleDisconnected)
unregister(_EVENT.LOGIN, self.__handleLogin)
unregister(_EVENT.PRESENCE, self.__handlePresence)
unregister(_EVENT.PRESENCE_ERROR, self.__handlePresenceError)
unregister(_EVENT.IQ, self.__handleIQ)
unregister(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived -= self.__me_onUsersListReceived
events.onUserActionReceived -= self.__me_onUserActionReceived
events.onUserStatusUpdated -= self.__me_onUserStatusUpdated
def setFilters(self, msgFilters):
self.__msgFilters = msgFilters
def isInCooldown(self):
return self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE)
@xmpp_query(QUERY_SIGN.DATABASE_ID, QUERY_SIGN.ACCOUNT_NAME)
def startChatSession(self, dbID, name):
self.__chatSessions.startSession(jid_entity.makeContactJID(dbID), name)
return (True, None)
def stopChatSession(self, jid):
self.__chatSessions.stopSession(jid.getBareJID())
def sendChatMessage(self, jid, body):
if self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE):
g_messengerEvents.onErrorReceived(ChatCoolDownError(CLIENT_ACTION_ID.SEND_MESSAGE, self.__limits.getBroadcastCoolDown()))
return
body = self.__msgFilters.chainOut(body, self.__limits)
if not body:
return
self.__chatSessions.sendMessage(jid.getBareJID(), body, self.__msgFilters)
self.__cooldown.process(CLIENT_ACTION_ID.SEND_MESSAGE)
def requestChatSessionHistory(self, jid):
contactId = int(jid.getBareJID().getNode())
self.__msgFilters.reset(contactId)
self.__chatSessions.requestHistory(jid.getBareJID())
@xmpp_query()
def createUserRoom(self, name, password = ''):
return self.__muc.createRoom(name, password=password)
@xmpp_query()
def joinToMUC(self, jid, password = ''):
return self.__muc.joinToRoom(jid.getBareJID(), password=password)
def leaveFromMUC(self, jid):
self.__muc.leaveFromRoom(jid.getBareJID())
def sendGroupChatMessage(self, jid, body):
if self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE):
g_messengerEvents.onErrorReceived(ChatCoolDownError(CLIENT_ACTION_ID.SEND_MESSAGE, self.__limits.getBroadcastCoolDown()))
return
body = self.__msgFilters.chainOut(body, self.__limits)
if not body:
return
self.__muc.sendMessage(jid_entity.ContactBareJID(jid), body, self.__msgFilters)
self.__cooldown.process(CLIENT_ACTION_ID.SEND_MESSAGE)
#.........这里部分代码省略.........
示例5: MessagesManager
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import process [as 别名]
class MessagesManager(ClientEventsHandler):
__slots__ = ('__msgFilters', '__limits', '__chatSessions', '__receivedTags', '__pending')
def __init__(self):
super(MessagesManager, self).__init__()
self.__msgFilters = None
self.__limits = _MessageLimits()
self.__chatSessions = _ChatSessions(self.__limits)
self.__isInited = False
self.__receivedTags = set()
self.__pending = []
self.__cooldown = XmppCooldownManager(self.__limits.getBroadcastCoolDown())
self.channelsStorage.onRestoredFromCache += self.__cs_onChannelsRestoredFromCache
@storage_getter('channels')
def channelsStorage(self):
return None
def clear(self):
self.channelsStorage.onRestoredFromCache -= self.__cs_onChannelsRestoredFromCache
self.__clearData()
super(MessagesManager, self).clear()
def registerHandlers(self):
register = self.client().registerHandler
register(_EVENT.DISCONNECTED, self.__handleDisconnected)
register(_EVENT.IQ, self.__handleIQ)
register(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived += self.__me_onUsersListReceived
events.onUserActionReceived += self.__me_onUserActionReceived
events.onUserStatusUpdated += self.__me_onUserStatusUpdated
def unregisterHandlers(self):
unregister = self.client().unregisterHandler
unregister(_EVENT.DISCONNECTED, self.__handleDisconnected)
unregister(_EVENT.IQ, self.__handleIQ)
unregister(_EVENT.MESSAGE, self.__handleMessage)
events = g_messengerEvents.users
events.onUsersListReceived -= self.__me_onUsersListReceived
events.onUserActionReceived -= self.__me_onUserActionReceived
events.onUserStatusUpdated -= self.__me_onUserStatusUpdated
def setFilters(self, msgFilters):
self.__msgFilters = msgFilters
def isInCooldown(self):
return self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE)
@xmpp_query(QUERY_SIGN.DATABASE_ID, QUERY_SIGN.ACCOUNT_NAME)
def startChatSession(self, dbID, name):
self.__chatSessions.startSession(makeContactJID(dbID), name)
return (True, None)
def stopChatSession(self, jid):
self.__chatSessions.stopSession(ContactBareJID(jid))
def sendChatMessage(self, jid, body):
if self.__cooldown.isInProcess(CLIENT_ACTION_ID.SEND_MESSAGE):
g_messengerEvents.onErrorReceived(ChatCoolDownError(CLIENT_ACTION_ID.SEND_MESSAGE, self.__limits.getBroadcastCoolDown()))
return
body = self.__msgFilters.chainOut(body, self.__limits)
if not body:
return
self.__chatSessions.sendMessage(ContactBareJID(jid), body, self.__msgFilters)
self.__cooldown.process(CLIENT_ACTION_ID.SEND_MESSAGE)
def requestChatHistory(self, jid):
self.__chatSessions.requestHistory(ContactBareJID(jid))
def __clearData(self):
self.__chatSessions.clear()
self.__receivedTags.clear()
self.__pending = []
def __handleDisconnected(self, reason, description):
self.__clearData()
channels = self.channelsStorage.getChannelsByCriteria(find_criteria.XMPPChannelFindCriteria())
for channel in channels:
channel.setJoined(False)
def __handleIQ(self, iqID, iqType, pyGlooxTag):
self.__chatSessions.handleIQ(iqID, iqType, pyGlooxTag)
def __handleMessage(self, _, msgType, body, jid, pyGlooxTag):
if msgType not in MESSAGE_TYPE_TO_ATTR:
return
message = MessageHandler(MESSAGE_TYPE_TO_ATTR[msgType]).handleTag(pyGlooxTag)
if not message.accountDBID:
g_logOutput.error(CLIENT_LOG_AREA.MESSAGE, 'Can not find sender info', pyGlooxTag.getXml())
return
if body:
message.body = self.__msgFilters.chainIn(message.accountDBID, body)
if not _REQUIRED_USER_TAGS.issubset(self.__receivedTags):
self.__pending.insert(0, (msgType, (jid, message)))
return
if msgType == MESSAGE_TYPE.CHAT or msgType == MESSAGE_TYPE.NORMAL and message.isHistory():
self.__chatSessions.addMessage(jid, message)
def __me_onUsersListReceived(self, tags):
#.........这里部分代码省略.........