예제 #1
0
    def info(self):
        '''
        Show information about the user or group
        '''
        output = ('<b>INFO</b>\n' '==================\n')
        chat_id = self.metadata['chat_id']
        if self.metadata['chat_type'] != 'private':
            # Get user warns
            user = get_user(self.metadata['user_id'])
            if user:
                user_adv = user[0].total_warns
            else:
                user_adv = 0

            max_warn = get_max_warns(self.metadata['chat_id'])

            output += (f'<code>ID DO GRUPO</code> : {chat_id}\n'
                       f'<code>TOTAL DE ADVERTENCIAS</code> : {max_warn}\n'
                       f'<code>SUAS ADVERTENCIAS</code> : {user_adv}\n')

        nome = self.metadata['username']
        id = self.metadata['user_id']
        output += (f'<code>NOME</code> : {nome}\n' f'<code>ID</code>   : {id}')

        self.bot.sendMessage(chat_id=chat_id,
                             parse_mode='HTML',
                             text=output,
                             reply_to_message_id=self.metadata['msg_id'])
예제 #2
0
    def warn(self):
        first_name = self.metadata['rpl_first_name']
        user_id = self.metadata['rpl_user_id']
        msg_id = self.metadata['rpl_msg_id']
        if user_id in self.tycot.admins_ids:
            self.bot.sendMessage(self.metadata['chat_id'],
                                 (f'*{first_name}* é um dos administradores.\n'
                                  'Não posso advertir administradores.'),
                                 parse_mode='Markdown',
                                 reply_to_message_id=self.metadata['msg_id'])
        else:
            if not user_exist(self.metadata['chat_id'], user_id):
                user = add_user(first_name, user_id, self.metadata['chat_id'])
            user = get_user(user_id)[0]

            group_max_warns = get_max_warns(self.metadata['chat_id'])
            warn_user(self.metadata['chat_id'], user_id)
            self.bot.sendMessage(
                self.metadata['chat_id'],
                (f'{first_name} *foi advertido'
                 f' ({user.total_warns}/{group_max_warns})*.'),
                parse_mode='Markdown',
                # reply_markup=self.keyboard_warn(user_id),
                reply_to_message_id=msg_id)
            self._kick_user(user, group_max_warns)
예제 #3
0
파일: user_cmd.py 프로젝트: gp2112/TycotBot
    def info(self):
        '''
        Show information about the user or group
        '''
        if self.metadata['chat_type'] != 'private':
            msg = ('*INFO*\n'
                   '==================\n'
                   '`ID DO GRUPO` : {chat_id}\n'
                   '`TOTAL DE ADVERTENCIAS` : {max_warn}\n'
                   '`SUAS ADVERTENCIAS` : {user_adv}\n'
                   '`NOME` : {nome}\n'
                   '`ID`   : {id}')
            # get user warns
            user = get_user(self.metadata['user_id'])
            if user:
                user_adv = user[0].total_warns
            else:
                user_adv = 0

            self.bot.sendMessage(chat_id=self.metadata['chat_id'],
                                 parse_mode='Markdown',
                                 text=msg.format(
                                     chat_id=self.metadata['chat_id'],
                                     max_warn=get_max_warns(
                                         self.metadata['chat_id']),
                                     user_adv=user_adv,
                                     nome=self.metadata['username'],
                                     id=self.metadata['user_id']),
                                 reply_to_message_id=self.metadata['msg_id'])
        else:
            msg = ('*ID INFO*\n'
                   '==================\n'
                   '`NOME` : {nome}\n'
                   '`ID`   : {id}')
            self.bot.sendMessage(chat_id=self.metadata['chat_id'],
                                 parse_mode='Markdown',
                                 text=msg.format(
                                     nome=self.metadata['username'],
                                     id=self.metadata['user_id']),
                                 reply_to_message_id=self.metadata['msg_id'])
예제 #4
0
 def unwarn(self):
     first_name = self.metadata['rpl_first_name']
     user_id = self.metadata['rpl_user_id']
     msg_id = self.metadata['rpl_msg_id']
     if user_id in self.tycot.admins_ids:
         self.bot.sendMessage(self.metadata['chat_id'],
                              'Administradores não possuem advertências.',
                              reply_to_message_id=self.metadata['msg_id'])
     else:
         user = get_user(user_id)[0]  # get the user from db
         if user.total_warns == 0:
             self.bot.sendMessage(
                 self.metadata['chat_id'],
                 f'*{first_name}* não possui advertencias.',
                 parse_mode='Markdown',
                 reply_to_message_id=msg_id)
         else:
             unwarn_user(self.metadata['chat_id'], user_id)
             self.bot.sendMessage(self.metadata['chat_id'],
                                  f'*{first_name} foi perdoado.*',
                                  parse_mode='Markdown',
                                  reply_to_message_id=msg_id)
예제 #5
0
	async def on_message(self, message):
		# Make sure the message is not sent by this bot and
		# also make sure that the member is still in the guild.
		if message.author == self.user or isinstance(message.author, discord.User):
			return

		user = queries.get_user(message.author.id, message.author.name)

		# Get global message channel
		global_status_channel = self.get_channel(self.config["global_status_channel_id"])

		# Command i know it's ugly:
		if message.content.startswith("check"):
			if message.mentions:
				c_user = queries.get_user(message.mentions[0].id, message.mentions[0].name)
				self.calculate_level(c_user)

				if global_status_channel is not None:
					await global_status_channel.send(f"{c_user.name}'s level: {lvl2str(c_user.lvl)}. You infected {c_user.infected} people and {c_user.infected_me} people have infected {c_user.name}.")
				return

			else:
				self.calculate_level(user)

				if global_status_channel is not None:
					await global_status_channel.send(f"Your level: {lvl2str(user.lvl)}. You infected {user.infected} people and {user.infected_me} people have infected you.")
				return

		# Get infected role and check if member is infected.
		infected_role = await self.get_infected_role(message.guild)

		if infected_role not in message.author.roles:
			return


		# At this point the author is valid and infected.
		print(f"[!] Member '{message.author}' is infected, checking nearby messages.")

		# Keep track of users we've seen, this will stop multiple infections
		# to the same person.
		seen_users = { message.author.id, self.user.id }


		# Timestamp cutoff point for past messages.
		max_time_diff = message.created_at - datetime.timedelta(seconds = self.config["max_time_difference_seconds"])
		distance = 0


		# Read message history.
		async for msg in message.channel.history(limit = self.config["nearby_messages"], before = message):
			distance += 1


			# If message is too old, we skip checking any more messages.
			# We also make sure the user is still inside the guild.
			if msg.created_at < max_time_diff or isinstance(msg.author, discord.User):
				break

			# Make sure this user has not been seen previously.
			if msg.author.id in seen_users or msg.author.id in self.incubating:
				continue


			seen_users.add(msg.author.id)


			# Check if member is already infected.
			if infected_role in msg.author.roles:
				continue

			# Decide whether or not to infect this user.
			n = self.config["nearby_messages"]  # number of messages to check
			c = self.config["infection_chance"] # this will cap the infection chance at some percentage


			# Function which reduces chances of infection based on distance
			multiplier = c - (((distance / 1) / n) ** 4) * c

			print(f"\t[-] Chance of infection: {int(multiplier)}% at distance {distance}, for member '{msg.author.name}'")

			if random.randint(1, 100) <= multiplier:
				print(f"\t[!] Member {message.author.name} infected {msg.author.name}.")

				# Construct a status message to send.
				src_nick = "" if message.author.nick is None else f" ({message.author.nick})"
				dest_nick = "" if msg.author.nick is None else f" ({msg.author.nick})"

				status = f"{message.author.name}#{message.author.discriminator}{src_nick} infected {msg.author.name}#{msg.author.discriminator}{dest_nick} in '{message.guild.name}'."

				# Get local status channel.
				local_status_channel = discord.utils.get(message.guild.text_channels, name = "pz-log")

				# Send new status message.
				if global_status_channel is not None:
					await global_status_channel.send(content = status)

				if local_status_channel is not None:
					await local_status_channel.send(content = status)

				# Save scores in DB
				old_lvl = user.lvl
				user.infected += 1
				self.calculate_level(user)
				queries.set_user(user)

				# Level up status message
				if old_lvl < user.lvl:
					await global_status_channel.send(f"\n {lvl2str(user.lvl)} {message.author.name}#{message.author.discriminator}{src_nick} has leveled up! You have infected :face_vomiting: {user.infected} people!")
					# https://www.youtube.com/watch?v=bLMWYcQ1fAo

				# Save infected user's stats in DB:
				user2 = queries.get_user(msg.author.id, msg.author.name)
				if user2:
					user2.infected_me += 1
					old_lvl2 = user2.lvl
					self.calculate_level(user2)
					queries.set_user(user2)

					# Level up message for the passive user:
					if old_lvl2 < user2.lvl:
						await global_status_channel.send(content=f"\n {lvl2str(user.lvl)} {msg.author.name}#{msg.author.discriminator}{dest_nick} has leveled up! You have been infected :nauseated_face: {user2.infected_me} times!")

				# Add user to incubating set and then sleep in a non blocking way.
				self.incubating.add(msg.author.id)

				await asyncio.sleep(self.config["incubation_time_seconds"])
				await msg.author.add_roles(infected_role, reason = "this person was infected.")

				# Remove user from incubating set, they are now infected.
				if msg.author.id in self.incubating:
					self.incubating.remove(msg.author.id)

			else:
				print(f"\t[-] Not infecting '{msg.author.name}'.")

		print("\t[-] Done!")