async def clense(message, keywords): if message.channel.permissions_for(message.author).manage_messages: try: amount = 100 try: amount = int(keywords[0]) except IndexError: pass if amount <= 0: raise ValueError await client.purge_from( message.channel, limit=amount + 1, check=lambda m: m.author.bot or m.content.startswith("&")) log.log( 0, "Clensed %s messages from channel #%s:%s, at request of @%s:%s" % (amount, message.channel.name, message.channel.id, message.author.name, message.author.id)) except (ValueError): raise utils.ArgumentError(None, message) else: raise utils.PermissionError("permissions.manage_messages", message)
async def badge(message, keywords): if message.channel.permissions_for(message.author).administrator: try: badge = keywords[0] user_id = ''.join(filter(lambda x: x.isdigit(), keywords[1])) user = server.get_member(user_id) nick = user.nick if user.nick else user.name await client.change_nickname(user, badge + nick) log.log(0, "Gave user @%s:%s bdage %s " % (user.name, user.id, badge)) except (IndexError, AttributeError): raise utils.ArgumentError(None, message) else: raise utils.PermissionError("permissions.administrator", message)
async def spamme(message, keywords): try: amount = 100 try: amount = int(keywords[0]) except IndexError: pass if amount <= 0: raise ValueError for i in range(amount): await client.send_message(message.author, ":b:" * 100) log.log( 0, "Spamming @%s:%s with %s messages (:b: * 100)" % (message.author.name, message.author.id, amount)) except (IndexError, AttributeError, ValueError): raise utils.ArgumentError(None, message)
def parse_cmd_args(): parser = OptionParser(usage="%prog [options]", version="%prog @KIT_VERSION@") parser.add_option("-d", "--debug", dest="debug", action="store_const", const=True, default=False, help="Run in debug mode, exit on failure") parser.add_option( "-t", "--vlantag", dest="vlan", default="trunk", help= "Specify a VLAN tag ID for which your switches have been configured") parser.add_option( "-g", "--generate", dest="generate", action="store_const", const=True, default=False, help="Generate the config file only. Do not run the tests yet.") parser.add_option("-l", "--list", dest="list_tests", action="store_const", const=True, default=False, help="List all of the test methods") parser.add_option( "-i", "--info", dest="info", help="Print out information about a specified test name.") parser.add_option( "-m", "--mode", dest="mode", default="ALL", help= "Specify the type of certification you wish to perform. (ALL (default) | NET | LSTOR | CPU | OPS)." ) parser.add_option( "-e", "--exclude", dest="exclude", action="append", default=[], help= "Exclude one or multiple set of tests. (OVS | BRIDGE | LSTOR | CPU | OPS | CRASH)." ) parser.add_option("-n", "--netconf", dest="netconf", help="Specify the network config file.") # The option string is an extension, allowing users to specify KVPs # e.g. optionstr = "dhcp=True,key1=val1,..." parser.add_option("-o", "--option", dest="optionstr", help="Specify extra options.") (options, _) = parser.parse_args() config = {} config['debug'] = options.debug if options.vlan: config['vlan_id'] = options.vlan if options.generate: config['generate'] = True if options.info: print_documentation(options.info) if options.netconf: assert_file_exists(options.netconf, 'Network config') config['netconf'] = parse_netconf_file(options.netconf) else: raise utils.ArgumentError( "You must specify a network configuration file. %s" % options.mode) config['mode'] = options.mode config['exclude'] = options.exclude utils.log.debug("Test Mode: %s" % options.netconf) if options.list_tests: print_all_test_classes() if options.optionstr: kvp_rec = kvp_string_to_rec(options.optionstr) for k, v in kvp_rec.iteritems(): config[k] = v # Check if files exist file_opts = [("vpx_dlvm_file", "VPX DLVM file")] for opt, label in file_opts: if opt in config.keys(): assert_file_exists(os.path.join(INSTALL_DIR, config[opt]), label) for key, value in config['netconf'].iteritems(): if key.startswith('eth'): vf_driver_pkg = value['vf_driver_pkg'] if vf_driver_pkg: assert_file_exists(os.path.join(INSTALL_DIR, vf_driver_pkg), "VF driver rpm package") return config