Exemplo n.º 1
0
def cmd_list(request):

    args = request.args
    config = request.config

    language = parse_opts_lang(request)

    selected_units = parse_opts_unit_names(request)
    if not selected_units:
        return error_no_unit_selected()

    if args:
        return error_unknown_parameters(args)

    msgs = []
    translations = []
    for unit in selected_units:
        translated_name = get_unit_name(unit.base_id, language)
        translations.append(translated_name)

    unit_list = '\n- '.join(translations)
    return [{
        'title':
        'Unit List',
        'description':
        'Here is the list of units you selected:\n- %s\n' % unit_list,
    }]
    def prepare_message(self, config, message):

        if 'key' in message and 'nick' in message and 'ally.code' in message:
            prep_key = '%s.%s.mention' % (message['key'], message['ally.code'])
            if prep_key in config and config[prep_key] is not False:
                prep_nick = self.prepare_nick(message['ally.code'])
                if prep_nick:
                    message['nick'] = prep_nick

        if 'unit' in message:
            message['unit'] = get_unit_name(message['unit'],
                                            config['language'])

        if 'gear.level' in message:
            gear_level = message['gear.level']
            message['gear.level.roman'] = ROMAN[gear_level]

        if 'gear.piece' in message:
            message['gear.piece'] = translate(message['gear.piece'],
                                              config['language'])

        if 'skill' in message:
            message['skill.id'] = message['skill']
            message['skill'] = get_ability_name(message['skill'],
                                                config['language'])

        if 'tier' in message:

            message['type'] = ''
            if message['tier'] >= MAX_SKILL_TIER:
                try:
                    skill = BaseUnitSkill.objects.get(
                        skill_id=message['skill.id'])
                    message['type'] = skill.is_zeta and 'zeta' or 'omega'

                except BaseUnitSkill.DoesNotExist:
                    self.logger.error(
                        'Could not find base unit skill with id: %s' %
                        message['skill.id'])

        return message
Exemplo n.º 3
0
async def cmd_relic(request):

    args = request.args
    author = request.author
    config = request.config

    language = parse_opts_lang(request)

    limit = 25
    relic_tier = parse_opts_relic_tier(request)
    relic_field = 'relic%d_percentage' % relic_tier
    relic_filter = '-%s' % relic_field
    include_locked = parse_opts_include_locked(request)

    selected_players, error = parse_opts_players(request,
                                                 min_allies=1,
                                                 max_allies=1)

    if error:
        return error

    if not selected_players:
        return error_no_ally_code_specified(config, author)

    if args:
        return error_unknown_parameters(args)

    ally_code = selected_players[0].ally_code
    players = await fetch_players(
        config, {
            'allycodes': [ally_code],
            'project': {
                'allyCode': 1,
                'name': 1,
                'roster': {
                    'defId': 1,
                    'relic': 1,
                },
            },
        })

    msgs = []
    all_relic = OrderedDict()
    for relic in RelicStat.objects.all().order_by(relic_filter).values():
        unit_id = relic['unit_id']
        relic['locked'] = True
        unit = BaseUnit.objects.get(id=unit_id)
        all_relic[unit.base_id] = relic

    for ally_code_str, player in players.items():

        relic_list = dict(all_relic)

        for base_id, unit in player['roster'].items():

            if 'relic' in unit and unit[
                    'relic'] is not None and 'currentTier' in unit[
                        'relic'] and unit['relic']['currentTier'] >= relic_tier:
                del relic_list[base_id]
                continue

            if base_id not in relic_list:
                continue

            relic_list[base_id]['locked'] = False

        lines = []
        for base_id, relic in relic_list.items():

            if relic['locked'] is not include_locked:
                continue

            unit_name = get_unit_name(base_id, language)
            percentage = relic[relic_field]

            lines.append('`%.2f` **%s**' % (percentage, unit_name))

            limit -= 1
            if limit <= 0:
                break

        msgs.append({
            'title': 'Relic Recommendations for %s' % player['name'],
            'description': '\n'.join(lines),
        })

    return msgs
Exemplo n.º 4
0
async def cmd_zetas(request):

    args = request.args
    author = request.author
    config = request.config

    language = parse_opts_lang(request)

    limit = parse_opts_limit(request)
    include_locked = parse_opts_include_locked(request)

    selected_players, error = parse_opts_players(request,
                                                 min_allies=1,
                                                 max_allies=1)

    if error:
        return error

    if not selected_players:
        return error_no_ally_code_specified(config, author)

    if args:
        return error_unknown_parameters(args)

    ally_code = selected_players[0].ally_code
    players = await fetch_players(
        config, {
            'allycodes': [ally_code],
            'project': {
                'allyCode': 1,
                'name': 1,
                'roster': {
                    'defId': 1,
                    'gear': 1,
                    'level': 1,
                    'rarity': 1,
                    'relic': 1,
                    'skills': 1,
                    'equipped': {
                        'slot': 1,
                    },
                },
            },
        })

    msgs = []
    all_zetas = OrderedDict()
    for zeta in ZetaStat.objects.all().order_by('-of_all_this_unit').values():
        skill_id = zeta['skill_id']
        zeta['locked'] = True
        all_zetas[skill_id] = zeta

    for ally_code_str, player in players.items():

        zetas = dict(all_zetas)

        for base_id, unit in player['roster'].items():
            for skill in unit['skills']:

                skill_id = skill['id']
                if skill_id not in zetas:
                    continue

                if 'tier' not in skill:
                    continue

                if skill['tier'] == 8:
                    del zetas[skill_id]
                    continue

                zetas[skill_id]['locked'] = False

        lines = []
        for zeta_id, zeta in zetas.items():

            if zeta['locked'] is not include_locked:
                continue

            percent = zeta['of_all_this_unit']
            unit = BaseUnit.objects.get(pk=zeta['unit_id'])
            unit_name = get_unit_name(unit.base_id, language)
            skill_name = get_ability_name(zeta['skill_id'], language)

            lines.append('`%.2f` **%s** %s' % (percent, unit_name, skill_name))

            limit -= 1
            if limit <= 0:
                break

        msgs.append({
            'title': 'Zeta Recommendations for %s' % player['name'],
            'description': '\n'.join(lines),
        })

    return msgs
Exemplo n.º 5
0
async def cmd_modroll(request):

	args = request.args
	author = request.author
	config = request.config

	msgs = []

	language = parse_opts_lang(request)

	selected_players, error = parse_opts_players(request)

	if args:
		return error_unknown_parameters(args)

	if error:
		return error

	if not selected_players:
		return error_no_ally_code_specified(config, author)

	ally_codes = [ p.ally_code for p in selected_players ]

	data = await fetch_players(config, {
		'allycodes': ally_codes,
		'project': {
			'allyCode': 1,
			'name': 1,
			'roster': {
				'defId': 1,
				'mods': 1,
			},
		},
	})

	players = {}
	for ally_code_str, player in data.items():
		ally_code = player['allyCode']
		players[ally_code] = player

	result = {}
	for ally_code, player in players.items():
		player_name = player['name']
		for def_id, unit in player['roster'].items():
			unit_name = get_unit_name(def_id, language)
			for mod in unit['mods']:
				for sec_stat in mod['secondaryStat']:
					if sec_stat['roll'] >= MIN_ROLLS:

						if player_name not in result:
							result[player_name] = {}

						if unit_name not in result[player_name]:
							result[player_name][unit_name] = []

						result[player_name][unit_name].append(mod)

	msgs = []
	for player_name, data in result.items():
		lines = []
		for unit_name, mods in sorted(data.items()):
			lines.append(unit_name)
			for mod in mods:
				slot = MODSLOTS[ mod['slot'] ].replace(' ', '').lower()
				slot_emoji = EMOJIS[slot]
				modset = MODSETS[ mod['set'] ].replace(' ', '').lower()
				modset_emoji = EMOJIS[modset]
				for sec in mod['secondaryStat']:
					if sec['roll'] >= MIN_ROLLS:
						stat_name = MODSECONDARYSTATS[ sec['unitStat'] ]
						stat_value = ('%.2f' % sec['value']).replace('.00', '')
						lines.append('%s%s %dD (%d) +%s %s' % (modset_emoji, slot_emoji, mod['pips'], sec['roll'], stat_value, stat_name))
		msgs.append({
			'title': '%d Roll Mods of %s' % (MIN_ROLLS, player_name),
			'description': '\n'.join(lines),
		})

	return msgs
Exemplo n.º 6
0
async def cmd_locked(request):

	args = request.args
	config = request.config

	language = parse_opts_lang(request)

	players, error = parse_opts_players(request)

	opts = parse_opts_locked(request)

	if args:
		return error_unknown_parameters(args)

	if error:
		return error

	ally_codes = [ player.ally_code for player in players ]
	players = await fetch_players(config, ally_codes)

	units = BaseUnit.objects.filter(combat_type=1).values()
	ships = BaseUnit.objects.filter(combat_type=2).values()
	char_list = { x['base_id']: x for x in units }
	ship_list = { x['base_id']: x for x in ships }

	msgs = []
	lines = []
	for ally_code, player in players.items():

		ally_units = player['roster']

		if opts in [ 'chars', 'all' ]:

			locked_chars = []
			for base_id, char in char_list.items():
				if base_id not in ally_units:
					char_name = get_unit_name(base_id, language)
					locked_chars.append(char_name)

			if not locked_chars:
				locked_chars.append('All characters unlocked!')

			lines.append('**Locked Characters**')
			lines += sorted(locked_chars)
			lines.append('')

		if opts in [ 'ships', 'all' ]:

			locked_ships = []
			for base_id, ship in ship_list.items():
				if base_id not in ally_units:
					ship_name = get_unit_name(base_id, language)
					locked_ships.append(ship_name)

			if not locked_ships:
				locked_ships.append('All ships unlocked!')

			lines.append('**Locked Ships**')
			lines += sorted(locked_ships)
			lines.append('')

		msgs.append({
			'author': {
				'name': '%s\'s Locked Units' % player['name'],
			},
			'title': '',
			'description': '\n'.join(lines),
		})

	return msgs
Exemplo n.º 7
0
async def cmd_gear13(request):

    args = request.args
    author = request.author
    config = request.config

    language = parse_opts_lang(request)

    limit = parse_opts_limit(request)
    include_locked = parse_opts_include_locked(request)

    selected_players, error = parse_opts_players(request,
                                                 min_allies=1,
                                                 max_allies=1)

    if error:
        return error

    if not selected_players:
        return error_no_ally_code_specified(config, author)

    if args:
        return error_unknown_parameters(args)

    ally_code = selected_players[0].ally_code
    players = await fetch_players(
        config, {
            'allycodes': [ally_code],
            'project': {
                'allyCode': 1,
                'name': 1,
                'roster': {
                    'defId': 1,
                    'gear': 1,
                },
            },
        })

    msgs = []
    all_g13 = OrderedDict()
    for g13 in Gear13Stat.objects.all().order_by('-percentage').values():
        unit_id = g13['unit_id']
        g13['locked'] = True
        unit = BaseUnit.objects.get(id=unit_id)
        all_g13[unit.base_id] = g13

    for ally_code_str, player in players.items():

        g13_list = dict(all_g13)

        for base_id, unit in player['roster'].items():

            if unit['gear'] == 13:
                del g13_list[base_id]
                continue

            if base_id not in g13_list:
                continue

            g13_list[base_id]['locked'] = False

        lines = []
        for base_id, g13 in g13_list.items():

            if g13['locked'] is not include_locked:
                continue

            unit_name = get_unit_name(base_id, language)
            percentage = g13['percentage']

            lines.append('`%.2f` **%s**' % (percentage, unit_name))

            limit -= 1
            if limit <= 0:
                break

        msgs.append({
            'title': 'Gear 13 Recommendations for %s' % player['name'],
            'description': '\n'.join(lines),
        })

    return msgs
Exemplo n.º 8
0
async def cmd_modcheck(request):

    args = request.args
    author = request.author
    channel = request.channel
    config = request.config

    msgs = []
    units_with_missing_mods = []
    units_with_incomplete_modsets = []

    language = parse_opts_lang(request)

    actions = parse_opts_actions(request)
    if not actions:
        actions = default_actions

    selected_players, error = parse_opts_players(request)

    if error:
        return error

    if not selected_players:
        return error_no_ally_code_specified(config, author)

    if args:
        return error_unknown_parameters(args)

    ally_codes = [p.ally_code for p in selected_players]
    players = await fetch_players(
        config, {
            'allycodes': ally_codes,
            'project': {
                'allyCode': 1,
                'name': 1,
                'roster': {
                    'defId': 1,
                    'level': 1,
                    'mods': 1,
                    'combatType': 1,
                },
            },
        })

    for ally_code_str, player in players.items():

        lines = []
        roster = player['roster']

        modcount, units_with_no_mods, units_with_missing_mods, units_with_incomplete_modsets, units_with_incomplete_modlevels, units_with_mods_less_5_pips, units_with_mods_less_6_pips, units_with_mods_weak_tier = get_mod_stats(
            roster)

        if 'count' in actions:
            lines.append('**%d** equipped mods.' % modcount)
            lines.append(config['separator'])

        if 'nomods' in actions:

            sublines = []
            for unit in units_with_no_mods:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                sublines.append('**[%s](%s)** (No mods)' %
                                (unit_name, unit_url))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found without any mods.')
            lines.append(config['separator'])

        if 'missing' in actions:

            sublines = []
            for unit in units_with_missing_mods:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                sublines.append('**[%s](%s)** (**%d** missing)' %
                                (unit_name, unit_url, unit['missing-mods']))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with missing mods.')
            lines.append(config['separator'])

        if 'incomplete' in actions:

            sublines = []
            for unit in units_with_incomplete_modsets:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                sublines.append('**[%s](%s)** (Incomplete modset)' %
                                (unit_name, unit_url))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with incomplete modsets.')
            lines.append(config['separator'])

        if 'level' in actions:

            sublines = []
            for unit in units_with_incomplete_modlevels:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                plural = len(unit['mods-no-max-level']) > 1 and 's' or ''
                sublines.append('**[%s](%s)** (**%d** mod%s < L15)' %
                                (unit_name, unit_url,
                                 len(unit['mods-no-max-level']), plural))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with mods less than level 15.')
            lines.append(config['separator'])

        if '5pips' in actions:

            sublines = []
            for unit in units_with_mods_less_5_pips:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                plural = len(unit['mods-not-5-pips']) > 1 and 's' or ''
                sublines.append('**[%s](%s)** (**%d** mod%s < 5 pips)' %
                                (unit_name, unit_url,
                                 len(unit['mods-not-5-pips']), plural))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with mods less than 5 pips.')
            lines.append(config['separator'])

        if '6pips' in actions:

            sublines = []
            for unit in units_with_mods_less_6_pips:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                plural = len(unit['mods-not-6-pips']) > 1 and 's' or ''
                sublines.append('**[%s](%s)** (**%d** mod%s < 6 pips)' %
                                (unit_name, unit_url,
                                 len(unit['mods-not-6-pips']), plural))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with mods less than 6 pips.')
            lines.append(config['separator'])

        if 'tier' in actions:

            sublines = []
            for unit in units_with_mods_weak_tier:
                unit_name = get_unit_name(unit['defId'], language)
                unit_url = get_swgohgg_player_unit_url(ally_code_str,
                                                       unit['defId'])
                plural = len(unit['weak-tier']) > 1 and 's' or ''
                sublines.append(
                    '**[%s](%s)** (**%d** mod%s < Gold)' %
                    (unit_name, unit_url, len(unit['weak-tier']), plural))
            lines.extend(sorted(sublines))
            if not lines:
                lines.append('No units found with mods tier less than gold.')
            lines.append(config['separator'])

        lines = lines[0:-1]

        msgs.append({
            'title': '%s' % player['name'],
            'description': '\n'.join(lines),
        })

    return msgs