コード例 #1
0
ファイル: Code.cs プロジェクト: TheIndra55/Sanara
        public async Task SearchColor(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Code);
            await Program.p.DoAction(Context.User, Program.Module.Code);

            var result = await Features.Tools.Code.SearchColor(args, Program.p.rand);

            switch (result.error)
            {
            case Features.Tools.Error.Image.InvalidArg:
                await ReplyAsync(Sentences.HelpColor(Context.Guild));

                break;

            case Features.Tools.Error.Image.InvalidColor:
                await ReplyAsync(Sentences.InvalidColor(Context.Guild));

                break;

            case Features.Tools.Error.Image.None:
                await ReplyAsync("", false, new EmbedBuilder()
                {
                    Title       = result.answer.name,
                    Color       = result.answer.discordColor,
                    ImageUrl    = result.answer.colorUrl,
                    Description = Sentences.Rgb(Context.Guild) + ": " + result.answer.discordColor.R + ", " + result.answer.discordColor.G + ", " + result.answer.discordColor.B + Environment.NewLine +
                                  Sentences.Hex(Context.Guild) + ": #" + result.answer.colorHex
                }.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #2
0
        public async Task SetPrefix(params string[] command)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Base.Sentences.CommandDontPm(Context.Guild));

                return;
            }
            await p.DoAction(Context.User, Program.Module.Settings);

            if (!CanModify(Context.User, Context.Guild))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild, Context.Guild.OwnerId));
            }
            else
            {
                if (command.Length == 0)
                {
                    await p.db.SetPrefix(Context.Guild.Id, "");
                    await ReplyAsync(Sentences.PrefixRemoved(Context.Guild));
                }
                else
                {
                    await p.db.SetPrefix(Context.Guild.Id, Utilities.AddArgs(command));
                    await ReplyAsync(Base.Sentences.DoneStr(Context.Guild));
                }
            }
        }
コード例 #3
0
        public async Task Poll(params string[] args)
        {
            Utilities.CheckAvailability(Context.Guild, Program.Module.Communication);
            await p.DoAction(Context.User, Program.Module.Communication);

            if (args.Length < 2)
            {
                await ReplyAsync(Sentences.PollHelp(Context.Guild));

                return;
            }
            if (args.Length > 10)
            {
                await ReplyAsync(Sentences.PollTooManyChoices(Context.Guild));

                return;
            }
            var    emotes = new[] { new Emoji("1️⃣"), new Emoji("2️⃣"), new Emoji("3️⃣"), new Emoji("4️⃣"), new Emoji("5️⃣"), new Emoji("6️⃣"), new Emoji("7️⃣"), new Emoji("8️⃣"), new Emoji("9️⃣") };
            string str    = "";
            int    i      = 0;

            foreach (string s in args.Skip(1))
            {
                str += emotes[i] + ": " + s + Environment.NewLine;
                i++;
            }
            var msg = await ReplyAsync("", false, new EmbedBuilder
            {
                Title       = args[0],
                Description = str,
                Color       = Color.Blue
            }.Build());

            await msg.AddReactionsAsync(emotes.Take(i).ToArray());
        }
コード例 #4
0
        public async Task Logs(params string[] args)
        {
            await p.DoAction(Context.User, Program.Module.Information);

            if (p.GitHubKey == null)
            {
                await ReplyAsync(Base.Sentences.NoApiKey(Context.Guild));

                return;
            }
            dynamic      json;
            EmbedBuilder eb = new EmbedBuilder()
            {
                Title = Sentences.LatestChanges(Context.Guild),
                Color = Color.Green
            };

            using (HttpClient hc = new HttpClient())
            {
                hc.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 Sanara");
                json = JsonConvert.DeserializeObject(await hc.GetStringAsync("https://api.github.com/repos/Xwilarg/Sanara/commits?per_page=5&access_token=" + p.GitHubKey));
            }
            foreach (var j in json)
            {
                eb.AddField(DateTime.ParseExact((string)j.commit.author.date, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).ToString(Base.Sentences.DateHourFormat(Context.Guild))
                            + " " + Sentences.ByStr(Context.Guild) + " " + j.commit.author.name, j.commit.message);
            }
            await ReplyAsync("", false, eb.Build());
        }
コード例 #5
0
        public async Task EvalFct(params string[] args)
        {
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Settings);

            if (Context.User.Id != Base.Sentences.ownerId)
            {
                await ReplyAsync(Base.Sentences.OnlyMasterStr(Context.Guild.Id));
            }
            else if (args.Length == 0)
            {
                await ReplyAsync(Sentences.EvalHelp(Context.Guild.Id));
            }
            else
            {
                Interpreter interpreter = new Interpreter()
                                          .SetVariable("Context", Context)
                                          .SetVariable("p", Program.p)
                                          .EnableReflection();
                try
                {
                    await ReplyAsync(interpreter.Eval(string.Join(" ", args)).ToString());
                }
                catch (Exception e)
                {
                    await ReplyAsync(Sentences.EvalError(Context.Guild.Id, e.Message));
                }
            }
        }
コード例 #6
0
        public async Task Infos(params string[] command)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Base.Sentences.CommandDontPm(Context.Guild));

                return;
            }
            Utilities.CheckAvailability(Context.Guild, Program.Module.Communication);
            await p.DoAction(Context.User, Program.Module.Communication);

            IGuildUser user;

            if (command.Length == 0)
            {
                user = Context.User as IGuildUser;
            }
            else
            {
                user = await Utilities.GetUser(Utilities.AddArgs(command), Context.Guild);

                if (user == null)
                {
                    await ReplyAsync(Sentences.UserNotExist(Context.Guild));

                    return;
                }
            }
            await InfosUser(user);
        }
コード例 #7
0
ファイル: Information.cs プロジェクト: Kadantte/Sanara
        public async Task Ping(params string[] _)
        {
            int latency = (int)new DateTimeOffset(DateTime.UtcNow).Subtract(Context.Message.CreatedAt).TotalMilliseconds;
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Information);

            await ReplyAsync(Sentences.Latency(Context.Guild.Id) + " " + latency + Sentences.MsStr(Context.Guild.Id));
        }
コード例 #8
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));
                }
            }
        }
コード例 #9
0
ファイル: Code.cs プロジェクト: TheIndra55/Sanara
        public async Task IncreaseSize(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Code);
            await Program.p.DoAction(Context.User, Program.Module.Code);

            if (Context.Message.Attachments.Count > 0)
            {
                args = new[] { Context.Message.Attachments.ToArray()[0].Url }
            }
            ;
            var result = await Features.Tools.Code.IncreaseSize(args, Program.p.rand);

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

                break;

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

                break;

            case Features.Tools.Error.IncreaseSize.None:
                await Context.Channel.SendFileAsync(result.answer.path);

                break;

            default:
                throw new NotImplementedException();
            }
        }
    }
コード例 #10
0
        public async Task Kanji(params string[] words)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Linguistic);
            await p.DoAction(Context.User, Program.Module.Linguistic);

            var result = await Features.Tools.Linguist.Kanji(words);

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

                break;

            case Features.Tools.Error.Kanji.NotFound:
                await ReplyAsync(Sentences.UrbanNotFound(Context.Guild));

                break;

            case Features.Tools.Error.Kanji.None:
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = result.answer.kanji.ToString(),
                    Description = result.answer.meaning,
                    ImageUrl    = result.answer.strokeOrder,
                    Color       = Color.Blue,
                    Fields      = new List <EmbedFieldBuilder>
                    {
                        new EmbedFieldBuilder()
                        {
                            Name  = Sentences.Radical(Context.Guild),
                            Value = result.answer.radicalKanji + ": " + result.answer.radicalMeaning
                        },
                        new EmbedFieldBuilder()
                        {
                            Name  = Sentences.Parts(Context.Guild),
                            Value = string.Join(Environment.NewLine, result.answer.parts.Select(x => x.Value == "" ? x.Key : x.Key + ": " + x.Value))
                        },
                        new EmbedFieldBuilder()
                        {
                            Name  = "Onyomi",
                            Value = result.answer.onyomi.Count == 0 ? Base.Sentences.None(Context.Guild) : string.Join(Environment.NewLine, result.answer.onyomi.Select(x => x.Key + " (" + x.Value + ")"))
                        },
                        new EmbedFieldBuilder()
                        {
                            Name  = "Kunyomi",
                            Value = result.answer.kunyomi.Count == 0 ? Base.Sentences.None(Context.Guild) : string.Join(Environment.NewLine, result.answer.kunyomi.Select(x => x.Key + " (" + x.Value + ")"))
                        }
                    }
                }.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #11
0
        public async Task Urban(params string[] words)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Linguistic);
            await p.DoAction(Context.User, Program.Module.Linguistic);

            var result = await Features.Tools.Linguist.UrbanSearch(!((ITextChannel)Context.Channel).IsNsfw, words);

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

                break;

            case Features.Tools.Error.Urban.ChanNotNSFW:
                await ReplyAsync(Base.Sentences.ChanIsNotNsfw(Context.Guild));

                break;

            case Features.Tools.Error.Urban.NotFound:
                await ReplyAsync(Sentences.UrbanNotFound(Context.Guild));

                break;

            case Features.Tools.Error.Urban.None:
                EmbedBuilder em = new EmbedBuilder
                {
                    Color  = Color.Blue,
                    Title  = char.ToUpper(result.answer.word[0]) + string.Concat(result.answer.word.Skip(1)),
                    Fields = new List <EmbedFieldBuilder>()
                    {
                        new EmbedFieldBuilder()
                        {
                            Name  = Sentences.Definition(Context.Guild),
                            Value = result.answer.definition
                        }
                    },
                    Footer = new EmbedFooterBuilder()
                    {
                        Text = Base.Sentences.FromStr(Context.Guild, result.answer.link)
                    }
                };
                if (result.answer.example != "")
                {
                    em.AddField(Sentences.Example(Context.Guild), result.answer.example);
                }
                await ReplyAsync("", false, em.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #12
0
ファイル: Information.cs プロジェクト: Kadantte/Sanara
        public async Task GDPR(params string[] command)
        {
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Information);

            await ReplyAsync("", false, new EmbedBuilder()
            {
                Color       = Color.Blue,
                Title       = Sentences.DataSaved(Context.Guild.Id, Context.Guild.Name),
                Description = await Program.p.db.GetGuild(Context.Guild.Id)
            }.Build());
        }
コード例 #13
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();
            }
        }
コード例 #14
0
        public async Task InfosUser(IGuildUser user)
        {
            string roles = "";

            foreach (ulong roleId in user.RoleIds)
            {
                IRole role = Context.Guild.GetRole(roleId);
                if (role.Name == "@everyone")
                {
                    continue;
                }
                roles += role.Name + ", ";
            }
            if (roles != "")
            {
                roles = roles.Substring(0, roles.Length - 2);
            }
            EmbedBuilder embed = new EmbedBuilder
            {
                ImageUrl = user.GetAvatarUrl(),
                Color    = Color.Purple
            };

            embed.AddField(Sentences.Username(Context.Guild.Id), user.ToString(), true);
            if (user.Nickname != null)
            {
                embed.AddField(Sentences.Nickname(Context.Guild.Id), user.Nickname, true);
            }
            embed.AddField(Sentences.AccountCreation(Context.Guild.Id), user.CreatedAt.ToString(Base.Sentences.DateHourFormat(Context.Guild.Id)), true);
            embed.AddField(Sentences.GuildJoined(Context.Guild.Id), user.JoinedAt.Value.ToString(Base.Sentences.DateHourFormat(Context.Guild.Id)), true);
            if (user == (await Context.Channel.GetUserAsync(Program.p.client.CurrentUser.Id)))
            {
                embed.AddField(Sentences.Creator(Context.Guild.Id), "Zirk#0001", true);
                embed.AddField(Sentences.LatestVersion(Context.Guild.Id), new FileInfo(Assembly.GetEntryAssembly().Location).LastWriteTimeUtc.ToString(Base.Sentences.DateHourFormat(Context.Guild.Id)), true);
                embed.AddField(Sentences.NumberGuilds(Context.Guild.Id), p.client.Guilds.Count, true);
                embed.AddField(Sentences.Uptime(Context.Guild.Id), Utilities.TimeSpanToString(DateTime.Now.Subtract(p.startTime), Context.Guild.Id));
                embed.AddField("GitHub", "https://github.com/Xwilarg/Sanara");
                embed.AddField(Sentences.Website(Context.Guild.Id), "https://sanara.zirk.eu");
                embed.AddField(Sentences.InvitationLink(Context.Guild.Id), "https://discordapp.com/oauth2/authorize?client_id=329664361016721408&permissions=3196928&scope=bot");
                embed.AddField(Sentences.OfficialGuild(Context.Guild.Id), "https://discordapp.com/invite/H6wMRYV");
                embed.AddField("Discord Bot List", "https://discordbots.org/bot/329664361016721408");
                embed.AddField(Sentences.ProfilePicture(Context.Guild.Id), "BlankSensei");
            }
            embed.AddField(Sentences.Roles(Context.Guild.Id), ((roles == "") ? (Sentences.NoRole(Context.Guild.Id)) : (roles)));
            await ReplyAsync("", false, embed.Build());
        }
コード例 #15
0
        public async Task Error(params string[] args)
        {
            await p.DoAction(Context.User, Program.Module.Information);

            if (args.Length == 0)
            {
                await ReplyAsync(Sentences.ErrorHelp(Context.Guild));

                return;
            }
            string id = string.Join("", args);

            if (!Program.p.exceptions.ContainsKey(id))
            {
                await ReplyAsync(Sentences.ErrorNotFound(Context.Guild));

                return;
            }
            var elem = Program.p.exceptions[id];

            await ReplyAsync("", false, new EmbedBuilder
            {
                Color       = Color.Purple,
                Title       = elem.exception.InnerException.GetType().ToString(),
                Description = "```" + Environment.NewLine + elem.exception.InnerException.Message + Environment.NewLine + "```",
                Fields      = new List <EmbedFieldBuilder>
                {
                    new EmbedFieldBuilder
                    {
                        Name  = Sentences.Command(Context.Guild),
                        Value = elem.exception.Context.Message.ToString().Replace("@", "@\u200b")
                    },
                    new EmbedFieldBuilder
                    {
                        Name  = Sentences.Date(Context.Guild),
                        Value = elem.date.ToString(Base.Sentences.DateHourFormat(Context.Guild))
                    }
                },
                Footer = new EmbedFooterBuilder
                {
                    Text = Sentences.ErrorGdpr(Context.Guild, "https://sanara.zirk.eu/gdpr.html#collectedError")
                }
            }.Build());
        }
コード例 #16
0
        public async Task Meaning(params string[] words)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Linguistic);
            await p.DoAction(Context.User, Program.Module.Linguistic);

            var result = await Features.Tools.Linguist.JapaneseTranslate(words);

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

                break;

            case Features.Tools.Error.JapaneseTranslation.NotFound:
                await ReplyAsync(Sentences.NoJapaneseTranslation(Context.Guild));

                break;

            case Features.Tools.Error.JapaneseTranslation.None:
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Color = Color.Blue,
                    Title = string.Join(" ", words)
                };
                int i = 0;
                foreach (var answer in result.answer)
                {
                    embed.AddField(string.Join(", ", answer.definition),
                                   string.Join(Environment.NewLine, answer.words.Select((Features.Tools.Response.JapaneseWord word) =>
                                                                                        ((word.word != null) ? (word.word + " - ") : ("")) + ((word.reading != null) ? (word.reading + " (" + word.romaji + ")") : ("")))));
                    if (++i == 5)
                    {
                        break;
                    }
                }
                await ReplyAsync("", false, embed.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #17
0
        public async Task Calc(params string[] args)
        {
            Utilities.CheckAvailability(Context.Guild, Program.Module.Communication);
            await p.DoAction(Context.User, Program.Module.Communication);

            DataTable table = new DataTable();

            try
            {
                await ReplyAsync(table.Compute(string.Join("", args), "").ToString());
            }
            catch (EvaluateException)
            {
                await ReplyAsync(Sentences.InvalidCalc(Context.Guild));
            }
            catch (SyntaxErrorException)
            {
                await ReplyAsync(Sentences.InvalidCalc(Context.Guild));
            }
        }
コード例 #18
0
ファイル: Code.cs プロジェクト: TheIndra55/Sanara
        public async Task Shell(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Code);
            await Program.p.DoAction(Context.User, Program.Module.Code);

            var result = await Features.Tools.Code.Shell(args);

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

                break;

            case Features.Tools.Error.Shell.NotFound:
                await ReplyAsync(Sentences.ShellNotFound(Context.Guild));

                break;

            case Features.Tools.Error.Shell.None:
                EmbedBuilder em = new EmbedBuilder()
                {
                    Color = Color.Green,
                    Title = result.answer.title,
                    Url   = result.answer.url
                };
                foreach (var ex in result.answer.explanations)
                {
                    em.AddField(ex.Item1, ex.Item2);
                }
                await ReplyAsync("", false, em.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #19
0
        public async Task Anonymize(params string[] args)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Base.Sentences.CommandDontPm(Context.Guild));

                return;
            }
            await p.DoAction(Context.User, Program.Module.Settings);

            if (!CanModify(Context.User, Context.Guild))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild, Context.Guild.OwnerId));
            }
            if (args.Length == 0)
            {
                if (Program.p.db.IsAnonymized(Context.Guild.Id))
                {
                    await ReplyAsync(Sentences.AnonymizeCurrentTrue(Context.Guild));
                }
                else
                {
                    await ReplyAsync(Sentences.AnonymizeCurrentFalse(Context.Guild));
                }
            }
            else
            {
                if (bool.TryParse(string.Join(" ", args), out bool value))
                {
                    await Games.GameModule.Anonymize(Context.Guild.Id, value);
                    await ReplyAsync(Base.Sentences.DoneStr(Context.Guild));
                }
                else
                {
                    await ReplyAsync(Sentences.AnonymizeHelp(Context.Guild));
                }
            }
        }
コード例 #20
0
        public async Task GDPR(params string[] command)
        {
            await p.DoAction(Context.User, Program.Module.Information);

            var guildId = Context.Guild == null ? Context.User.Id : Context.Guild.Id;
            var guild   = await Program.p.db.GetGuild(guildId);

            if (guild != null)
            {
                await ReplyAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Blue,
                    Title       = Sentences.DataSaved(Context.Guild, Context.Guild?.Name ?? Context.User.ToString()),
                    Description = guild
                }.Build());
            }
            var me = Program.p.cm.GetProfile(Context.User.Id);

            if (me != null)
            {
                await Context.User.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Blue,
                    Title       = "Data saved about you",
                    Description = string.Join(Environment.NewLine, me.GetProfileToDb(Program.p.db.GetR(), true).Select(x => x.Key + ": " + x.Value)),
                    Footer      = new EmbedFooterBuilder
                    {
                        Text = "Achievements progression is kept hidden"
                    }
                }.Build());
            }
            else if (guild == null)
            {
                await ReplyAsync("I don't have any information stored about you.");
            }
        }
コード例 #21
0
ファイル: Information.cs プロジェクト: Kadantte/Sanara
        public async Task Status()
        {
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Information);

            int          yes   = 0;
            int          no    = 0;
            EmbedBuilder embed = new EmbedBuilder()
            {
                Title = Sentences.ServicesAvailability(Context.Guild.Id)
            };
            string description = "";

            for (Program.Module i = 0; i < Program.Module.Youtube; i++)
            {
                description += "**" + i.ToString() + "**: " + ((Program.p.db.IsAvailable(Context.Guild.Id, i)) ? (Sentences.Enabled(Context.Guild.Id)) : (Sentences.Disabled(Context.Guild.Id))) + Environment.NewLine;
            }
            embed.Description = description;
            if (Program.p.db.IsAvailable(Context.Guild.Id, Program.Module.Radio))
            {
                embed.AddField("Radio Module",
                               "**Opus dll:** " + ((File.Exists("opus.dll") ? ("Yes") : ("No"))) + Environment.NewLine +
                               "**Lib Sodium dll:** " + ((File.Exists("libsodium.dll") ? ("Yes") : ("No"))) + Environment.NewLine +
                               "**Ffmpeg:** " + ((File.Exists("ffmpeg.exe") ? ("Yes") : ("No"))) + Environment.NewLine +
                               "**youtube-dl:** " + ((File.Exists("youtube-dl.exe") ? ("Yes") : ("No"))) + Environment.NewLine +
                               "**YouTube API key:** " + ((p.youtubeService != null ? ("Yes") : ("No"))));
                if (File.Exists("opus.dll") && File.Exists("libsodium.dll") && File.Exists("ffmpeg.exe") && p.youtubeService != null)
                {
                    yes++;
                }
                else
                {
                    no++;
                }
            }
            if (Program.p.db.IsAvailable(Context.Guild.Id, Program.Module.Game))
            {
                embed.AddField("Game Module", ScoreManager.GetInformation(Context.Guild.Id, ref yes, ref no));
            }
            if (Program.p.db.IsAvailable(Context.Guild.Id, Program.Module.Linguistic))
            {
                embed.AddField("Linguistic Module - Translations",
                               "**Google Translate API key:** " + ((p.translationClient != null ? ("Yes") : ("No"))) + Environment.NewLine +
                               "**Google Vision API key:** " + ((p.visionClient != null ? ("Yes") : ("No"))));
                if (p.translationClient != null)
                {
                    yes++;
                    if (p.visionClient != null)
                    {
                        yes++;
                    }
                    else
                    {
                        no++;
                    }
                }
                else
                {
                    no += 2;
                }
            }
            embed.AddField("Information Module - Logs", "**GitHub API key:** " + (p.GitHubKey != null ? "Yes" : "No"));
            if (p.GitHubKey != null)
            {
                yes++;
            }
            else
            {
                no++;
            }
            embed.AddField("Anime/Manga Module - NSFW", "**Kitsu logins:** " + (p.kitsuAuth != null ? "Yes" : "No"));
            embed.AddField("Anime/Manga Module - Subscription", "**Subscription channel:** " + await p.db.GetMyChannelNameAsync(Context.Guild));
            if (p.kitsuAuth != null)
            {
                yes++;
            }
            else
            {
                no++;
            }
            if (Program.p.db.IsAvailable(Context.Guild.Id, Program.Module.Youtube))
            {
                embed.AddField("YouTube Module", "**YouTube API key:** " + ((p.youtubeService != null) ? ("Yes") : ("No")));
                if (p.youtubeService != null)
                {
                    yes++;
                }
                else
                {
                    no++;
                }
            }
            if (yes + no == 0)
            {
                yes++;
            }
            int max = yes + no;

            embed.Color = new Color(no * 255 / max, yes * 255 / max, 0);
            Dictionary <string, int> allTrads = new Dictionary <string, int>();

            foreach (var elem in Program.p.allLanguages)
            {
                allTrads.Add(elem.Key, 0);
            }
            foreach (var s in Program.p.translations)
            {
                if (s.Value.Any(x => x.language == "en"))
                {
                    foreach (var trad in s.Value)
                    {
                        allTrads[trad.language]++;
                    }
                }
            }
            string finalLanguage = "";
            int    enRef         = allTrads["en"];

            foreach (var s in allTrads)
            {
                finalLanguage += CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Program.p.allLanguages[s.Key][0]) + ": " + (s.Value * 100 / enRef) + "%" + Environment.NewLine;
            }
            embed.AddField(Sentences.TranslationsAvailability(Context.Guild.Id), finalLanguage);
            await ReplyAsync("", false, embed.Build());
        }
コード例 #22
0
        public async Task Help(params string[] args)
        {
            await p.DoAction(Context.User, Program.Module.Information);

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title = Sentences.Help(Context.Guild),
                Color = Color.Purple
            };
            string animeMangaModule       = Sentences.AnimeMangaModuleName(Context.Guild);
            string arknightsModule        = Sentences.ArknightsModuleName(Context.Guild);
            string booruModule            = Sentences.BooruModuleName(Context.Guild);
            string codeModule             = Sentences.CodeModuleName(Context.Guild);
            string communicationModule    = Sentences.CommunicationModuleName(Context.Guild);
            string communityModule        = Sentences.CommunityModuleName(Context.Guild);
            string doujinshiModule        = Sentences.DoujinshiModuleName(Context.Guild);
            string gameModule             = Sentences.GameModuleName(Context.Guild);
            string informationModule      = Sentences.InformationModuleName(Context.Guild);
            string kantaiCollectionModule = Sentences.KantaiCollectionModuleName(Context.Guild);
            string linguisticModule       = Sentences.LinguisticModuleName(Context.Guild);
            string radioModule            = Sentences.RadioModuleName(Context.Guild);
            string settingsModule         = Sentences.SettingsModuleName(Context.Guild);
            string visualNovelModule      = Sentences.VisualNovelModuleName(Context.Guild);
            string xkcdModule             = Sentences.XkcdModuleName(Context.Guild);
            string youtubeModule          = Sentences.YoutubeModuleName(Context.Guild);
            string page     = string.Join(" ", args).ToLower();
            var    textChan = Context.Channel as ITextChannel;
            var    isNsfw   = textChan == null ? false : textChan.IsNsfw;

            if (page != "" && (page == "1" || animeMangaModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + animeMangaModule + ")";
                embed.Description = Sentences.AnimeMangaHelp(Context.Guild, Settings.CanModify(Context.User, Context.Guild));
            }
            else if (page != "" && (page == "2" || arknightsModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + arknightsModule + ")";
                embed.Description = Sentences.ArknightsHelp(Context.Guild);
            }
            else if (page != "" && (page == "3" || booruModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + booruModule + ")";
                embed.Description = Sentences.BooruHelp(Context.Guild, isNsfw);
            }
            else if (page != "" && (page == "4" || codeModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + codeModule + ")";
                embed.Description = Sentences.CodeHelp(Context.Guild);
            }
            else if (page != "" && (page == "5" || communicationModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + communicationModule + ")";
                embed.Description = Sentences.CommunicationHelp(Context.Guild);
            }
            else if (page != "" && (page == "6" || communityModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + communityModule + ")";
                embed.Description = Sentences.CommunityHelp(Context.Guild, Context.User.Id == Base.Sentences.ownerId);
            }
            else if (page != "" && (page == "7" || doujinshiModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + doujinshiModule + ")";
                embed.Description = Sentences.DoujinshiHelp(Context.Guild, isNsfw);
            }
            else if (page != "" && (page == "8" || gameModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + gameModule + ")";
                embed.Description = Sentences.GameHelp(Context.Guild, isNsfw);
            }
            else if (page != "" && (page == "9" || informationModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + informationModule + ")";
                embed.Description = Sentences.InformationHelp(Context.Guild);
            }
            else if (page != "" && (page == "10" || kantaiCollectionModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + kantaiCollectionModule + ")";
                embed.Description = Sentences.KantaiCollectionHelp(Context.Guild);
            }
            else if (page != "" && (page == "11" || linguisticModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + linguisticModule + ")";
                embed.Description = Sentences.LinguisticHelp(Context.Guild, isNsfw);
            }
            else if (page != "" && (page == "12" || radioModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + radioModule + ")";
                embed.Description = Sentences.RadioHelp(Context.Guild);
            }
            else if (page != "" && (page == "13" || settingsModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + settingsModule + ")";
                embed.Description = Sentences.SettingsHelp(Context.Guild, Settings.CanModify(Context.User, Context.Guild), Context.User.Id == Base.Sentences.ownerId);
            }
            else if (page != "" && (page == "14" || visualNovelModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + visualNovelModule + ")";
                embed.Description = Sentences.VisualNovelHelp(Context.Guild);
            }
            else if (page != "" && (page == "15" || xkcdModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + xkcdModule + ")";
                embed.Description = Sentences.XkcdHelp(Context.Guild);
            }
            else if (page != "" && (page == "16" || youtubeModule.ToLower().Contains(page)))
            {
                embed.Title      += " (" + youtubeModule + ")";
                embed.Description = Sentences.YouTubeHelp(Context.Guild);
            }
            else
            {
                var guildId = Context.Guild?.Id ?? 0;
                embed.Description = Sentences.HelpHelp(Context.Guild) + Environment.NewLine +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.AnimeManga) ? "**1**: " + animeMangaModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Arknights) ? "**2**: " + arknightsModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Booru) ? "**3**: " + booruModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Code) ? "**4**: " + codeModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Communication) ? "**5**: " + communicationModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Community) ? "**6**: " + communityModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Doujinshi) ? "**7**: " + doujinshiModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Game) ? "**8**: " + gameModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Information) ? "**9**: " + informationModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Kancolle) ? "**10**: " + kantaiCollectionModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Linguistic) ? "**11**: " + linguisticModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Radio) ? "**12**: " + radioModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Settings) ? "**13**: " + settingsModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Vn) ? "**14**: " + visualNovelModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Xkcd) ? "**15**: " + xkcdModule + Environment.NewLine : "") +
                                    (Program.p.db.IsAvailable(guildId, Program.Module.Youtube) ? "**16**: " + youtubeModule + Environment.NewLine: "");
            }
            await ReplyAsync("", false, embed.Build());
        }
コード例 #23
0
        public async Task Complete(params string[] args)
        {
            Utilities.CheckAvailability(Context.Guild, Program.Module.Communication);
            await p.DoAction(Context.User, Program.Module.Communication);

            IUserMessage message    = null;
            string       content    = string.Join(" ", args);
            string       oldContent = content;
            var          result     = await Features.Tools.Communication.Complete(args,
                                                                                  (e) =>
            {
                content += " " + e;
            },
                                                                                  (e) =>
            {
                var embed = new EmbedBuilder
                {
                    Color       = Color.Red,
                    Description = e
                }.Build();
                if (message != null)
                {
                    message.ModifyAsync(x => x.Embed = embed).GetAwaiter().GetResult();
                }
                else
                {
                    ReplyAsync("", false, embed).GetAwaiter().GetResult();
                }
            },
                                                                                  () =>
            {
                if (message != null)
                {
                    message.ModifyAsync(x => x.Embed = new EmbedBuilder
                    {
                        Color       = Color.Blue,
                        Description = content
                    }.Build()).GetAwaiter().GetResult();
                }
                content = null;
            });

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

                break;

            case Features.Tools.Error.Complete.None:
                message = await ReplyAsync("", false, new EmbedBuilder
                {
                    Color       = Color.Blue,
                    Description = content,
                    Footer      = new EmbedFooterBuilder
                    {
                        Text = Sentences.CompleteWait(Context.Guild)
                    }
                }.Build());

                await Task.Run(async() =>
                {
                    while (content != null)
                    {
                        await Task.Delay(2000);
                        if (content != null && oldContent != content)
                        {
                            await message.ModifyAsync(x => x.Embed = new EmbedBuilder
                            {
                                Color       = Color.Blue,
                                Description = content,
                                Footer      = new EmbedFooterBuilder
                                {
                                    Text = Sentences.CompleteWait(Context.Guild)
                                }
                            }.Build());
                        }
                        oldContent = content;
                    }
                });

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #24
0
        public async Task Quote(params string[] id)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Communication);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Communication);

            IUser author = (id.Length == 0) ? (null) : (await Utilities.GetUser(string.Join("", id), Context.Guild));

            if (id.Length == 0 || author != null)
            {
                if (author == null)
                {
                    author = Context.User;
                }
                IMessage msg = (await Context.Channel.GetMessagesAsync().FlattenAsync()).Skip(1).ToList().Find(x => x.Author.Id == author.Id);
                if (msg == null)
                {
                    await ReplyAsync(Sentences.QuoteNoMessage(Context.Guild.Id));
                }
                else
                {
                    await ReplyAsync("", false, new EmbedBuilder()
                    {
                        Description = msg.Content
                    }.WithAuthor(msg.Author.ToString(), msg.Author.GetAvatarUrl()).WithFooter("The " + msg.CreatedAt.ToString(Base.Sentences.DateHourFormat(Context.Guild.Id)) + " in " + msg.Channel.Name).Build());
                }
            }
            else
            {
                IMessage msg = null;
                Match    url = Regex.Match(id[0], "https:\\/\\/discordapp.com\\/channels\\/" + Context.Guild.Id + "\\/([0-9]{18})\\/([0-9]{18})");
                if (url.Success)
                {
                    ulong idChan, idMsg;
                    if (ulong.TryParse(url.Groups[1].Value, out idChan) && ulong.TryParse(url.Groups[2].Value, out idMsg))
                    {
                        msg = await(await Context.Guild.GetTextChannelAsync(idChan))?.GetMessageAsync(idMsg);
                    }
                }
                else
                {
                    ulong uId;
                    try
                    {
                        uId = Convert.ToUInt64(id[0]);
                    }
                    catch (FormatException)
                    {
                        await ReplyAsync(Sentences.QuoteInvalidId(Context.Guild.Id));

                        return;
                    }
                    catch (OverflowException)
                    {
                        await ReplyAsync(Sentences.QuoteInvalidId(Context.Guild.Id));

                        return;
                    }
                    msg = await Context.Channel.GetMessageAsync(uId);

                    if (msg == null)
                    {
                        foreach (IGuildChannel chan in await Context.Guild.GetChannelsAsync())
                        {
                            try
                            {
                                ITextChannel textChan = chan as ITextChannel;
                                if (textChan == null)
                                {
                                    continue;
                                }
                                msg = await textChan.GetMessageAsync(uId);

                                if (msg != null)
                                {
                                    break;
                                }
                            }
                            catch (HttpException) { }
                        }
                    }
                }
                if (msg == null)
                {
                    await ReplyAsync(Sentences.QuoteInvalidId(Context.Guild.Id));
                }
                else
                {
                    await ReplyAsync("", false, new EmbedBuilder()
                    {
                        Description = msg.Content
                    }.WithAuthor(msg.Author.ToString(), msg.Author.GetAvatarUrl()).WithFooter("The " + msg.CreatedAt.ToString(Base.Sentences.DateHourFormat(Context.Guild.Id)) + " in " + msg.Channel.Name).Build());
                }
            }
        }
コード例 #25
0
        public async Task Status()
        {
            await p.DoAction(Context.User, Program.Module.Information);

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title = Sentences.ServicesAvailability(Context.Guild)
            };
            var textChan = Context.Channel as ITextChannel;

            if (textChan != null && !textChan.IsNsfw)
            {
                embed.WithFooter("Ask again in a NSFW channel for a more complete status.");
            }
            List <string> disabledModules = new List <string>();

            for (Program.Module i = 0; i <= Enum.GetValues(typeof(Program.Module)).Cast <Program.Module>().Max(); i++)
            {
                if (!Program.p.db.IsAvailable(Context.Guild?.Id ?? 0, i))
                {
                    disabledModules.Add(i.ToString());
                }
            }
            embed.Description = disabledModules.Count == 0 ? "All modules are enabled" : "Disabled modules:" + string.Join(", ", disabledModules);
            string[] toCheck = new[]
            {
                "opus.dll", "libsodium.dll", "ffmpeg.exe", "youtube-dl.exe",
            };
            List <string> missingFiles = new List <string>();

            foreach (string file in toCheck)
            {
                if (!File.Exists(file))
                {
                    missingFiles.Add(file);
                }
            }
            if (p.translationClient == null)
            {
                missingFiles.Add("Google Translate API Key");
            }
            if (p.visionClient == null)
            {
                missingFiles.Add("Google Vision API Key");
            }
            if (p.GitHubKey == null)
            {
                missingFiles.Add("GitHub API Key");
            }
            if (p.kitsuAuth == null)
            {
                missingFiles.Add("Kitsu Logins");
            }
            if (p.youtubeService == null)
            {
                missingFiles.Add("YouTube API Key");
            }
            embed.AddField("Missing Files", missingFiles.Count == 0 ? "None" : string.Join(", ", missingFiles));
            embed.AddField("Game Dictionnaries", ScoreManager.GetInformation(Context.Guild));
            if (Context.Guild != null)
            {
                embed.AddField("Anime/Manga Subscription Channel", await p.db.GetMyChannelNameAnimeAsync(Context.Guild));
                if (textChan.IsNsfw)
                {
                    var doujinChan = await p.db.GetMyChannelNameDoujinshiAsync(Context.Guild);

                    embed.AddField("Doujinshi Subscription Channel", doujinChan?.Mention ?? "None");
                    if (doujinChan != null)
                    {
                        var tags = Program.p.db.NHentaiSubscription.Where(x => x.Item1.Id == doujinChan.Id).ElementAt(0);
                        embed.AddField("Doujinshi Subscription Tags", "Whitelist: " + tags.Item2.GetWhitelistTags() + Environment.NewLine + "Blacklist: " + tags.Item2.GetBlacklistTags());
                    }
                }
            }
            embed.AddField("Profile Count", Program.p.cm.GetProfileCount(), true);
            embed.AddField("Anime Subscription Count", Program.p.db.AnimeSubscription.Count(), true);
            if (textChan == null || textChan.IsNsfw)
            {
                embed.AddField("Doujinshi Subscription Count", Program.p.db.NHentaiSubscription.Count(), true);
            }
            embed.Color = Color.Blue;
            Dictionary <string, int> allTrads = new Dictionary <string, int>();

            foreach (var elem in Program.p.allLanguages)
            {
                allTrads.Add(elem.Key, 0);
            }
            foreach (var s in Program.p.translations)
            {
                if (s.Value.Any(x => x.language == "en"))
                {
                    foreach (var trad in s.Value)
                    {
                        allTrads[trad.language]++;
                    }
                }
            }
            string finalLanguage = "";
            int    enRef         = allTrads["en"];

            foreach (var s in allTrads)
            {
                finalLanguage += CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Program.p.allLanguages[s.Key][0]) + ": " + (s.Value * 100 / enRef) + "%" + Environment.NewLine;
            }
            embed.AddField(Sentences.TranslationsAvailability(Context.Guild), finalLanguage);
            await ReplyAsync("", false, embed.Build());
        }
コード例 #26
0
        private async Task ManageModule(IMessageChannel chan, string[] args, int enable)
        {
            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));

                return;
            }
            if (args.Length == 0)
            {
                await chan.SendMessageAsync(Sentences.ModuleManagementHelp(Context.Guild.Id) + " " + GetModuleList(Context.Guild.Id));

                return;
            }
            Program.Module?module = null;
            string         name   = Utilities.AddArgs(args).Replace(" ", "");

            if (name == "all") // Enable/Disable all modules at once
            {
                if (enable == 1 && Program.p.db.AreAllAvailable(Context.Guild.Id))
                {
                    await chan.SendMessageAsync(Sentences.AllModulesAlreadyEnabled(Context.Guild.Id));
                }
                else if (enable == 0 && Program.p.db.AreNoneAvailable(Context.Guild.Id))
                {
                    await chan.SendMessageAsync(Sentences.AllModulesAlreadyDisabled(Context.Guild.Id));
                }
                else
                {
                    for (Program.Module i = 0; i <= Program.Module.Youtube; i++)
                    {
                        // We can't disable Settings and Information module
                        // We however can enable them, just in case
                        if (enable == 0 && (i == Program.Module.Settings || i == Program.Module.Information))
                        {
                            continue;
                        }
                        await Program.p.db.SetAvailability(Context.Guild.Id, i, enable);
                    }
                    if (enable == 1)
                    {
                        await chan.SendMessageAsync(Sentences.AllModulesEnabled(Context.Guild.Id));
                    }
                    else
                    {
                        await chan.SendMessageAsync(Sentences.AllModulesDisabled(Context.Guild.Id));
                    }
                }
                return;
            }
            for (Program.Module i = 0; i <= Program.Module.Youtube; i++)
            {
                if (i == Program.Module.Settings || i == Program.Module.Information)
                {
                    continue;
                }
                if (i.ToString().ToLower() == name.ToLower())
                {
                    module = i;
                    break;
                }
            }
            if (module == null)
            {
                await chan.SendMessageAsync(Sentences.ModuleManagementInvalid(Context.Guild.Id) + " " + GetModuleList(Context.Guild.Id));

                return;
            }
            bool availability = Program.p.db.IsAvailable(Context.Guild.Id, module.Value);

            if (availability && enable == 1)
            {
                await chan.SendMessageAsync(Sentences.ModuleAlreadyEnabled(Context.Guild.Id, module.ToString()));
            }
            else if (!availability && enable == 0)
            {
                await chan.SendMessageAsync(Sentences.ModuleAlreadyDisabled(Context.Guild.Id, module.ToString()));
            }
            else
            {
                await Program.p.db.SetAvailability(Context.Guild.Id, module.Value, enable);

                if (enable == 1)
                {
                    await chan.SendMessageAsync(Sentences.ModuleEnabled(Context.Guild.Id, module.ToString()));
                }
                else
                {
                    await chan.SendMessageAsync(Sentences.ModuleDisabled(Context.Guild.Id, module.ToString()));
                }
            }
        }