Beispiel #1
0
        public async Task Translate(string languageCode, [Remainder] string message)
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            //Ensure whitelist isn't enforced unless the list is populated
            if (config.WhitelistRoles.Any())
            {
                //Check to see if the user has a whitelisted role
                if (!config.WhitelistRoles.Any(x => (Context.User as IGuildUser)?.RoleIds.Contains(x) == true))
                {
                    await ReplyAsync("You do not have enough permissions to run translations.");

                    return;
                }
            }

            var response = TranslateService.Translate(Context.Guild.Id, message, languageCode);

            if (response.ResponseResult != TranslateService.TranslateResponse.Result.Success)
            {
                return;
            }
            var embed = TranslateService.GetTranslationEmbed(response);

            if (embed == null)
            {
                return;
            }
            await ReplyAsync("", false, embed.Build());
        }
Beispiel #2
0
        public async Task ToggleDmReactions()
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            config.DirectMessageTranslations = !config.DirectMessageTranslations;
            TranslateService.SaveTranslateGuild(config);
            await ReplyAsync($"DM Users Translations: {config.DirectMessageTranslations}");
        }
Beispiel #3
0
        public async Task ToggleReactions()
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            config.ReactionTranslations = !config.ReactionTranslations;
            TranslateService.SaveTranslateGuild(config);
            await ReplyAsync($"Translation Reactions Enabled: {config.ReactionTranslations}");
        }
Beispiel #4
0
        public async Task RemoveWhitelistRole(ulong roleId)
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            config.WhitelistRoles.Remove(roleId);
            TranslateService.SaveTranslateGuild(config);
            await ReplyAsync("Role removed.");
        }
Beispiel #5
0
        public async Task AddWhitelistedRole(IRole role)
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            config.WhitelistRoles = config.WhitelistRoles.Where(x => x != role.Id).ToList();
            config.WhitelistRoles.Add(role.Id);
            TranslateService.SaveTranslateGuild(config);
            await ReplyAsync("Role has been whitelisted.");
        }
Beispiel #6
0
        public Task ListAsync()
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);
            var fields = config.CustomPairs.Select(x => new EmbedFieldBuilder {
                Name = x.LanguageString, Value = string.Join("\n", x.EmoteMatches), IsInline = true
            }).ToList();
            var embed = new EmbedBuilder {
                Fields = fields
            };

            return(ReplyAsync("", false, embed.Build()));
        }
Beispiel #7
0
        public async Task Settings()
        {
            var profile = TranslateService.License.GetQuantifiableUser(TranslateService.TranslateType, Context.Guild.Id);
            var config  = TranslateService.GetTranslateGuild(Context.Guild.Id);
            var roles   = config.WhitelistRoles.Select(x => Context.Guild.GetRole(x)?.Mention ?? $"Deleted Role: [{x}]").ToList();

            await ReplyAsync($"Remaining Uses: {profile.RemainingUses()}\n" +
                             $"Total Used: {profile.TotalUsed}\n" +
                             $"DM Translations: {config.DirectMessageTranslations}\n" +
                             $"Reaction Translations: {config.ReactionTranslations}\n" +
                             $"Whitelisted Roles: {(roles.Any() ? string.Join("\n", roles) : "None")}\n" +
                             $"Use the List and Defaults commands to see reactions settings.");
        }
Beispiel #8
0
        public async Task RemovePair(Emoji emote)
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            foreach (var pair in config.CustomPairs)
            {
                pair.EmoteMatches.Remove(emote.Name);
            }

            await ReplyAsync("Reaction removed.");

            TranslateService.SaveTranslateGuild(config);
        }
Beispiel #9
0
        public async Task ShowWhitelist()
        {
            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);

            if (!config.WhitelistRoles.Any())
            {
                await ReplyAsync("There are no whitelisted roles. ie. all users can translate messages.");

                return;
            }

            var roles = config.WhitelistRoles.Select(x => Context.Guild.GetRole(x)?.Mention ?? $"Deleted Role: [{x}]").ToList();

            await ReplyAsync("", false, new EmbedBuilder()
            {
                Description = string.Join("\n", roles),
                Title       = "Role whitelist"
            }.Build());
        }
Beispiel #10
0
        public async Task AddPair(Emoji emote, string code)
        {
            if (!TranslateService.Translator.IsValidLanguageCode(code))
            {
                await ReplyAsync("Language code is not valid.");

                return;
            }

            var config = TranslateService.GetTranslateGuild(Context.Guild.Id);
            var match  = config.CustomPairs.FirstOrDefault(x => x.LanguageString.Equals(code, StringComparison.InvariantCultureIgnoreCase));

            if (match != null)
            {
                if (match.EmoteMatches.Any(x => x == emote.Name))
                {
                    await ReplyAsync("This emote is already configured to work with this language.");

                    return;
                }

                match.EmoteMatches.Add(emote.Name);
            }
            else
            {
                config.CustomPairs.Add(new LanguageMap.TranslationSet()
                {
                    EmoteMatches = new List <string> {
                        emote.Name
                    },
                    LanguageString = code
                });
            }

            TranslateService.SaveTranslateGuild(config);
            await ReplyAsync($"{emote.Name} reactions will now translate messages to {code}");
        }