コード例 #1
0
ファイル: models.py プロジェクト: rbroemeling/SMIRC
	def execute(self):
		"""Join a chat conversation that you have been invited to.

		/JOIN [user who invited you] in [conversation you are invited to]
		
		Example: /JOIN Foo in Bar
		Take the user "Foo" up on their invitation and join them in the
		conversation "Bar".
		"""
		try:
			invitation = Invitation.objects.get(invitee=self.executor, inviter=self.arguments['user'], conversation__name__iexact=self.arguments['conversation_identifier'])
		except Invitation.DoesNotExist:
			raise SmircCommandException('you do not have an outstanding invitation from %s to the conversation "%s"' % (self.arguments['user'].username, self.arguments['conversation_identifier']))
		
		try:
			Membership.load_membership(self.executor, invitation.conversation)
		except Membership.DoesNotExist:
			pass
		else:
			raise SmircCommandException('you are already in the conversation "%s"', invitation.conversation.name)

		try:
			Membership.load_membership(self.executor, invitation.conversation.name)
		except Membership.DoesNotExist:
			pass
		else:
			raise SmircCommandException('you are already in a different conversation named "%s"')
		
		m = Membership()
		m.conversation = invitation.conversation
		m.user = self.executor
		m.save()
		invitation.delete()
		return 'you have joined the conversation named "%s"' % (m.conversation.name)
コード例 #2
0
ファイル: models.py プロジェクト: rbroemeling/SMIRC
	def execute(self):
		"""Create a new SMIRC conversation.  Executor automatically joins
		the created conversation and is given operator permissions in it.
		
		/CREATE [conversation name]
		
		Example: /CREATE HelloWorld
		Creates a new SMIRC conversation called "HelloWorld" and automatically
		joins the executing user to it with full operator permissions.
		"""
		try:
			Conversation.validate_name(self.arguments['conversation_identifier'])
		except SmircRestrictedNameException as e:
			raise SmircCommandException(str(e))

		try:
			m = Membership.load_membership(self.executor, self.arguments['conversation_identifier'])
		except Membership.DoesNotExist:
			c = Conversation()
			c.name = self.arguments['conversation_identifier']
			c.save()
			m = Membership()
			m.conversation = c
			m.mode_operator = True
			m.user = self.executor
			m.save()
			return 'you have created a conversation named "%s"' % (c.name)
		else:
			raise SmircCommandException('you are already taking part in a conversation named "%s"' % (m.conversation.name))