Exemplo n.º 1
0
    async def get_fields(self):
        own_player = await self.own_record.get_related(
            'player') if self.own_record else None
        compare_player = await self.compare_record.get_related('player')

        return [
            {
                'name': 'Checkpoint',
                'index': 'cp',
                'sorting': False,
                'searching': False,
                'width': 40,
                'type': 'label'
            },
            {
                'name':
                '#{}: $n{}'.format(self.own_rank,
                                   style_strip(own_player.nickname))
                if self.own_rank else '-',
                'index':
                'own_time',
                'sorting':
                False,
                'searching':
                False,
                'width':
                70
            },
            {
                'name':
                '#{}: $n{}'.format(self.compare_rank,
                                   style_strip(compare_player.nickname)),
                'index':
                'compare_time',
                'sorting':
                False,
                'searching':
                False,
                'width':
                70,
            },
            {
                'name': 'Difference',
                'index': 'difference',
                'sorting': False,
                'searching': False,
                'width': 50,
                'type': 'label'
            },
        ]
Exemplo n.º 2
0
	async def on_map_begin(self, map, **kwargs):
		is_active  = await self.setting_dynatime_active.get_value()

		if not is_active:
			return

		multiplier = await self.setting_dynatime_multiplier.get_value(refresh=True)
		
		mode_settings = await self.instance.mode_manager.get_settings()

		if 'S_TimeLimit' not in mode_settings:
			raise ModeIncompatibe('Current mode doesn\'t support Dynatime. Not TimeAttack?')

		timelimit = int(multiplier * map.time_bronze / 1000)
		timelimit_ms = timelimit * 1000;

		mode_settings['S_TimeLimit'] = timelimit


		bm_time = format_time( time=map.time_bronze, hide_milliseconds=True)
		new_time = format_time( time=timelimit_ms, hide_milliseconds=True)
		mname = style_strip( map.name, STRIP_ALL)
		chat_message = "$FF0$oDynatime$z set new timelimit for map $fff%s$z$ff0 to $fff⏳ %s$ff0, based on the bronze-medal of $fff🏆 %s$z" % ( mname, new_time, bm_time )

		await self.instance.mode_manager.update_settings(mode_settings)
	
		announce = await self.setting_dynatime_announce.get_value()
		if announce:
			await self.instance.chat(chat_message)
Exemplo n.º 3
0
 async def get_fields(self):
     return [
         {
             'name': 'Checkpoint',
             'index': 'cp',
             'sorting': False,
             'searching': False,
             'width': 40,
             'type': 'label'
         },
         {
             'name':
             '#{}: $n{}'.format(self.own_record.rank,
                                style_strip(self.own_record.nickname)),
             'index':
             'own_time',
             'sorting':
             False,
             'searching':
             False,
             'width':
             70
         },
         {
             'name':
             '#{}: $n{}'.format(self.compare_record.rank,
                                style_strip(self.compare_record.nickname)),
             'index':
             'compare_time',
             'sorting':
             False,
             'searching':
             False,
             'width':
             70,
         },
         {
             'name': 'Difference',
             'index': 'difference',
             'sorting': False,
             'searching': False,
             'width': 50,
             'type': 'label'
         },
     ]
Exemplo n.º 4
0
 async def output_deprecated(self):
     msg = [
         '$f00$o\uf0a1 $z$s$f00$o$wDEPRECATION:$z$s$f55$o Please change your settings! $z$f55$s(\uf121 apps.py)',
         '$f55Replace \'pyplanet.apps.contrib.mapinfo\' by \'pyplanet.apps.contrib.info\'.',
         '$f55MapInfo will be removed in $o0.7.0$o and will break your installation!'
     ]
     for m in msg:
         logging.error(style.style_strip(m))
     await self.instance.chat.execute(*msg)
Exemplo n.º 5
0
	async def delete_record(self, player, values, data, view, **kwargs):
		if not await self.app.instance.permission_manager.has_permission(player, 'local_records:manage_records'):
			return await self.app.instance.chat('$ff0You do not have permissions to manage local records!', player)

		try:
			record = await self.app.get_local(id=data['id'])
		except:
			return

		if not await ask_confirmation(player, 'Are you sure you want to remove record {} by {}'.format(
			format_time(record.score), style_strip((await record.get_related('player')).nickname)
		), size='sm'):
			await self.app.delete_record(record)
			await self.app.refresh()
			await self.refresh(player)
Exemplo n.º 6
0
	async def command_queue_list(self, player, *args, **kwargs):
		"""
		/queue command

		:param player: Player instance
		"""
		nicknames = [style.style_strip(p.nickname, style.STRIP_SIZES, style.STRIP_COLORS) for p in await self.list.copy()]
		if nicknames:
			await self.instance.chat(
				'$39fCurrent queue: $fff{}'.format('$39f,$fff '.join(nicknames)), player
			)
		else:
			await self.instance.chat(
				'$39fThere is nobody in the waiting queue!', player
			)
Exemplo n.º 7
0
	async def apply_filter(self, frame):
		if not self.search_text:
			return frame
		query = list()
		for field in await self.get_fields():
			if 'searching' in field and field['searching']:
				if 'search_strip_styles' in field and field['search_strip_styles']:
					query.append(
						frame[field['index']].apply(lambda x: self.search_text.lower() in style.style_strip(x.lower()))
					)
				else:
					query.append(
						frame[field['index']].apply(lambda x: self.search_text.lower() in x.lower())
					)
		if query:
			query = np.logical_or.reduce(query)
			return frame.loc[query]
		return frame
Exemplo n.º 8
0
    async def map_begin(self, map, **kwargs):
        if not await self.setting_dynatime_active.get_value():
            return

        clip = lambda x, l, u: l if x < l else u if x > u else x

        announce_string = await self.setting_dynatime_announce_string.get_value(
        )
        medal = clip(await self.setting_dynatime_medal.get_value(), 0, 3)
        multiplier = clip(await self.setting_dynatime_multiplier.get_value(),
                          1, 10)
        min_time = max(await self.setting_dynatime_minimum_time.get_value(), 0)
        max_time = max(await self.setting_dynatime_maximum_time.get_value(), 0)
        formula = await self.setting_dynatime_formula.get_value()
        roundto = clip(await self.setting_dynatime_round_time.get_value(), 0,
                       30)

        mode_settings = await self.instance.mode_manager.get_settings()

        if 'S_TimeLimit' not in mode_settings:
            raise ModeIncompatible(
                'Current mode doesn\'t support Dynatime. Not TimeAttack?')

        if '{medal_time}' not in formula or '{multiplier}' not in formula:
            message = '$0b3Error: Dynatime formula does not contain all necessary variables.'
            logger.error(
                'Dynatime formula does not contain all necessary variables!')
            await self.instance.chat(message)
            return

        medals = ['bronze', 'silver', 'gold', 'author']
        medal_time = eval('map.time_{0}'.format(medals[medal]))
        if map.num_laps > 0:
            medal_time /= map.num_laps

        if max_time <= min_time:
            if min_time <= self.setting_dynatime_minimum_time:
                max_time = self.setting_dynatime_maximum_time.default
            else:
                max_time = int(self.setting_dynatime_maximum_time.default /
                               self.setting_dynatime_minimum_time.default *
                               min_time)
        try:
            timelimit = int(
                eval(
                    formula.format(medal_time=medal_time / 1000,
                                   multiplier=multiplier,
                                   min_time=min_time,
                                   max_time=max_time)))
            timelimit = clip(timelimit, min_time, max_time)
            if roundto > 0:
                timelimit = timelimit // 60 * 60 + roundto * (
                    (timelimit % 60 // roundto) +
                    (1 if
                     ((timelimit % 60) % roundto) / roundto >= 0.5 else 0))
            timelimit_ms = timelimit * 1000
        except:
            message = '$0b3Error: Dynatime formula can not be executed successfully.'
            logger.error('Dynatime formula can not be executed successfully!')
            await self.instance.chat(message)
            return

        mode_settings['S_TimeLimit'] = timelimit

        try:
            message = announce_string.format(
                map=style_strip(map.name, STRIP_ALL),
                medal=medals[medal],
                new_time=format_time(time=timelimit_ms,
                                     hide_milliseconds=True),
                medal_time=format_time(time=medal_time,
                                       hide_milliseconds=True))
        except:
            message = '$0b3Error: Dynatime announce string is not formatted correctly.'
            logger.error(
                'Dynatime announce string is not formatted correctly!')
            await self.instance.chat(message)
            return

        await self.instance.mode_manager.update_settings(mode_settings)

        announce = await self.setting_dynatime_announce.get_value()
        if announce:
            await self.instance.chat(message)
Exemplo n.º 9
0
def test_style_stripping():
    # Colors
    raw = '$i$fffMax$06fSmurf$f00.$fffes$$l$09f.$fffm$08f$a5x$n$w$o'
    expect = '$iMaxSmurf.es$$l.m$a5x$n$w$o'
    assert style.style_strip(raw, style.STRIP_COLORS) == expect

    raw = '$l[some link]$i$FFFMax$06fSmurf$f00.$fffesl$09f.$fffm$08fx$l'
    expect = '$l[some link]$iMaxSmurf.esl.mx$l'
    assert style.style_strip(raw, style.STRIP_COLORS) == expect

    raw = '$l[some link]$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08fx'
    expect = '$l[some link]$iMaxSmurf.esl.mx'
    assert style.style_strip(raw, style.STRIP_COLORS) == expect

    # Links
    raw = '$l$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08f$a5x$l'
    expect = '$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08f$a5x'
    assert style.style_strip(raw, style.STRIP_LINKS) == expect

    raw = '$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08f$a5x'
    expect = '$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08f$a5x'
    assert style.style_strip(raw, style.STRIP_LINKS) == expect

    raw = '$l[some link]$i$fffMax$06fSmurf$f00.$fffes$$l$09f.$fffm$08fx$l'
    expect = '$i$fffMax$06fSmurf$f00.$fffes$$09f.$fffm$08fx'
    assert style.style_strip(raw, style.STRIP_LINKS) == expect

    raw = '$l[some link]$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08fx'
    expect = '$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08fx'
    assert style.style_strip(raw, style.STRIP_LINKS) == expect

    # Sizes
    raw = '$i$n$fffMax$06fSmurf$f00.$w$o$fffe$$nsl$09f.$w$fffm$08f$a5$ox'
    expect = '$fffMax$06fSmurf$f00.$fffe$sl$09f.$fffm$08f$a5x'
    assert style.style_strip(raw, style.STRIP_SIZES) == expect

    # All
    raw = '$h$i$fffMax$06fSmurf$f00.$fffesl$09f.$fffm$08f$a5x$h'
    expect = 'MaxSmurf.esl.m$a5x'
    assert style.style_strip(raw) == expect

    raw = '$l[some link]$i$fffMax$06fSmur$$f$f00.$fffesl$09f.$fffm$08fx$l'
    expect = 'MaxSmur$$f.esl.mx'
    assert style.style_strip(raw) == expect

    raw = '$l[some link]$i$fffMax$06fSmu$nrf$f00.$fffesl$09f.$fffm$08fx'
    expect = 'MaxSmurf.esl.mx'
    assert style.style_strip(raw) == expect

    # Combination & Misc
    raw = '$f80$i$oToffe$g$z$06fSmurf $z$sHello'
    expect = 'Toffe$zSmurf $zHello'
    assert style.style_strip(raw, keep_reset=True) == expect

    raw = '$f80$i$oToffe$g$z$06fSmurf $z$sHello'
    expect = 'ToffeSmurf $sHello'
    assert style.style_strip(raw, style.STRIP_SIZES,
                             style.STRIP_COLORS) == expect