Exemplo n.º 1
0
 def test_ping_host_multiple(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         ping("ping host host2 host3 host4", self.hosts)
         self.assertEqual(mock_system.call_count, 3)
         expected = [(('ping -c 1 -q host2 > /dev/null',),),
                     (('ping -c 1 -q host3.domain.com > /dev/null',),),
                     (('ping -c 1 -q 4.4.4.4 > /dev/null',),)]
         self.assertEqual(mock_system.call_args_list, expected)
Exemplo n.º 2
0
 def test_ping_other_multiple(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         ping("ping other test.com google.com 1.1.1.1", self.hosts)
         self.assertEqual(mock_system.call_count, 3)
         expected = [(('ping -c 1 -q test.com > /dev/null',),),
                     (('ping -c 1 -q google.com > /dev/null',),),
                     (('ping -c 1 -q 1.1.1.1 > /dev/null',),),]
         self.assertEqual(mock_system.call_args_list, expected)
Exemplo n.º 3
0
 def test_ping_other_url(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         ping("ping other <https://test.com|test.com>", self.hosts)
         self.assertEqual(mock_system.call_count, 1)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q test.com > /dev/null',),))
         mock_system.return_value = False
         ping("ping other <https://google.com|google.com>", self.hosts)
         self.assertEqual(mock_system.call_count, 2)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q google.com > /dev/null',),))
Exemplo n.º 4
0
 def test_ping_other_ip(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         ping("ping other 1.1.1.1", self.hosts)
         self.assertEqual(mock_system.call_count, 1)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q 1.1.1.1 > /dev/null',),))
         mock_system.return_value = False
         ping("ping other 2.2.2.2", self.hosts)
         self.assertEqual(mock_system.call_count, 2)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q 2.2.2.2 > /dev/null',),))
Exemplo n.º 5
0
 def test_ping_host_single(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         ping("ping host host1", self.hosts)
         self.assertEqual(mock_system.call_count, 1)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q 1.1.1.1 > /dev/null',),))
         mock_system.return_value = False
         ping("ping host host2", self.hosts)
         self.assertEqual(mock_system.call_count, 2)
         self.assertEqual(mock_system.call_args, 
                          (('ping -c 1 -q host2 > /dev/null',),))
Exemplo n.º 6
0
 def test_ping_host_none(self):
     with patch('os.system') as mock_system:
         mock_system.return_value = True
         response = ping("ping host", self.hosts)
         self.assertIs(type(response), str)
         self.assertEqual(mock_system.call_count, 0)
Exemplo n.º 7
0
                                    cmd.dungeonmaster(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'dungeonstats':
                                    cmd.dungeonstats(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'raidstats':
                                    cmd.raidstats(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'ping':
                                    cmd.ping(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'leaderboard' or params[0] == 'lb':
                                    cmd.leaderboard(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'channels':
                                    cmd.channels(channel)
                                    db(opt.CHANNELS).update_one_by_name(channel, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)
                                    db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True)

                                if params[0] == 'xp' or params[0] == 'exp':
                                    try:
async def on_message(message):
    """looks at every message sent in the server.
    If it is a function command, it is executed.
    Also logs PMs.
    """
    global state
    global channels
    global day
    global setupchannel
    global admin_role
    global stupid_role
    global player_role
    global players
    global stupid
    global admins
    global playMsg
    global pmChannels
    global stChannels
    global pmInit
    global pmCount
    global adv  # asynchronous functions are hard

    msg = message.content
    msgch = message.channel
    msggd = message.guild
    to_send = {}

    if message.author == client.user:
        return
        # Makes the bot ignore its own messages

    if msg.startswith('!setup'):
        setupchannel, to_send = cmd.setup(setupchannel, msgch)

    elif msg.startswith('!add'):
        channels, to_send = cmd.add(msgch, channels)

    elif msg.startswith('!catadd'):
        channels, to_send = cmd.catadd(msgch, channels)

    elif msg.startswith('!servadd'):
        channels, to_send = cmd.servadd(msggd, channels)

    elif msg.startswith('!remove'):
        channels, to_send = cmd.remove(msgch, channels)

    elif msg.startswith('!catrm'):
        channels, to_send = cmd.catrm(msgch, channels)

    elif msg.startswith('!servrm'):
        channels, to_send = cmd.servrm(msgch)

    elif msg.startswith('!pmadd'):
        pmChannels, to_send = cmd.pmadd(message, pmChannels)

    elif msg.startswith('!pmcatadd'):
        pmChannels, to_send = cmd.pmcatadd(admins, msgch, pmChannels)

    elif msg.startswith('!stadd'):
        stChannels, to_send = cmd.pmadd(message, stChannels)

    elif msg.startswith('!stcatadd'):
        stChannels, to_send = cmd.stcatadd(admins, msgch, stChannels)

    elif msg.startswith('!admin'):
        admin_role, admins, to_send = cmd.admin(message, setupchannel,
                                                admin_role, admins)

    elif msg.startswith('!player'):
        player_role, to_send = cmd.player(message, setupchannel, player_role)

    elif msg.startswith('!stupid'):
        stupid_role, to_send = cmd.stupid(message, setupchannel, stupid_role)

    elif msg.startswith('!pladd'):
        players = cmd.pladd(players, message)

    elif msg.startswith('!divide'):
        day, consent, to_send = cmd.divide(message, setupchannel, day,
                                           channels, adv, consent)
        for sinner in stupid:   # reset stupid roles
            updated = sinner.roles
            updated.remove(stupid_role)
            await player.edit(roles=updated, reason=
                              'A new day dawns, and all is forgiven')
        stuipd = []

    elif msg.startswith('!reset'):
        day, to_send = cmd.reset(day, message)

    elif msg.startswith('!tick'):
        day = cmd.tick(day)

    elif msg.startswith('!newgame'):
        if playMsg:
            players = []
            for emj in playMsg.reactions:
                players.append(await reaction.users().flatten())
            players = set(players)
            for user in players:
                await user.add_roles(playerRole, reason = 'Assigned player')
        (day, playMsg, admins,
         preconsent, consent,
         adv, to_send) = cmd.newgame(playMsg, admin_role, players, message)

    elif msg.startswith('!ping'):
        to_send = cmd.ping(msgch, day, channels, players, admins)

    if 'react here to play' in msg.lower():
        playMsg = message
        await setupchannel.send('Advanced newgame available '
                                'once players have reacted')

    if adv and pmChannels:
        if msgch in pmChannels:#what the actual f**k was this supposed to be
            init = msg.author
            allow = discord.PermissionsOverwrite
            deny = discord.PermissionsOverwrite
            allow.send_messages = True
            deny.send_messages = False
            if pmChannels[msgch][0] == init:
                reci = pmChannels[msgch][1]
            elif pmChannels[msgch][1] == init:
                reci = pmChannels[msgch][0]
            else:
                return
            if consent[msgch][0] == 'init':
                if (' ' in msg
                        or len(message.mentions !=1
                        or message.mentions[0] != reci)):
                    await msg.delete()
                    warning = await msgch.send('{}, please only mention '
                                               'the other player.'
                                               .format(init.mention))
                    await warning.delete(delay=5)
                else:
                    pmInit[msgch] = msg
                    consent[msgch] = ['wait', reci]
                    await msgch.set_permissions(init, overwrite=deny)
                    await msgch.set_permissions(reci, overwrite=deny)
            if consent[msgch][0] == 'wait':
                if preconsent[reci][1] == 'given':
                    consent[msgch] = ['given']
                    await msgch.set_permissions(init, overwrite=allow)
                    await msgch.set_permissions(reci, overwrite=allow)
                    await pmInit[msgch].delete()
                    pmInit[msgch] = None
                    consent[msgch] = ['given']

    banned = ['uwu', 'uωu', 'uшu']
    delim = [' ','.',',','-','_','+','|','/']
    clean_msg = msg.lower()
    for char in delim:
        clean_msg = clean_msg.replace(char,'')
    for word in banned:
        if word in clean_msg:
            if not to_send[msgch]:
                to_send[msgch] = []
            to_send[msgch].append('***NO UWU***')
            if stupid_role:
                sinner = message.author
                if sinner not in stupid:
                    await sinner.add_roles(stupid_role, reason='Filthy UWUer')
                    stupid.append(sinner)


    for ch in to_send:
        for ms in to_send[ch]:
            await ch.send(ms)
Exemplo n.º 9
0
    def runTest(self, interface):
        """data transfer test"""

        self.appendText('\n*** Start of Test ***\n\n')
        self.appendText(messageForDevice(interface))
        self.appendText('\nProbe Interface: %s\n.' % interface)

        try:
            probe = False

            for probe_count in range(600):
                time.sleep(0.1)
                self.checkStop()

                (rc, host_ip) = commands.getIP(interface)
                if rc:
                    self.appendText('\nHost interface IP Address = ' +
                                    host_ip + '\n')

                    remote_ip = mapIP(host_ip)
                    if remote_ip == '':
                        raise TestException('Remote IP Address not found')

                    self.checkStop()

                    self.appendText('Remote IP Address = ' + remote_ip + '\n')
                    for ping_count in range(5):
                        (rc, out) = commands.ping(remote_ip)
                        if rc:
                            break
                    self.appendText(out + '\n')
                    if not rc:
                        raise TestException(
                            'Remote IP Address is not responding')

                    self.checkStop()

                    self.appendText('\nUpload ssh authentication files\n')
                    (rc, out) = commands.remote(remote_ip,
                                                'mkdir -m 0700 -p .ssh')
                    if not rc:
                        self.appendText(out + '\n')
                        raise TestException(
                            'Unable to create ssh configuration directory')

                    self.checkStop()

                    (rc, out) = commands.sendAuth(remote_ip, PUBLIC_KEY)
                    self.appendText(out + '\n')
                    if not rc:
                        raise TestException('Unable to send Public Key file')
                        break
                    self.checkStop()

                    self.appendText('\n')
                    (output, error,
                     rc) = commands.local('ifconfig ' + interface)
                    if rc == 0:
                        self.appendText(output + '\n')
                    else:
                        self.appendText(error + '\n')
                        raise TestException('Unable to read IP information')

                    self.appendText('\n')
                    probe = True
                    block_count = 0
                    while self.testRunning:
                        block_count += 1

                        self.appendText('%04d Send data.' % block_count)

                        (rc, out, cmd) = commands.sendOneFile(
                            remote_ip, PRIVATE_KEY, self.send, '/tmp/usb.data',
                            self.getPercentage)

                        if self.debug:
                            self.appendText(cmd + ' -> ')
                            self.appendText(out)
                        self.appendText('\n')

                        self.checkStop()

                        self.appendText('%04d Receive data.' % block_count)

                        (rc, out, cmd) = commands.receiveOneFile(
                            remote_ip, PRIVATE_KEY, '/tmp/usb.data',
                            self.receive, self.getPercentage)
                        if self.debug:
                            self.appendText(cmd + ' -> ')
                            self.appendText(out)
                        self.appendText('\n')

                        self.checkStop()
                    break
                elif probe_count != 0:
                    if probe_count % 50 == 0:
                        self.appendText('\n')
                    self.appendText('.')

            self.appendText('\n')
            if probe:
                raise TestException('Connection to remote failed')
        except StopTestException, e:
            if probe:
                (output, error, rc) = commands.local('ifconfig ' + interface)
                if rc == 0:
                    self.appendText(output + '\n')
                else:
                    self.appendText(error + '\n')