Exemple #1
0
def run():
    # test all OK files found
    # Note: txt target is to test the table-to-verbatim mapping
    for outfile in glob.glob("ok/*"):
        stderr = 0
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target)
        if target == 'out':
            target = 'txt'
            stderr = 1
        infile = basename + ".t2t"
        outfile = outfile.replace('ok/', '')

        if lib.initTest(basename, infile, outfile):
            cmdline = ['-H']
            cmdline.extend(['-t', target])
            cmdline.extend(['-i', infile])
            if stderr:
                cmdline.extend(['-o', '-'])
                cmdline.append('>' + outfile)
                cmdline.append('2>&1')
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile))
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #2
0
def run():
	for test in tests:
		infile  = test['name'] + '.t2t'
		outfile = test['name'] + '.' + (test.get('target') or 'out')
		extra   = test.get('extra') or []
		cmdline = test['cmdline']
		if not 'noinfile' in extra:
			cmdline = test['cmdline'] + [infile]
		if lib.initTest(test['name'], infile, outfile):
			# create the extra files (if needed for this test)
			if 'config' in extra:
				lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT)
			if 'css' in extra:
				lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT)
			# may I add the -t target automatically?
			if not 'notarget' in extra:
				cmdline = ['-t', test['target']] + cmdline
			# may I redirect the output to a file?
			if test.get('redir'):
				cmdline = cmdline + test['redir']
			# always catch the error output
			cmdline = cmdline + ['2>&1']
			# create the source file
			lib.WriteFile(infile, test['content'])
			# convert and check results
			lib.convert(cmdline)
			lib.diff(outfile)
			# remove the trash
			os.remove(infile)
			if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE)
			if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE)
	return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #3
0
def run():
	for test in tests:
		infile  = test['name'] + '.t2t'
		outfile = test['name'] + '.' + (test.get('target') or 'out')
		cmdline = test['cmdline'] + [infile]
		extra   = test.get('extra') or []
		if lib.initTest(test['name'], infile, outfile):
			# create the extra files (if needed for this test)
			if 'config' in extra:
				lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT)
			if 'css' in extra:
				lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT)
			if not 'notarget' in extra:
				cmdline = ['-t', test['target']] + cmdline
			if test.get('redir'):
				cmdline = cmdline + test['redir']
			# create the source file
			lib.WriteFile(infile, test['content'])
			# convert and check results
			lib.convert(cmdline)
			lib.diff(outfile)
			# remove the trash
			os.remove(infile)
			if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE)
			if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE)
	return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #4
0
def run():
    # test all .t2t files found
    for infile in glob.glob("*.t2t"):
        basename = infile.replace('.t2t', '')

        # Choose targets
        targets = all_targets
        if basename == 'table':
            targets = tableable

        for target in targets:
            outfile = basename + '.' + target
            outfilelite = basename + '.' + (lib.EXTENSION.get(target)
                                            or target)
            testname = '%s in %s' % (basename, target)
            if lib.initTest(testname, infile, outfile):
                cmdline = []
                cmdline.extend(['-i', infile])
                cmdline.extend(['-t', target])
                if target == 'aap':
                    cmdline.extend(['--width', '80'])
                lib.convert(cmdline)
                lib.diff(outfile)
                lib.convert(cmdline, True)
                lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile))
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #5
0
def run():
	# test all OK files found
	for outfile in glob.glob("ok/*"):
		stderr = 0
		basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
		target = re.sub('.*\.', '', outfile)
		if target == 'out':
			target = 'txt'
			stderr = 1
		infile = basename + ".t2t"
		outfile = outfile.replace('ok/', '')
		if lib.initTest(basename, infile, outfile):
			cmdline = ['-H']
			cmdline.extend(['-t', target])
			cmdline.extend(['-i', infile])
			if stderr:
				cmdline.extend(['-o', '-'])
				cmdline.append('>' + outfile)
				cmdline.append('2>&1')
			lib.convert(cmdline)
			lib.diff(outfile)
	# clean up
	if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE)
	
	return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #6
0
def run():
    # test all OK files found
    # Note: txt target is to test the table-to-verbatim mapping
    for outfile in glob.glob("ok/*"):
        stderr = 0
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target)
        if target == 'out':
            target = 'txt'
            stderr = 1
        infile = basename + ".t2t"
        outfile = outfile.replace('ok/', '')

        if lib.initTest(basename, infile, outfile):
            cmdline = ['-H']
            cmdline.extend(['-t', target])
            cmdline.extend(['-i', infile])
            if stderr:
                cmdline.extend(['-o', '-'])
                cmdline.append('>' + outfile)
                cmdline.append('2>&1')
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile))
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)
    
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #7
0
def run():
    # test all .t2t files found
    for infile in glob.glob("*.t2t"):
        basename = infile.replace('.t2t', '')
        
        # Choose targets
        targets = all_targets
        if basename == 'table':
            targets = tableable
        
        for target in targets:
            outfile = basename + '.' + target
            outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target)
            testname = '%s in %s' % (basename, target)
            if lib.initTest(testname, infile, outfile):
                cmdline = []
                cmdline.extend(['-i', infile])
                cmdline.extend(['-t', target])
                if target == 'aap':
                    cmdline.extend(['--width', '80'])
                lib.convert(cmdline)
                lib.diff(outfile)
                lib.convert(cmdline, True)
                lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile))
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #8
0
def run():
    # test all .t2t files found
    for infile in glob.glob("*.t2t"):
        basename = infile.replace('.t2t', '')
        outfile = basename + '.html'
        if lib.initTest(basename, infile, outfile):
            cmdline = addFilters(FILTERS.get(basename))
            cmdline.append(infile)
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # using smart filters, same files generate more than one output
    for alias in ALIASES.keys():
        infile = ALIASES[alias] + '.t2t'
        outfile = alias + '.html'
        if lib.initTest(alias, infile, outfile):
            cmdline = addFilters(FILTERS.get(alias))
            cmdline.extend(['-o', outfile, infile])
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #9
0
def run():
    # test all .t2t files found
    for infile in glob.glob("*.t2t"):
        basename = infile.replace('.t2t', '')
        outfile = basename + '.html'
        if lib.initTest(basename, infile, outfile):
            cmdline = [infile]
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # using smart filters, same files generate more than one output
    for alias in ALIASES.keys():
        infile = ALIASES[alias] + '.t2t'
        outfile = alias + '.html'
        if lib.initTest(alias, infile, outfile):
            cmdline = addFilters(FILTERS.get(alias))
            cmdline.append('-H')
            cmdline.extend(['-o', outfile, infile])
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)
    
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #10
0
def run():
	for testid in tests.split():
		infile  = testid + '.t2t'
		outfile = testid + '.html'
		cmdline = ['-t html --css-sugar -C test.conf', infile]
		if lib.initTest(testid, infile, outfile):
			# compose source file contents
			infile_txt = []
			for letter in testid:
				infile_txt.append(txt[letter])
			infile_txt = '\n'.join(infile_txt)
			# create the source file
			lib.WriteFile(infile, infile_txt)
			# convert and check results
			lib.convert(cmdline)
			lib.diff(outfile)
			# remove the trash
			os.remove(infile)
	return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #11
0
 def post(self,*args,**kwargs):
     files= self.request.files["file[]"]
     if len(files) == 1:        
         info = matlib.convert(files[0])
         self.write(json_encode(info))
         self.finish()
     elif len(files) == 2:
         info = matlib.extract(files)
         self.write(json_encode(info))
         self.finish()
Exemple #12
0
def run():
    for test in tests:
        target = test.get('target') or 'txt'
        infile = test['name'] + '.t2t'
        outfile = test.get('outfile') or test['name'] + '.' + target
        extra = test.get('extra') or []
        cmdline = ['-i', infile] + test.get('cmdline', [])
        content = test['content']
        if 'noversion' in extra:
            content = VERSION_GOTCHA + content
        if 'error' in extra:
            outfile = test['name'] + '.out'
        if lib.initTest(test['name'], infile, outfile):
            # create the extra files (if needed for this test)
            if 'config' in extra:
                lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT)
            if 'css' in extra:
                lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT)
            # may I add the -t target automatically?
            if not 'notarget' in extra:
                cmdline = ['-t', target] + cmdline
            # may I redirect the output to a file?
            if test.get('redir'):
                cmdline.extend(test['redir'])
            elif 'error' in extra:
                cmdline.append('> %s.out' % test['name'])
            # always catch the error output
            cmdline.append('2>&1')
            # create the source file
            lib.WriteFile(infile, EMPTY_HEADER + content + '\n' + SIMPLE_BODY)
            # convert and check results
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
            # remove the trash
            os.remove(infile)
            if os.path.isfile(lib.CSS_FILE):
                os.remove(lib.CSS_FILE)
            if os.path.isfile(lib.CONFIG_FILE):
                os.remove(lib.CONFIG_FILE)
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #13
0
def run():
    # test all OK files found
    for outfile in glob.glob("ok/*"):
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        infile = basename + ".t2t"
        outfile = outfile.replace('ok/', '')
        if lib.initTest(basename, infile, outfile):
            cmdline = ['-H']
            cmdline.extend(['-t', target])
            cmdline.append(infile)
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #14
0
def run():
    # test all OK files found
    for outfile in glob.glob("ok/*"):
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        infile = basename + ".t2t"
        outfile = outfile.replace('ok/', '')
        if lib.initTest(basename, infile, outfile):
            cmdline = ['-H']
            cmdline.extend(['-t', target])
            cmdline.append(infile)
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)
    
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #15
0
def run():
    for testid in tests.split():
        infile = testid + '.t2t'
        outfile = testid + '.html'
        cmdline = ['-t html --css-sugar -C test.conf', infile]
        if lib.initTest(testid, infile, outfile):
            # compose source file contents
            infile_txt = []
            for letter in testid:
                infile_txt.append(txt[letter])
            infile_txt = '\n'.join(infile_txt)
            # create the source file
            lib.WriteFile(infile, infile_txt)
            # convert and check results
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
            # remove the trash
            os.remove(infile)
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #16
0
def run():
    for test in tests:
        infile = test['name'] + '.t2t'
        outfile = test['name'] + '.' + (test.get('target') or 'out')
        extra = test.get('extra') or []
        cmdline = test['cmdline']
        if not 'noinfile' in extra:
            cmdline = test['cmdline'] + [infile]
        if lib.initTest(test['name'], infile, outfile):
            # create the extra files (if needed for this test)
            if 'config' in extra:
                lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT)
            if 'css' in extra:
                lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT)
            # may I add the -t target automatically?
            if not 'notarget' in extra:
                cmdline = ['-t', test['target']] + cmdline
            # may I remove the SVN revision number?
            if 'norevision' in extra:
                cmdline.append(' | sed "%s;%s"' %
                               (SED_NO_REVISION1, SED_NO_REVISION2))
            # may I redirect the output to a file?
            if test.get('redir'):
                cmdline.extend(test['redir'])
            # always catch the error output
            cmdline.append('2>&1')
            # create the source file
            lib.WriteFile(infile, test['content'])
            # convert and check results
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
            # remove the trash
            os.remove(infile)
            if os.path.isfile(lib.CSS_FILE):
                os.remove(lib.CSS_FILE)
            if os.path.isfile(lib.CONFIG_FILE):
                os.remove(lib.CONFIG_FILE)
    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #17
0
def run():
    # test all OK files found
    for outfile in glob.glob("ok/*"):
        stderr = 0
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        if target == 'out':
            target = 'txt'
            stderr = 1
        infile = basename + ".t2t"
        # Using filename -H suffix to run new tests using -H option
        if basename.endswith('-H'):
            infile = basename.replace('-H', '') + ".t2t"
        outfile = outfile.replace('ok/', '')

        if lib.initTest(basename, infile, outfile):
            cmdline = []
            cmdline = addFilters(FILTERS)
            if basename == 'path':
                cmdline.extend(['--width', '200'])
            if basename.endswith('-H'):
                cmdline.append('-H')
                cmdline.extend(['-o', outfile])
            cmdline.extend(['-t', target])
            cmdline.extend(['-i', infile])
            if stderr:
                cmdline.extend(['-o', '-'])
                cmdline.append('>' + outfile)
                cmdline.append('2>&1')
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #18
0
def run():
    # test all OK files found
    for outfile in glob.glob("ok/*"):
        stderr = 0
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        if target == 'out':
            target = 'txt'
            stderr = 1
        infile = basename + ".t2t"
        # Using filename -H suffix to run new tests using -H option
        if basename.endswith('-H'):
            infile = basename.replace('-H', '') + ".t2t"
        outfile = outfile.replace('ok/', '')

        if lib.initTest(basename, infile, outfile):
            cmdline = []
            cmdline = addFilters(FILTERS)
            if basename == 'path':
                cmdline.extend(['--width', '200'])
            if basename.endswith('-H'):
                cmdline.append('-H')
                cmdline.extend(['-o', outfile])
            cmdline.extend(['-t', target])
            cmdline.extend(['-i', infile])
            if stderr:
                cmdline.extend(['-o', '-'])
                cmdline.append('>' + outfile)
                cmdline.append('2>&1')
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #19
0
def run():
    # test all OK files found
    for outfile in glob.glob("ok/*"):
        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
        target = re.sub('.*\.', '', outfile)
        infile = basename + ".t2t"
        if infile in remote_infiles:
            infile = remote_root + infile
        if basename in remote_mapping:
            infile = remote_root + remote_mapping[basename]
        outfile = outfile.replace('ok/', '')
        if lib.initTest(basename, infile, outfile):
            cmdline = []
            cmdline.extend(['-i', infile])
            if infile.startswith(remote_root) \
                and basename != 'remote-outfile':
                cmdline.extend(['-o', outfile])
            if basename == 'not-found':
                cmdline.append('>' + outfile)
                cmdline.append('2>&1')
            elif basename == 'stdout':
                cmdline.extend(['-o', '-'])
                cmdline.append('>' + outfile)
            elif basename == 'remote-outfile':
                cmdline.append('2>' + outfile)
            elif basename == 'relative-path':
                cmdline.extend(['-t', 'html'])
                cmdline.append('--fix-path')
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)
    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #20
0
def run():

    ### First test the %!includeconf command

    errors = [
        'includeconf-itself',
        'includeconf-not-found',
        'includeconf-targeted',
        'includeconf-text',
        ]
    unnumbered = [
        'includeconf-empty',
        ]

    # test all t2t files found
    for infile in glob.glob("includeconf-*.t2t"):
        basename = infile.replace('.t2t', '')
        outfile = basename + '.html'

        if basename in unnumbered:
            okfile = 'ok/not-numbered.html'
        else:
            okfile = 'ok/numbered.html'

        if basename in errors:
            outfile = basename + '.out'
            okfile = 'ok/' + outfile
            cmdline = ['-H', '-i', infile, '-o- >', outfile, '2>&1']
        else:
            cmdline = ['-H', '-i', infile, '-o', outfile]

        if lib.initTest(basename, infile, outfile, okfile):
            lib.convert(cmdline)
            lib.diff(outfile, okfile)
            lib.convert(cmdline, True)
            lib.diff(outfile, okfile)

    ### Now test -C and --config-file command line options

    errors = ['C-not-found', 'C-text']
    default_cmdline = ['-H -i body-only.t2t']
    infile = 'body-only.t2t'
    for test in tests:

        # --enum-title is used by this test?
        if test.get('not-numbered'):
            okfile = 'ok/not-numbered.html'
        else:
            okfile = 'ok/numbered.html'

        # 1st turn (-C), 2nd turn (--config-file)
        for i in (1, 2):

            if i == 1:
                name = test['name']
                cmdline = test['cmdline']
            else:
                name = test['name'].replace('C', 'config-file')
                cmdline = map(lambda x: x.replace('-C', '--config-file'), test['cmdline'])

            outfile = name + '.html'

            if test['name'] in errors:
                outfile = name + '.out'
                okfile = 'ok/' + outfile
                cmdline = default_cmdline + cmdline + ['-o- >', outfile, '2>&1']
            else:
                cmdline = default_cmdline + cmdline + ['-o', outfile]

            # convert and check results
            if lib.initTest(name, infile, outfile, okfile):
                lib.convert(cmdline)
                lib.diff(outfile, okfile)
                lib.convert(cmdline, True)
                lib.diff(outfile, okfile)

    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
Exemple #21
0
def run():
    # test all .t2t files found
    for infile in glob.glob("*.t2t"):
        basename = infile.replace('.t2t', '')
        outfile = basename + '.html'
        if lib.initTest(basename, infile, outfile):
            cmdline = [infile]
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)

    # extra: bar.t2t as TXT
    infile = 'bar.t2t'
    basename = 'bar'
    outfile = basename + '.txt'
    if lib.initTest(basename, infile, outfile):
        cmdline = ['-t', 'txt', '-i', infile]
        cmdline.extend(['--width', '150'])  # to avoid wrapping
        lib.convert(cmdline)
        lib.diff(outfile)
        lib.convert(cmdline, True)
        lib.diff(outfile)

    # using smart filters, same files generate more than one output
    for alias in ALIASES.keys():
        infile = ALIASES[alias] + '.t2t'
        outfile = alias + '.html'
        if lib.initTest(alias, infile, outfile):
            cmdline = addFilters(FILTERS.get(alias))
            cmdline.append('-H')
            cmdline.extend(['-o', outfile, infile])
            lib.convert(cmdline)
            lib.diff(outfile)
            lib.convert(cmdline, True)
            lib.diff(outfile)

    # extra: bar2.t2t as TXT
    alias = 'bar2'
    infile = ALIASES[alias] + '.t2t'
    outfile = alias + '.txt'
    if lib.initTest(alias, infile, outfile):
        cmdline = addFilters(FILTERS.get(alias))
        cmdline.append('-H')
        cmdline.extend(['--width', '150'])  # to avoid wrapping
        cmdline.extend(['-t', 'txt', '-o', outfile, infile])
        lib.convert(cmdline)
        lib.diff(outfile)
        lib.convert(cmdline, True)
        lib.diff(outfile)

    # clean up
    if os.path.isfile(lib.CONFIG_FILE):
        os.remove(lib.CONFIG_FILE)

    return lib.OK, lib.FAILED, lib.ERROR_FILES
    async def create_giveaway(self, ctx: commands.Context):
        """Allowes you to to create giveaway by answering some simple questions!"""
        # Ask Questions
        embed = Embed(
            title="Giveaway Time!! \U00002728",
            description=
            "Time for a new Giveaway. Answer the following questions in 25 seconds each for the Giveaway",
            color=ctx.author.color,
        )
        await ctx.send(embed=embed)
        questions = [
            "In Which channel do you want to host the giveaway?",
            "For How long should the Giveaway be hosted ? type number followed (s|m|h|d)",
            "What is the Prize?",
            "What role should a person must have in order to enter? If no roles required then type `none`",
            "Tasks that the person should do in order to participate? If no tasks then type `none`",
        ]
        answers = []

        def check(m):
            return m.author == ctx.author and m.channel == ctx.channel

        for i, question in enumerate(questions):
            embed = Embed(title=f"Question {i+1}", description=question)
            await ctx.send(embed=embed)
            try:
                message = await self.bot.wait_for("message",
                                                  timeout=25,
                                                  check=check)
            except TimeoutError:
                await ctx.send("You didn't answer the questions in Time")
                return
            answers.append(message.content)

        # Check if Channel Id is valid
        try:
            channel_id = int(answers[0][2:-1])
        except:
            await ctx.send(
                f"The Channel provided was wrong. The channel provided should be like {ctx.channel.mention}"
            )
            return

        channel = self.bot.get_channel(channel_id)

        # Check if the role is valid
        role = answers[3]
        if role.lower() in ("none", "no", "no roles"):
            role = None
        else:
            try:
                int(answers[3][3:-1])
            except:
                i = ctx.guild.roles
                for j in i:
                    if j.name in ("@everyone", "@here"):
                        i.remove(j)
                bot_roles = choice(i)
                await ctx.send(
                    f"The role provided was wrong. The role should be like {bot_roles.mention}"
                )
                return

        time_ends = convert(answers[1]) * 1000

        # Check if Time is valid
        if time == -1:
            await ctx.send("The Time format was wrong")
            return
        if time == -2:
            await ctx.send("The Time was not conventional number")
            return
        prize = answers[2]

        task = answers[4]
        if task.lower() in ("none", "no", "no task"):
            task = None

        embed = Embed(
            title="**:tada::tada: Giveaway Time !! :tada::tada:**",
            description=f":gift: Win a **{prize}** today",
            colour=0x00FFFF,
        )
        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.display_avatar.url)
        embed.set_image(url=self.giveaway_image)
        embed.add_field(
            name="Giveway ends in",
            value=
            f"{format_relative(discord.utils.utcnow() + timedelta(milliseconds=time_ends))} | [Timer]({LinksAndVars.website.value}/giveaway_timer.html?start={int(time.time() * 1000)}&length={time_ends})",
        )
        if role:
            embed.add_field(name="Role Required", value=f"{role}")
        if task:
            embed.add_field(name="\U0001f3c1 Tasks", value=task)
        newMsg = await channel.send(embed=embed)
        embed.set_footer(text=f"Giveaway ID: {newMsg.id}")
        await newMsg.edit(embed=embed)
        await newMsg.add_reaction(discord.PartialEmoji(name="\U0001f389"))
        await ctx.send(
            f"Your giveaway will be hosted in {channel.mention} and will last for {answers[1]}\n{newMsg.jump_url}"
        )
        await self.create_timer_for_giveaway(
            newMsg, (discord.utils.utcnow() +
                     timedelta(milliseconds=time_ends)).timestamp())
Exemple #23
0
 def _(self, orig, expected):
     observed = lib.convert(orig)
     n.assert_equal(observed, expected)