本文整理汇总了Python中messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager.isInProcess方法的典型用法代码示例。如果您正苦于以下问题:Python XmppCooldownManager.isInProcess方法的具体用法?Python XmppCooldownManager.isInProcess怎么用?Python XmppCooldownManager.isInProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager
的用法示例。
在下文中一共展示了XmppCooldownManager.isInProcess方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessagesManager
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import isInProcess [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 isInProcess [as 别名]
#.........这里部分代码省略.........
self.__cooldown.process(CLIENT_ACTION_ID.REMOVE_NOTE)
return self.__addTasks(CLIENT_ACTION_ID.SET_NOTE, jid, note_tasks.RemoveNoteTask(jid))
def __makeChangeGroupsChain(self, exclude, include = None):
chain = []
for contact in self.usersStorage.getList(GroupFindCriteria(exclude)):
jid = contact.getJID()
groups = contact.getGroups()
groups.discard(exclude)
if include:
groups.add(include)
chain.append((jid, contact.getName(), groups))
return roster_tasks.ChangeRosterItemsGroupsChain(chain)
def __makeRemoveItemsByGroupChain(self, name):
chain = []
for contact in self.usersStorage.getList(GroupFindCriteria(name)):
groups = contact.getGroups()
groups.discard(name)
chain.append((contact.getJID(), contact.getName(), groups))
return roster_tasks.RemoveRosterItemsGroupsChain(chain)
def __addTasks(self, actionID, jid, *tasks):
if self.__tasks.addTasks(jid, *tasks):
self.__tasks.runFirstTask(jid)
else:
return (False, ClientActionError(actionID, CLIENT_ERROR_ID.LOCKED))
return (True, None)
def __checkCooldown(self, actionID):
error = None
if self.__cooldown.isInProcess(actionID):
error = ChatCoolDownError(actionID, self.__cooldown.getDefaultCoolDown())
return error
def __checkRosterSize(self):
length = self.usersStorage.getCount(ItemsFindCriteria((XMPP_ITEM_TYPE.ROSTER_ITEM,)))
if length >= CONTACT_LIMIT.ROSTER_MAX_COUNT:
return ClientIntLimitError(LIMIT_ERROR_ID.MAX_ROSTER_ITEMS, CONTACT_LIMIT.ROSTER_MAX_COUNT)
else:
return None
def __handleConnected(self):
self.__tasks.suspend()
self.__seq.onInited += self.__onSeqsInited
tasks = [roster_tasks.RosterResultTask(), block_tasks.BlockListResultTask()]
if GUI_SETTINGS.isXmppNotesEnabled:
tasks.append(note_tasks.NotesListTask())
self.__seq.init(*tasks)
def __handleDisconnected(self, reason, description):
self.__seq.fini()
self.__tasks.clear()
for contact in self.usersStorage.getList(ProtoFindCriteria(PROTO_TYPE.XMPP)):
resources = contact.getItem().getResources()
if not resources.isEmpty():
resources.clear()
g_messengerEvents.users.onUserStatusUpdated(contact)
def __handleIQ(self, iqID, iqType, pyGlooxTag):
if not self.__seq.handleIQ(iqID, iqType, pyGlooxTag):
self.__tasks.handleIQ(iqID, iqType, pyGlooxTag)
def __handleRosterQuery(self, iqID, jid, context):
示例3: ChatSessionHistoryRequester
# 需要导入模块: from messenger.proto.xmpp.XmppCooldownManager import XmppCooldownManager [as 别名]
# 或者: from messenger.proto.xmpp.XmppCooldownManager.XmppCooldownManager import isInProcess [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 isInProcess [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 isInProcess [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):
#.........这里部分代码省略.........