Exemple #1
0
        public async Task SetLanguage(params string[] language)
        {
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Settings);

            if (!CanModify(Context.User, Context.Guild.OwnerId))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild.Id, Context.Guild.OwnerId));
            }
            else if (language.Length == 0)
            {
                await ReplyAsync(Sentences.NeedLanguage(Context.Guild.Id));
            }
            else
            {
                string nextLanguage = Utilities.AddArgs(language);
                string lang         = Utilities.GetLanguage(nextLanguage);
                if (lang == null)
                {
                    await ReplyAsync(Sentences.InvalidLanguage(Context.Guild.Id));
                }
                else
                {
                    await p.db.SetLanguage(Context.Guild.Id, lang);
                    await ReplyAsync(Base.Sentences.DoneStr(Context.Guild.Id));
                }
            }
        }
Exemple #2
0
        public async Task Translation(params string[] words)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Linguistic);
            await p.DoAction(Context.User, Program.Module.Linguistic);

            if (Context.Message.Attachments.Count > 0)
            {
                var list = words.ToList();
                list.Add(Context.Message.Attachments.ToArray()[0].Url);
                words = list.ToArray();
            }
            var result = await Features.Tools.Linguist.Translate(words, Program.p.translationClient, Program.p.visionClient, Program.p.allLanguages);

            switch (result.error)
            {
            case Features.Tools.Error.Translation.Help:
                await ReplyAsync(Sentences.TranslateHelp(Context.Guild));

                break;

            case Features.Tools.Error.Translation.InvalidApiKey:
                await ReplyAsync(Base.Sentences.NoApiKey(Context.Guild));

                break;

            case Features.Tools.Error.Translation.InvalidLanguage:
                await ReplyAsync(Sentences.InvalidLanguage(Context.Guild));

                break;

            case Features.Tools.Error.Translation.NotAnImage:
                await ReplyAsync(Sentences.NotAnImage(Context.Guild));

                break;

            case Features.Tools.Error.Translation.NoTextOnImage:
                await ReplyAsync(Sentences.NoTextOnImage(Context.Guild));

                break;

            case Features.Tools.Error.Translation.None:
                await ReplyAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Blue,
                    Title       = Base.Sentences.FromStr(Context.Guild, result.answer.sourceLanguage),
                    Description = result.answer.sentence
                }.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }