示例#1
0
async def approveSimpleCommand(context, id: int = 1):
    'Approves a command. Request queue is 1-indexed'

    # Assert privilege
    if context.message.author.id != args.config['adminId']:
        await bot.say('Denied')
        return

    # Assert valid id
    if not 1 <= id <= len(commandRequests):
        await bot.say('Invalid request id')
        return

    # Instatiate command and remove from requests queue
    command = commandRequests.pop(id - 1)
    bot.command(name=command.regex,
                help=command.message,
                server=command.server)(makeSayWrapper(command.message))

    # Add to simple commands JSON file
    global simpleCommands
    simpleCommands += [command]
    with open('commands.json', 'w') as f:
        json.dump(simpleCommands, f, indent=4)

    await bot.say(f'Approved command: {command.regex}')
示例#2
0
def add_message_to_db(data):
    message_type = get_message_type(data["message"])
    user = models.Users.query.get(user_emails[request.sid])
    db.session.add(models.Chat(user.email, data["message"], message_type))
    db.session.commit()

    bot_answer = bot.command(data["message"])
    if bot_answer:
        db.session.add(models.Chat(BOT_NAME, bot_answer, "text"))
        db.session.commit()
示例#3
0
async def approveSimpleCommand(context, id: int = 1):
    'Approves a command. Request queue is 1-indexed'

    # Assert privilege
    if context.message.author.id != args.config['adminId']:
        await bot.say('Denied')
        return

    # Assert valid id
    if not 1 <= id <= len(commandRequests):
        await bot.say('Invalid request id')
        return

    # Instatiate command and remove from requests queue
    command = commandRequests.pop(id - 1)
    bot.command(name = command.regex, help = command.message, server = command.server)(makeSayWrapper(command.message))

    # Add to simple commands JSON file
    global simpleCommands
    simpleCommands += [command]
    with open('commands.json', 'w') as f:
        json.dump(simpleCommands, f, indent = 4)

    await bot.say(f'Approved command: {command.regex}')
示例#4
0
文件: run.py 项目: digideskio/devobot
import bot, config

for login in config.logins:
    bot.login(login)
while True:
    msg = raw_input("> ")
    for client in bot.clients():
        bot.command(client, msg)

示例#5
0
try:
    with open('commands.json') as f:
        simpleCommands = [SimpleCommand(*command) for command in json.load(f)]
except FileNotFoundError as e:
    pass


def makeSayWrapper(message):
    async def wrapper():
        await bot.say(message)

    return wrapper


for command in simpleCommands:
    bot.command(command.regex, server=command.server,
                help=command.message)(makeSayWrapper(command.message))

commandRequests = []

# Load RAM map
ramMap = {}

with open('RAM map.asm', 'r') as f:
    for line in f:
        if 'VRAM during main gameplay' in line:
            break

        match = re.match(r'\s*\$([0-9A-F]+)(?::([0-9A-F]+))?(:|\.\.).+', line,
                         re.IGNORECASE)
        if not match:
            continue
示例#6
0
import bot, config

for login in config.logins:
    bot.login(login)
while True:
    msg = raw_input("> ")
    for client in bot.clients():
        bot.command(client, msg)
示例#7
0
 def test_command_failure(self):
     for test in self.failure_test_params:
         response = command(test[KEY_INPUT])
         expected = test[KEY_EXPECTED]
         self.assertNotEqual(response, expected[KEY_BOT_ANSWER])
示例#8
0
 def test_command_success(self):
     for test in self.success_test_params:
         response = command(test[KEY_INPUT])
         expected = test[KEY_EXPECTED]
         self.assertEqual(response, expected[KEY_BOT_ANSWER])
示例#9
0
 def test_funtranslate_key_error(self):
     for test in self.keyerror_funtranslate_test_params:
         with mock.patch("requests.get", mocked_request_get_keyerror):
             response = command(test[KEY_INPUT])
             expected = test[KEY_EXPECTED]
             self.assertEqual(response, expected[KEY_BOT_ANSWER])
示例#10
0
 def test_8ball_success(self):
     for test in self.success_8ball_test_params:
         with mock.patch("requests.get", mocked_8ball_request_get):
             response = command(test[KEY_INPUT])
             expected = test[KEY_EXPECTED]
             self.assertEqual(response, expected[KEY_BOT_ANSWER])
示例#11
0
 def test_roll_success(self):
     for test in self.success_roll_test_params:
         with mock.patch("random.randint", mocked_random_int):
             response = command(test[KEY_INPUT])
             expected = test[KEY_EXPECTED]
             self.assertEqual(response, expected[KEY_BOT_ANSWER])
示例#12
0
SimpleCommand = namedtuple('SimpleCommand', ['server', 'regex', 'message'])
simpleCommands = []
try:
    with open('commands.json') as f:
        simpleCommands = [SimpleCommand(*command) for command in json.load(f)]
except FileNotFoundError as e:
    pass

def makeSayWrapper(message):
    async def wrapper():
        await bot.say(message)

    return wrapper

for command in simpleCommands:
    bot.command(command.regex, server = command.server, help = command.message)(makeSayWrapper(command.message))

commandRequests = []

# Load RAM map
ramMap = {}

with open('RAM map.asm', 'r') as f:
    for line in f:
        if 'VRAM during main gameplay' in line:
            break

        match = re.match(r'\s*\$([0-9A-F]+)(?::([0-9A-F]+))?(:|\.\.).+', line, re.IGNORECASE)
        if not match:
            continue
示例#13
0
def command(*args):
    bot.command(*args)