Exemplo n.º 1
0
 async def tempblock(self, ctx, channel: typing.Optional[discord.TextChannel],
                     members: commands.Greedy[discord.Member], time, *, reason: commands.clean_content = None):
     """ Temporarily mute member(s) """
     if channel is None:
         channel = ctx.channel
 
     try:
         delta = await parse_time(time.lower())
     except ValueError:
         return await ctx.reply('Invalid time specified, use format `1d1h30m10s`', mention_author=True)
     remind_at = datetime.datetime.now() + delta
     human_time = datetime.datetime.strftime(remind_at, "%H:%M:%S on %a %d %b")
 
     ow = discord.PermissionOverwrite(read_messages=False, send_messages=False)
 
     # Mute, send to notification channel if exists.
     for i in members:
         await channel.set_permissions(i, overwrite=ow)
     
         connection = await self.bot.db.acquire()
         record = await connection.fetchval(""" INSERT INTO reminders (message_id, channel_id, guild_id,
         reminder_content,
         created_time, target_time. user_id, mod_action, mod_target) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
         RETURNING *""", ctx.message.id, channel.id, ctx.guild.id, reason, datetime.datetime.now(), remind_at,
                                           ctx.author.id, "unblock", i.id)
         await self.bot.db.release(connection)
         self.bot.reminders.append(self.bot.loop.create_task(spool_reminder(ctx.bot, record)))
 
     e = discord.Embed()
     e.title = "⏰ User blocked"
     e.description = f"{', '.join([i.mention for i in members])} will be blocked from {channel.mention} " \
                     f"\n{reason}\nuntil\n {human_time}"
     e.colour = 0x00ffff
     e.timestamp = remind_at
     await ctx.reply(embed=e, mention_author=False)
Exemplo n.º 2
0
    async def timer(self, ctx, time, *, message: commands.clean_content):
        """ Remind you of something at a specified time.
            Format is remind 1d2h3m4s <note>, e.g. remind 1d3h Kickoff."""
        delta = await parse_time(time.lower())

        remind_at = datetime.datetime.now() + delta
        human_time = datetime.datetime.strftime(remind_at,
                                                "%a %d %b at %H:%M:%S")

        connection = await self.bot.db.acquire()
        record = await connection.fetchrow(
            """ INSERT INTO reminders
        (message_id, channel_id, guild_id, reminder_content, created_time, target_time, user_id)
        VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *""", ctx.message.id,
            ctx.channel.id, ctx.guild.id, message, ctx.message.created_at,
            remind_at, ctx.author.id)
        await self.bot.db.release(connection)
        print(record)
        self.bot.reminders.append(
            self.bot.loop.create_task(spool_reminder(self.bot, record)))

        e = discord.Embed()
        e.title = "⏰ Reminder Set"
        e.description = f"**{human_time}**\n{message}"
        e.colour = 0x00ffff
        e.timestamp = remind_at
        await ctx.send(embed=e)
Exemplo n.º 3
0
 async def tempban(self, ctx,  members: commands.Greedy[discord.Member], time, *,
                   reason: commands.clean_content = None):
     """ Temporarily ban member(s) """
     try:
         delta = await parse_time(time.lower())
     except ValueError:
         return await ctx.reply('Invalid time specified, use format `1d1h30m10s`', mention_author=True)
     remind_at = datetime.datetime.now() + delta
     human_time = datetime.datetime.strftime(remind_at, "%H:%M:%S on %a %d %b")
 
     for i in members:
         try:
             await ctx.guild.ban(i, reason=reason)
         except discord.Forbidden:
             await ctx.reply(f"🚫 I can't ban {i.mention}.", mention_author=True)
             continue
     
         connection = await self.bot.db.acquire()
         record = await connection.fetchrow(""" INSERT INTO reminders (message_id, channel_id, guild_id,
         reminder_content,
         created_time, target_time. user_id, mod_action, mod_target) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
         RETURNING *""", ctx.message.id, ctx.channel.id, ctx.guild.id, reason, datetime.datetime.now(), remind_at,
                                           ctx.author.id, "unban", i.id)
         await self.bot.db.release(connection)
         self.bot.reminders.append(self.bot.loop.create_task(spool_reminder(ctx.bot, record)))
 
     e = discord.Embed()
     e.title = "⏰ User banned"
     e.description = f"{[i.mention for i in members]} will be unbanned for \n{reason}\nat\n {human_time}"
     e.colour = 0x00ffff
     e.timestamp = remind_at
     await ctx.reply(embed=e, mention_author=False)
Exemplo n.º 4
0
 async def spool_initial(self):
     connection = await self.bot.db.acquire()
     records = await connection.fetch("""SELECT * FROM reminders""")
     async with connection.transaction():
         for r in records:
             self.bot.reminders.append(
                 self.bot.loop.create_task(
                     timed_events.spool_reminder(self.bot, r)))
     await self.bot.db.release(connection)
Exemplo n.º 5
0
    async def tempmute(self,
                       ctx,
                       members: commands.Greedy[discord.Member],
                       time,
                       *,
                       reason: commands.clean_content = None):
        """ Temporarily mute member(s) """
        delta = await parse_time(time.lower())
        remind_at = datetime.datetime.now() + delta
        human_time = datetime.datetime.strftime(remind_at,
                                                "%H:%M:%S on %a %d %b")

        # Role.
        muted_role = discord.utils.get(ctx.guild.roles, name='Muted')
        if not muted_role:
            muted_role = await ctx.guild.create_role(
                name="Muted")  # Read Messages / Read mesasge history.
            await muted_role.edit(position=ctx.me.top_role.position - 1)
            m_overwrite = discord.PermissionOverwrite(add_reactions=False,
                                                      send_messages=False)

            for i in ctx.guild.text_channels:
                await i.set_permissions(muted_role, overwrite=m_overwrite)

        # Mute
        for i in members:
            await i.add_roles(muted_role, reason=f"{ctx.author}: {reason}")
            connection = await self.bot.db.acquire()
            record = await connection.fetchrow(
                """ INSERT INTO reminders
            (message_id, channel_id, guild_id, reminder_content,
             created_time, target_time, user_id, mod_action, mod_target)
            VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
            RETURNING *""", ctx.message.id, ctx.channel.id, ctx.guild.id,
                reason, ctx.message.created_at, remind_at, ctx.author.id,
                "unmute", i.id)
            await self.bot.db.release(connection)
            self.bot.reminders.append(
                self.bot.loop.create_task(spool_reminder(ctx.bot, record)))

        e = discord.Embed()
        e.title = "⏰ User muted"
        e.description = f"{', '.join([i.mention for i in members])} temporarily muted:"
        e.add_field(name="Until", value=human_time)
        if reason is not None:
            e.add_field(name="Reason", value=reason)
        e.colour = 0x00ffff
        e.timestamp = remind_at
        await ctx.send(embed=e)
Exemplo n.º 6
0
    async def timer(self, ctx, time, *, message: commands.clean_content):
        """ Remind you of something at a specified time.
            Format is remind 1d2h3m4s <note>, e.g. remind 1d3h Kickoff."""
        try:
            delta = await timed_events.parse_time(time.lower())
        except ValueError:
            return await ctx.reply('Invalid time specified.',
                                   mention_author=False)

        try:
            remind_at = datetime.datetime.now() + delta
        except OverflowError:
            return await ctx.reply("You'll be dead by then.",
                                   mention_author=False)
        human_time = datetime.datetime.strftime(remind_at,
                                                "%a %d %b at %H:%M:%S")

        connection = await self.bot.db.acquire()
        async with connection.transaction():
            record = await connection.fetchrow(
                """ INSERT INTO reminders
            (message_id, channel_id, guild_id, reminder_content, created_time, target_time, user_id)
            VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *""", ctx.message.id,
                ctx.channel.id, ctx.guild.id, message, ctx.message.created_at,
                remind_at, ctx.author.id)
        await self.bot.db.release(connection)
        self.bot.reminders.append(
            self.bot.loop.create_task(
                timed_events.spool_reminder(self.bot, record)))

        e = discord.Embed()
        e.title = "⏰ Reminder Set"
        e.description = f"**{human_time}**\n{message}"
        e.colour = 0x00ffff
        e.timestamp = remind_at
        await ctx.reply(embed=e, mention_author=False)
Exemplo n.º 7
0
 async def spool_initial(self):
     connection = await self.bot.db.acquire()
     records = await connection.fetch("""SELECT * FROM reminders""")
     for r in records:
         self.bot.reminders.append(
             self.bot.loop.create_task(spool_reminder(self.bot, r)))