<commit_before>/*
 * Copyright (C) 2016-2019 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package space.npstr.wolfia.domain.setup;

import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.springframework.stereotype.Component;
import space.npstr.wolfia.commands.Context;
import space.npstr.wolfia.domain.game.GameRegistry;
import space.npstr.wolfia.game.GameInfo;
import space.npstr.wolfia.game.definitions.Games;
import space.npstr.wolfia.game.tools.NiceEmbedBuilder;
import space.npstr.wolfia.utils.discord.TextchatUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;

/**
 * Renders are responsible for rendering complex information to be displayable in the Discord client.
 * <p>
 * TODO: generify as a component? apply automatically to "replied" objects?
 */
@Component
public class GameSetupRender {

    private final GameRegistry gameRegistry;

    public GameSetupRender(GameRegistry gameRegistry) {
        this.gameRegistry = gameRegistry;
    }

    public MessageEmbed render(GameSetup setup, Context context) {
        long channelId = setup.getChannelId();

        Games game = setup.getGame();
        GameInfo.GameMode mode = setup.getMode();
        GameInfo info = Games.getInfo(game);
        Set<Long> innedUsers = setup.getInnedUsers();

        var neb = NiceEmbedBuilder.defaultBuilder();
        ShardManager shardManager = context.getJda().getShardManager();
        TextChannel channel = requireNonNull(shardManager).getTextChannelById(channelId);
        if (channel == null) {
            neb.addField("Could not find channel with id " + channelId, "", false);
            return neb.build();
        }
        neb.setTitle("Setup for channel #" + channel.getName());
        neb.setDescription(this.gameRegistry.get(channelId) == null
                ? "Game has **NOT** started yet."
                : "Game has started.");

        //games
        var possibleGames = new StringBuilder();
        Arrays.stream(Games.values()).forEach(g ->
                possibleGames.append(g == game ? "`[x]` " : "`[ ]` ").append(g.textRep).append("\n"));
        neb.addField("Game", possibleGames.toString(), true);

        //modes
        var possibleModes = new StringBuilder();
        info.getSupportedModes().forEach(m ->
                possibleModes.append(mode.equals(m) ? "`[x]` " : "`[ ]` ").append(m).append("\n"));
        neb.addField("Mode", possibleModes.toString(), true);

        //day length
        neb.addField("Day length", TextchatUtils.formatMillis(setup.getDayLength().toMillis()), true);

        //accepted player numbers
        neb.addField("Accepted players",
                info.getAcceptablePlayerNumbers(mode),
                true);
<commit_msg>Show day length in minutes in the setup<commit_after>/*
 * Copyright (C) 2016-2019 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package space.npstr.wolfia.domain.setup;

import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.springframework.stereotype.Component;
import space.npstr.wolfia.commands.Context;
import space.npstr.wolfia.domain.game.GameRegistry;
import space.npstr.wolfia.game.GameInfo;
import space.npstr.wolfia.game.definitions.Games;
import space.npstr.wolfia.game.tools.NiceEmbedBuilder;
import space.npstr.wolfia.utils.discord.TextchatUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;

/**
 * Renders are responsible for rendering complex information to be displayable in the Discord client.
 * <p>
 * TODO: generify as a component? apply automatically to "replied" objects?
 */
@Component
public class GameSetupRender {

    private final GameRegistry gameRegistry;

    public GameSetupRender(GameRegistry gameRegistry) {
        this.gameRegistry = gameRegistry;
    }

    public MessageEmbed render(GameSetup setup, Context context) {
        long channelId = setup.getChannelId();

        Games game = setup.getGame();
        GameInfo.GameMode mode = setup.getMode();
        GameInfo info = Games.getInfo(game);
        Set<Long> innedUsers = setup.getInnedUsers();

        var neb = NiceEmbedBuilder.defaultBuilder();
        ShardManager shardManager = context.getJda().getShardManager();
        TextChannel channel = requireNonNull(shardManager).getTextChannelById(channelId);
        if (channel == null) {
            neb.addField("Could not find channel with id " + channelId, "", false);
            return neb.build();
        }
        neb.setTitle("Setup for channel #" + channel.getName());
        neb.setDescription(this.gameRegistry.get(channelId) == null
                ? "Game has **NOT** started yet."
                : "Game has started.");

        //games
        var possibleGames = new StringBuilder();
        Arrays.stream(Games.values()).forEach(g ->
                possibleGames.append(g == game ? "`[x]` " : "`[ ]` ").append(g.textRep).append("\n"));
        neb.addField("Game", possibleGames.toString(), true);

        //modes
        var possibleModes = new StringBuilder();
        info.getSupportedModes().forEach(m ->
                possibleModes.append(mode.equals(m) ? "`[x]` " : "`[ ]` ").append(m).append("\n"));
        neb.addField("Mode", possibleModes.toString(), true);

        //day length
        neb.addField("Day length", setup.getDayLength().toMinutes() + " minutes", true);

        //accepted player numbers
        neb.addField("Accepted players",
                info.getAcceptablePlayerNumbers(mode),
                true);

{'fraction_non_alphanumeric': 0.11351503231244732, 'fraction_numerical': 0.0033717336330429896, 'mean_word_length': 3.2224199288256226, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4740625', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1955, 'n_words': 554}