Exemplo n.º 1
0
    def __init__(self,
                 source_port,
                 address,
                 params,
                 stats,
                 visualiser,
                 socket=SocketAPI.SocketAPI(),
                 timer=Timer.Timer(),
                 mode=False):
        self.sock = socket
        self.source_port = source_port
        self.source_ip = self.sock.get_host()
        self.address = address
        self.count, self.timeout, self.interval = params
        self.visualiser = visualiser
        self.timer = timer
        self.is_unlimited_mode = mode

        self.packets = {}
        self.count_of_packets_sent = 0
        self.count_of_received_packets = 0
        self.seq = 10

        self.stats = stats
        for addr in self.address:
            self.stats.add_address(addr)
Exemplo n.º 2
0
    async def temp_mute(self, ctx: commands.Context, victim: discord.Member, *,
                        time_and_reason: converters.HumanTime(other=True)):
        """
        Temporarily mute a user
        Args:
            victim: Member you want to mute
            time: Un-mute time - Optional
            reason: Reason for mute - Optional
        """

        time = time_and_reason.time
        reason = time_and_reason.other

        if victim.id == ctx.author.id:
            return await ctx.send(
                "Why do want to mute yourself?\nI'm not gonna let you do it")

        async with ctx.typing():
            await self.do_mute(ctx, victim=victim, time=time, reason=reason)

            if time:
                extras = {
                    'mute_id': inserted.id,
                    'guild_id': inserted.guild_id,
                    'muted_user_id': inserted.muted_user_id,
                }
                timer = Timer(event='tempmute',
                              created_at=ctx.message.created_at,
                              expires_at=time,
                              kwargs=extras)
                await self.bot.timers.create_timer(timer)
Exemplo n.º 3
0
 async def fetch_past_timers(db: asyncpg.Connection) -> typing.List[Timer]:
     fetched = await db.fetch('''
         select *
         from Timers
         where now() > expires_at;
     ''')
     return Timer.convertMany(fetched)
Exemplo n.º 4
0
    async def tempban(
            self,
            ctx: commands.Context,
            victim: discord.Member,
            *,
            time_and_reason: converters.HumanTime(other=True) = None):
        """
        Temporarily ban a user
        Args:
            victim: Member you want to ban
            time: Un-ban time - Optional
            reason: Reason for ban - Optional
        """
        if time_and_reason is None:
            time = None
            reason = ''
        else:
            time = time_and_reason.time
            reason = time_and_reason.other if time_and_reason.other is not None else ''
        await self.do_ban(ctx, victim, reason, time)

        if time:
            extras = {
                'ban_id': saved.id,
                'guild_id': saved.guild_id,
                'banned_user_id': saved.banned_user_id,
            }
            timer = Timer(event='tempban',
                          created_at=ctx.message.created_at,
                          expires_at=time,
                          kwargs=extras)
            await self.bot.timers.create_timer(timer)
Exemplo n.º 5
0
    async def remind(self, ctx: commands.Context, *, time_and_text: HumanTime(other=True)):
        """
        Reminds you of something after a certain amount of time.

        Args:
            time: When you want to be reminded; should be a relative time like 2h, 1d, etc
            text: What you want to be reminded of
        """

        time, text = time_and_text.time, time_and_text.other

        timer = Timer(
            event='reminder',
            created_at=ctx.message.created_at,
            expires_at=time,
            kwargs={
                'author_id': ctx.author.id,
                'guild_id': ctx.guild.id,
                'channel_id': ctx.channel.id,
                'text': text
            }
        )
        await self.bot.timers.create_timer(timer)
        delta = (pendulum.instance(timer.expires_at) - pendulum.instance(ctx.message.created_at)).in_words()
        await ctx.send(f"{ctx.author.display_name} in {delta}:\n{timer.kwargs['text']}")
Exemplo n.º 6
0
 async def delete(db: asyncpg.Connection, timer: Timer) -> Timer:
     deleted = await db.fetchrow(
         '''
         delete from timers
         where id = $1
         returning *
     ''', timer.id)
     return Timer.convert(deleted)
Exemplo n.º 7
0
    async def insert(db: asyncpg.Connection, timer: Timer) -> Timer:
        inserted = await db.fetchrow(
            '''
            insert into Timers (event, created_at, expires_at, extras)
            values ($1, $2, $3, $4::jsonb)
            returning *;
        ''', timer.event, timer.created_at, timer.expires_at, timer.kwargs)

        return Timer.convert(inserted)
Exemplo n.º 8
0
 async def get_where(db: asyncpg.Connection, *, extras: typing.Dict,
                     limit: int) -> typing.List[Timer]:
     query = '''
         select *
         from Timers where extras @> $1::jsonb
         limit $2;
     '''
     fetched = await db.fetch(query, extras, limit)
     return Timer.convertMany(fetched)
Exemplo n.º 9
0
    if not (0 <= port <= 65535):
        raise ValueError
    return ip, port


if __name__ == "__main__":
    if sys.platform == 'win32':
        sys.stderr.write('Windows don\'t supported\n')
        sys.exit(1)

    parsed, address = parse_args()
    source_port = parsed.source_port
    if parsed.v:
        visualiser = Visualiser.TimeVisualiser()
    else:
        visualiser = Visualiser.StreamVisualiser(parsed.timeout)
    stats = Statistics.AddressStatManager(
        (Statistics.PacketStatusStat, Statistics.MinTimeStat,
         Statistics.MaxTimeStat, Statistics.AverageTimeStat))

    sock = SocketAPI.SocketAPI()
    timer = Timer.Timer()
    program = TCPing.TCPing(source_port, address,
                            (parsed.packet, parsed.timeout, parsed.interval),
                            stats, visualiser, sock, timer, parsed.unlimited)
    if parsed.unlimited:
        signal.signal(signal.SIGUSR1, program.signal_handler)
    program.send_and_receive_packets()
    if not parsed.unlimited:
        program.process_data()
Exemplo n.º 10
0
 async def fetch_all_timers(db: asyncpg.Connection) -> typing.List[Timer]:
     fetched = await db.fetch('''
         select *
         from Timers;
     ''')
     return Timer.convertMany(fetched)