def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ uploaded_image_data = self.random_parrot() show_image = args[-1] == 'showimage' if args else False if args and args[0] != 'showimage' and self.get_parrot(args[0]): uploaded_image_data = self.get_parrot(args[0]) uploaded_image = uploaded_image_data[0] uploaded_image_dims = uploaded_image_data[1] if User.compareRanks(room.rank, '*') and show_image: return ReplyObject(( '/addhtmlbox <img src="{url}" height="{height}" width={width}></img>' '').format(url=uploaded_image, height=uploaded_image_dims[1], width=uploaded_image_dims[0]), True, True) else: return ReplyObject(uploaded_image, True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ gameid = args[0] show_image = args[-1] == 'showimage' if args else False game_url = 'https://store.steampowered.com/app/{}'.format(gameid) steaminfo = {'appids': gameid} r = requests.get('http://store.steampowered.com/api/appdetails', params=steaminfo) game_data = r.json()[gameid]['data'] header_image, name, description = game_data['header_image'], game_data[ 'name'], game_data['short_description'] width, height = OnlineImage.get_image_info(header_image) if User.compareRanks(room.rank, '*') and show_image: res = ReplyObject(( '/addhtmlbox <div id="gameinfo"> <img src="{}" height="{}" width="{}"></img> <p>Name: <a href="{}"> {}</a></p> <p>Description: {} </p> </div>' ).format(header_image, height, width, game_url, name, description), True, True) print(res.text) return res else: return ReplyObject( 'Name: {} Link: Description: {}'.format( name, game_url, description), True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject Raises: LatexParsingException: there was an issue parsing the document """ showimage = True if len( args) == 1 and args[0] == 'showimage' else False uploaded_image_data = self._upload_random_problem() uploaded_image = uploaded_image_data[0] uploaded_image_dims = uploaded_image_data[1] if showimage: return ReplyObject( '/addhtmlbox <img src="{url}" height="{height}" width="{width}"></img>' .format(url=uploaded_image_data, height=uploaded_image_dims[1], width=uploaded_image_dims[0]), True, True) else: return ReplyObject('{url}'.format(url=uploaded_image), True)
def test_xkcd(): cmd = Xkcd() reply = cmd.response(test_room, test_user, []) assert reply.text.startswith('https'), "xkcd command proper url isn't sent" reply = cmd.response(test_room, test_user, ['1']) answer = ReplyObject('https://imgs.xkcd.com/comics/barrel_cropped_(1).jpg', True) assert reply == answer, 'xkcd command individual xkcd article not found' reply = cmd.response(test_room, test_user, ['rand']) assert reply.text.startswith( 'https'), 'xkcd command rand xkcd article not found' test_room.rank = '*' reply = cmd.response(test_room, test_user, ['rand', 'showimage']) assert reply.text.startswith( '/addhtmlbox'), 'xkcd command rand showimage xkcd article not found' test_room.rank = ' ' test_room.rank = '*' reply = cmd.response(test_room, test_user, ['showimage']) assert reply.text.startswith( '/addhtmlbox'), 'xkcd command recent showimage xkcd article not found' test_room.rank = ' ' reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject(( "Responds with url to xkcd article. if left empty, returns most recent. If 'rand' is passed generates a random article. " "If a 'number' is passed, returns that specified xkcd article. This command also supports showimages." ), True) assert reply == answer, 'xkcd command help function is incorrect'
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ uploaded_image_data = self.handle_request(args[0]) uploaded_image = uploaded_image_data[0] uploaded_image_dims = uploaded_image_data[1] show_image = args[-1] == 'showimage' if User.compareRanks(room.rank, '*') and show_image: # don't render to 100% of screen because latex renders badly return ReplyObject( '/addhtmlbox <img src="{url}" height="{height}" width="{width}"></img>' .format(url=uploaded_image, height=uploaded_image_dims[1], width=uploaded_image_dims[0]), True, True) else: return ReplyObject(uploaded_image, True)
def test_commands_delegation(): cmd_out = Command(None, 'send', test_room, 'testing', test_owner) answer = ReplyObject('testing', True, True) assert cmd_out == answer, "delegation to modules doesn't work" cmd_out = Command(None, 'machine', test_room, '', test_user) answer = ReplyObject('I am the machine!', True) assert cmd_out == answer, "delegation to modules doesn't work" cmd_out = Command(None, 'secret', test_room, '', test_owner) answer = ReplyObject('This is a secret command!', True) assert cmd_out == answer, "delegation to secret commands doesn't work"
def test_dilbert(): cmd = Dilbert() reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject(( "Responds with url to random xkcd article, number can also be specified. And this command " "supports showimages."), True) assert reply == answer, 'Help command for Dilbert is incorrect' reply = cmd.response(test_room, test_user, []) assert reply.text.startswith('http'), 'Dilbert command url not generated.' reply = cmd.response(test_room, test_user, ['args1', 'args2']) answer = ReplyObject("This command doesn't take any arguments", True) assert reply == answer, 'arguments passed to Dilbert command when they should not'
def test_send(): cmd = Send() reply = cmd.response(test_room, test_user, ['hi']) answer = ReplyObject("This command is reserved for this bot's owner", True) assert reply == answer, 'send command does not handle permissions correctly' reply = cmd.response(test_room, test_owner, ['hi']) answer = ReplyObject('hi', True, True) assert reply == answer, "send command's success output is incorrect" reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject( 'Responds with arguments passed to this command, reserved for bot owner', True) assert reply == answer, "send command's help output incorrect"
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ if len(args) == 2: return ReplyObject(str(self.solve_on_standard_posix(args[0], args[1])), True) else: return ReplyObject(str(self.solve_on_standard_posix(args[0])), True)
def test_credits(): cmd = Credits() reply = cmd.response(test_room, test_user, []) answer = ReplyObject( "Source code can be found at: https://github.com/wgma00/quadbot/", True) assert reply == answer, "Credit command's success output is incorrect" reply = cmd.response(test_room, test_owner, ['arg1', 'arg2']) answer = ReplyObject("This command doesn't take any arguments", True) assert reply == answer, "Credit command shouldn't take any arguments" reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject("Responds with url to this bot's source code", True) assert reply == answer, "Credit command's help output incorrect"
def test_machine(): cmd = Machine() reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject( "Responds with I am the machine! [[The Machine - Bert Kreischer: THE MACHINE]]", True) assert reply == answer, "Help command output isn't correct" reply = cmd.response(test_room, test_user, ["whodamachine?"]) answer = ReplyObject("This command doesn't take any arguments", True) assert reply == answer, "Help command Amount of arguments taken is incorrect" reply = cmd.response(test_room, test_user, []) answer = ReplyObject("I am the machine!", True) assert reply == answer, "Help command success output not correct"
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ msg = args[0] if args else 'rand' show_image = args[-1] == 'showimage' if args else False r = requests.get('http://xkcd.com/info.0.json') data = r.json() uploaded_image = data['img'] uploaded_image_dims = OnlineImage.get_image_info(uploaded_image) alt_data = data['alt'] if msg and msg == 'rand': msg = random.randint(1, data['num']) r = requests.get( 'http://xkcd.com/{num}/info.0.json'.format(num=int(msg))) data = r.json() uploaded_image = data['img'] uploaded_image_dims = OnlineImage.get_image_info(uploaded_image) alt_data = data['alt'] elif msg and msg.isdigit() and 1 <= int(msg) <= data['num']: r = requests.get( 'http://xkcd.com/{num}/info.0.json'.format(num=int(msg))) data = r.json() uploaded_image = data['img'] uploaded_image_dims = OnlineImage.get_image_info(uploaded_image) alt_data = data['alt'] if User.compareRanks(room.rank, '*') and show_image: return ReplyObject( ('/addhtmlbox <img src="{url}" height=100% width=100%></img>' '<br><b>{alt}</b></br>').format(alt=alt_data, url=uploaded_image, width=uploaded_image_dims[0]), True, True) else: return ReplyObject(uploaded_image, True)
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'internal_error': return ReplyObject("There was an internal error", True) elif reason == 'too_many_args': return ReplyObject('This command supports only 1 substitution for value x', True) elif reason == 'not_enough_args': return ReplyObject('There should be an expression optionally followed by substitution', True)
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'too_many_args': return ReplyObject("This command doesn't take any arguments", True) if reason == 'incorrect_args': return ReplyObject( 'first argument should be a number if you want a specific xkcd article, otherwise rand to chose a random article.', True)
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'too_many_args': return ReplyObject('This command does not take any arguments', True) elif reason == 'insufficient_room_rank': return ReplyObject( 'This bot requires * or # rank to showimage in chat', True) elif reason == 'show_image_pms': return ReplyObject('This bot cannot showimage in PMs.', True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject("Responds with I am the machine! [[The Machine - Bert Kreischer: THE MACHINE]]", True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject("Responds with url to this bot's source code", True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject('http://dilbert.com/strip/' + time.strftime("%Y-%m-%d"), True)
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'too_many_args': return ReplyObject("This command only takes 1 argument", True) elif reason == 'invalid_arg': return ReplyObject("You have provided an invalid argument", True) elif reason == 'pms': return ReplyObject("There are no broadcast ranks in PMs", True) elif reason == 'insufficient_rank': return ReplyObject("This command is reserved for Room Owners(#)", True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ if len(args) == 0: return ReplyObject('Rank required to broadcast: {rank}'.format( rank=room.broadcast_rank)) else: broadcast_rank = ' ' if args[0] == 'off' else args[0] room.broadcast_rank = broadcast_rank return ReplyObject( 'Broadcast rank set to {rank}. (This is not saved on reboot)'. format(rank=broadcast_rank if not broadcast_rank == ' ' else 'none'), True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject(args[0], True, True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject('Calculator functionality through GNOME Calculator. Supports substitution for a value x', True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject(("Responds with url to random xkcd article, number can also be specified. And this command " "supports showimages."), True)
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'incorrect_args': return ReplyObject( 'Correct args are nothing or something on http://cultofthepartyparrot.com/', True) elif reason == 'insufficient_room_rank': return ReplyObject( 'This bot requires * or # rank to showimage in chat', True) if reason == 'too_many_args': return ReplyObject( 'Too many argsuments passed, takes at most 2 arguments.', True)
def _success(self, room, user, args): """ Returns a success response to the user. Successfully returns the expected response from the user based on the args. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject('Source code can be found at: {url}'.format( url='https://github.com/wgma00/quadbot/'))
def test_parrot(): cmd = PartyParrot() reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject(( 'If left empty prints a url to a random parrot from http://cultofthepartyparrot.com/, ' 'otherwise you may choose to print a specific url. This command supports showimages.' ), True) assert reply == answer, 'help for party parrot is not correct' reply = cmd.response(test_room, test_user, ['sirocco']) answer = ReplyObject('http://cultofthepartyparrot.com/assets/sirocco.gif', True) assert reply == answer, 'stuff' reply = cmd.response(test_room, test_user, ['sirocco', 'showimage']) answer = ReplyObject('This bot requires * or # rank to showimage in chat', True) assert reply == answer, 'stuff' test_room.rank = '*' reply = cmd.response(test_room, test_user, ['sirocco', 'showimage']) assert reply.text.startswith('/addhtmlbox'), 'stuff'
def test_putnam_problem(): cmd = Putnam() reply = cmd.response(test_room, test_user, ['help']) answer = ReplyObject( 'This generates a link to a random putnam problem from {start} to {end} and supports showimages' .format(start=1985, end=2016), True) assert reply == answer, 'help output for putnam problem is incorrect.' test_room.rank = '*' test_room.isPM = False reply = cmd.response(test_room, test_user, ['showimage']) assert reply.text.startswith( '/addhtmlbox'), "show imaging doesn't work in putnam_problem"
def _error(self, room, user, reason): """ Returns an error response to the user. In particular gives a helpful error response to the user. Errors can range from internal errors to user input errors. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. reason: str, reason for this error. Returns: ReplyObject """ if reason == 'too_many_args': return ReplyObject("This command doesn't take any arguments", True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject( 'Responds with arguments passed to this command, reserved for bot owner', True)
def _help(self, room, user, args): """ Returns a help response to the user. In particular gives more information about this command to the user. Args: room: Room, room this command was evoked from. user: User, user who evoked this command. args: list of str, any sequence of parameters which are supplied to this command Returns: ReplyObject """ return ReplyObject( "For now supply the steamid for the game you want more info for i.e. dark souls 3 is 374320", True)