Exemplo n.º 1
0
	def thread(self, user, msg):
		if iMan.loaded('roster'):
			roster = iMan.roster[utils.getname(user).lower()]
			match = self.r.match(msg)
			if msg.startswith('|') and msg.endswith('|'):
				return False
			if not match and 'afk' in roster:
				timestamp = datetime.datetime.fromtimestamp(roster.afk[1])
				self.parent.sendto(
					user, (random.choice(self.webies) + " You were gone for %s") % (
						utils.getname(user),
						utils.time_since(timestamp, '.')
					)
				)
				del roster.afk
			elif match:
				reason = match.group('reason')
				roster.afk = [reason, time.time()]
				self.parent.sendto(user, random.choice(self.byes) % utils.getname(user))
Exemplo n.º 2
0
	def thread(self, user, args, whisper):
		# Sterilize the name to prevent abuse.
		if self.truncate_to:
			if ' ' in args:
				args, _ = args.split(' ', 1)
			if len(args) > self.truncate_to:
				args = args[:self.truncate_to]
		elif False:
			try:
				args = self.lastseen_parser.parse_args(shlex.split(args))
			except:
				args = None

		if not args:
			raise const.CommandHelp
		username = utils.getname(user)

		orig_name = args
		name = args.lower()
		roster = iMan.roster[name]

		reply = '%s, ' % username

		#The target is the calling user.
		if username.lower() == name:
			reply += "are you really that conceited? You're right here!"

		# We've never seen the target before.
		elif not roster:
			reply += "who is %s?" % (orig_name)

		# The user is AFK. AFK status is persistent across statuses
		elif 'afk' in roster:
			timestamp = datetime.datetime.fromtimestamp(roster.afk[1])
			sentence = "%s%%s went AFK %s" % (orig_name, utils.time_since(timestamp))
			# If the user is online
			if roster.last_login is None:
				reply += sentence % ''
			else:
				reply += sentence % "(offline)"

			if roster.afk[0]:
				reply += " and is %s" % roster.afk[0]
			reply += "."

		# We see the user as online
		elif 'last_login' in roster and roster.last_login is None:
			if not roster.last_message:
				reply += "%s hasn't spoken a word since he logged on." % orig_name
			else:
				timestamp = datetime.datetime.fromtimestamp(roster.last_message)
				reply += '%s spoke %s' % (orig_name, utils.time_since(timestamp))

		# The user is offline
		else:
			then = datetime.datetime.fromtimestamp(roster.last_login)
			reply += 'I saw %s %s' % (orig_name, utils.time_since(then))

		if False and whisper:
			self.parent.sendto(user, reply)
		else:
			self.parent.sendtoall(reply)