<commit_before>﻿using Discord;
using Discord.WebSocket;
using Microsoft.Extensions.Logging;
using PoGo.DiscordBot.Configuration;
using PoGo.DiscordBot.Dto;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace PoGo.DiscordBot.Services
{
    public class UserService
    {
        private readonly ILogger<UserService> logger;
        private readonly TeamService teamService;

        public UserService(ILogger<UserService> logger, TeamService teamService)
        {
            this.logger = logger;
            this.teamService = teamService;
        }

        public int? GetPlayerLevel(SocketGuildUser user)
        {
            var name = user.ToString();
            const string levelRegex = @" (\d)";
            var result = Regex.Match(name, levelRegex, RegexOptions.RightToLeft);
            if (int.TryParse(result.Value, out var level))
                return level;
            return null;
        }

        public PokemonTeam? GetTeam(SocketGuildUser user)
        {
            var teamRoles = teamService.GuildTeamRoles[user.Guild.Id].RoleTeams;

            foreach (var role in user.Roles)
                if (teamRoles.TryGetValue(role.Id, out var team))
                    return team;

            return null;
        }

        public PlayerDto GetPlayer(SocketGuildUser user) => new PlayerDto
        {
            User = user,
            Team = GetTeam(user),
        };

        public async Task CheckTeam(SocketGuildUser user)
        {
            var team = GetTeam(user);

            if (team == null)
            {
                logger.LogInformation($"Notifying {user.Id} '{user.Nickname ?? user.Username}' about team role");
                string userMessage = "Ahoj, nastav si team a level prosím." + Environment.NewLine +
                    "Tyhle příkazy mi nemůžeš psát přímo tady, ale musíš ho psát do některých z kanálů (např. #diskuze)" + Environment.NewLine +
                    "Team si nastavíš pomocí příkazu team, např. !team mystic" + Environment.NewLine +
                    "Level si nastavíš pomocí příkazu level, např. !level 30" + Environment.NewLine +
                    "Díky!";
                await user.SendMessageAsync(userMessage);
            }
        }

        public Task OnUserJoined(SocketGuildUser user)
        {
            logger.LogInformation($"User joined {user.Id} '{user.Nickname ?? user.Username}'");
            return CheckTeam(user);
        }<commit_msg>Welcome message modify.<commit_after>﻿using Discord;
using Discord.WebSocket;
using Microsoft.Extensions.Logging;
using PoGo.DiscordBot.Configuration;
using PoGo.DiscordBot.Dto;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace PoGo.DiscordBot.Services
{
    public class UserService
    {
        private readonly ILogger<UserService> logger;
        private readonly TeamService teamService;

        public UserService(ILogger<UserService> logger, TeamService teamService)
        {
            this.logger = logger;
            this.teamService = teamService;
        }

        public int? GetPlayerLevel(SocketGuildUser user)
        {
            var name = user.ToString();
            const string levelRegex = @" (\d)";
            var result = Regex.Match(name, levelRegex, RegexOptions.RightToLeft);
            if (int.TryParse(result.Value, out var level))
                return level;
            return null;
        }

        public PokemonTeam? GetTeam(SocketGuildUser user)
        {
            var teamRoles = teamService.GuildTeamRoles[user.Guild.Id].RoleTeams;

            foreach (var role in user.Roles)
                if (teamRoles.TryGetValue(role.Id, out var team))
                    return team;

            return null;
        }

        public PlayerDto GetPlayer(SocketGuildUser user) => new PlayerDto
        {
            User = user,
            Team = GetTeam(user),
        };

        public async Task CheckTeam(SocketGuildUser user)
        {
            var team = GetTeam(user);

            if (team == null)
            {
                logger.LogInformation($"Notifying {user.Id} '{user.Nickname ?? user.Username}' about team role");
                string userMessage = "Ahoj, nastav si team a level prosím." + Environment.NewLine +
                    "Tyhle příkazy mi nemůžeš psát přímo tady, ale musíš ho psát do některých z kanálů (např. #diskuze)" + Environment.NewLine +
                    "Přípazy piš zvlášť, jeden příkaz = jedna zpráva." + Environment.NewLine +
                    "Team si nastavíš pomocí příkazu team, např. !team mystic" + Environment.NewLine +
                    "Level si nastavíš pomocí příkazu level, např. !level 30" + Environment.NewLine +
                    "Díky!";
                await user.SendMessageAsync(userMessage);
            }
        }

        public Task OnUserJoined(SocketGuildUser user)
        {
            logger.LogInformation($"User joined {user.Id} '{user.Nickname ?? user.Username}'");
            return CheckTeam(user);
        }
{'fraction_non_alphanumeric': 0.08675978752705095, 'fraction_numerical': 0.0007869368483179224, 'mean_word_length': 1.992348440258976, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '808257', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1403, 'n_words': 358}