コード例 #1
0
ファイル: PrefixModule.cs プロジェクト: jfantonopoulos/Misaka
        public async Task Prefixes()
        {
            DateTime startTime = DateTime.Now;
            List <DiscordCustomPrefix> prefixList = await PrefixService.GetGuildPrefixes(Context.Guild);

            if (prefixList.Count == 0)
            {
                await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("The current guild has no custom prefixes."), lifeTime : Config.FeedbackMessageLifeTime);
            }
            else
            {
                EmbedBuilder embedBuilder = new EmbedBuilder();
                EmbedService.BuildSuccessEmbed(embedBuilder);
                embedBuilder.Title        = $"This guild has {prefixList.Count.ToString()} custom prefixes.";
                embedBuilder.Description += " ";
                foreach (DiscordCustomPrefix prefix in prefixList)
                {
                    embedBuilder.Description += $"{{  {prefix.Prefix.Bold()}  }}, ";
                }
                embedBuilder.Description = embedBuilder.Description.Substring(0, embedBuilder.Description.Length - 2);
                embedBuilder.WithFooter(footer =>
                {
                    footer.Text = $"⏰ {"Generated in:"}  {Math.Round((DateTime.Now.Subtract(startTime).TotalMilliseconds)).ToString()}ms";
                });
                await ReplyAsync("", embed : embedBuilder.Build());
            }
        }
コード例 #2
0
ファイル: DataModule.cs プロジェクト: jfantonopoulos/Misaka
        public async Task BTC()
        {
            EmbedBuilder embedBuilder = new EmbedBuilder();

            EmbedService.BuildSuccessEmbed(embedBuilder);
            string httpContent = await HttpService.Get("https://www.google.com/search?q=btc+to+usd&oq=btc+to+usd");

            var parser        = new HtmlParser(Configuration.Default.WithDefaultLoader(x => x.IsResourceLoadingEnabled = true));
            var document      = parser.Parse(httpContent);
            var gCardSelector = document.QuerySelector("div.currency.g.vk_c.obcontainer");

            if (gCardSelector != null)
            {
                var amtText = gCardSelector.QuerySelector("div.curtgt").TextContent;
                var imgSrc  = gCardSelector.QuerySelector("img#ccw_chart").Attributes["data-src"].Value + "&chs=400x250&chsc=1";
                embedBuilder.Title       = "💵 Current Bitcoin Worth in USD";
                embedBuilder.Description = $"**1** Bitcoin = {amtText.Replace(" US Dollar", "").Bold()} USD";
                embedBuilder.WithImageUrl(imgSrc);
                await ReplyAsync("", embed : embedBuilder.Build());
            }
        }
コード例 #3
0
        public async Task Toxicity()
        {
            string content = (await Context.Channel.GetMessagesAsync(10).Flatten()).ToList()[1].Content;

            try
            {
                string resp = await HttpService.Post($"https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key={Config.PerspectiveApiKey}", "{comment: {text: \"" + content + "\"}, languages: [\"en\"], requestedAttributes: {TOXICITY:{}, INCOHERENT:{}, OBSCENE:{}, SPAM:{}, INFLAMMATORY:{}}}");

                Dictionary <string, dynamic> json = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(resp));

                EmbedBuilder embedBuilder = new EmbedBuilder();
                embedBuilder.Title = "Google Perspective API";
                EmbedService.BuildSuccessEmbed(embedBuilder);
                embedBuilder.Description  = "";
                embedBuilder.Description += $"Reviewing Message [{content.Code()}]";
                embedBuilder.AddField(x =>
                {
                    x.Name     = ":skull_crossbones: Toxic";
                    x.Value    = ((float)json["attributeScores"]["TOXICITY"]["summaryScore"]["value"] * 100).ToString() + "%";
                    x.IsInline = true;
                });
                embedBuilder.AddField(x =>
                {
                    x.Name     = ":tropical_drink: Incoherent";
                    x.Value    = ((float)json["attributeScores"]["INCOHERENT"]["summaryScore"]["value"] * 100).ToString() + "%";
                    x.IsInline = true;
                });
                embedBuilder.AddField(x =>
                {
                    x.Name  = ":warning: Obscene";
                    x.Value = ((float)json["attributeScores"]["OBSCENE"]["summaryScore"]["value"] * 100).ToString() + "%";
                });
                embedBuilder.AddField(x =>
                {
                    x.Name     = ":love_letter: Spam";
                    x.Value    = ((float)json["attributeScores"]["SPAM"]["summaryScore"]["value"] * 100).ToString() + "%";
                    x.IsInline = true;
                });
                embedBuilder.AddField(x =>
                {
                    x.Name     = ":fire: Inflammatory";
                    x.Value    = ((float)json["attributeScores"]["INFLAMMATORY"]["summaryScore"]["value"] * 100).ToString() + "%";
                    x.IsInline = true;
                });
                await ReplyAsync("", embed : embedBuilder);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #4
0
ファイル: HelpModule.cs プロジェクト: jfantonopoulos/Misaka
        public async Task Syntax([Summary("The command name.")] CommandInfo cmdInfo)
        {
            EmbedBuilder embedBuilder = new EmbedBuilder();

            EmbedService.BuildSuccessEmbed(embedBuilder);
            embedBuilder.Title       = $"->{cmdInfo.Name.Code()} Command Syntax";
            embedBuilder.Description = cmdInfo.Summary.Code();
            foreach (var arg in cmdInfo.Parameters)
            {
                embedBuilder.AddField(x =>
                {
                    x.Name  = $":paperclip: {arg.Name} - {arg.Type.ToString().Bold()}";
                    x.Value = arg.Summary;
                });
            }

            await ReplyAsync("", embed : embedBuilder);
        }
コード例 #5
0
ファイル: VoiceModule.cs プロジェクト: jfantonopoulos/Misaka
        public async Task Queue()
        {
            ulong guildId = Context.Guild.Id;

            if (AudioService.Queue.Count(guildId) == 0)
            {
                await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed($"The queue is currently empty."), lifeTime : Config.FeedbackMessageLifeTime);

                return;
            }

            EmbedBuilder embedBuilder = new EmbedBuilder();

            EmbedService.BuildSuccessEmbed(embedBuilder);
            embedBuilder.Description = "";
            embedBuilder.Title       = "Audio Queue";
            int counter = 1;
            int limit   = 7;

            foreach (AudioInfo audioInfo in AudioService.Queue.GetQueue(guildId))
            {
                if (counter > limit)
                {
                    break;
                }

                embedBuilder.AddField(x =>
                {
                    x.Name  = $"#{counter.ToString().Bold()} {audioInfo.ItemInfo}";
                    x.Value = audioInfo.Url;
                });
                counter++;
            }

            embedBuilder.WithFooter(x => x.Text = $"{AudioService.Queue.Count(guildId)} item(s) in queue.");
            await ReplyAsync("", embed : embedBuilder.Build());
        }
コード例 #6
0
ファイル: StatsModule.cs プロジェクト: jfantonopoulos/Misaka
        public async Task Speedtest()
        {
            IUserMessage holdMessage = await ReplyAsync("", embed : EmbedService.MakeFeedbackEmbed(":satellite: Conducting speedtest, please hold..."));

            bool hasFailed = false;

            using (await Context.Channel.EnterTypingState(30))
            {
                Process process = new Process();
                process.StartInfo.FileName               = "speedtest-cli";
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                EmbedBuilder embed = new EmbedBuilder();

                process.OutputDataReceived += (sendingProcess, outLine) =>
                {
                    if (outLine == null || string.IsNullOrEmpty(outLine.Data))
                    {
                        return;
                    }

                    string line = outLine.Data;
                    if (line.StartsWith("Hosted by"))
                    {
                        embed.AddField(x =>
                        {
                            x.Name  = ":house: Closest Server";
                            x.Value = line.Replace("Hosted by", "");
                        });
                    }
                    else if (line.StartsWith("Download:"))
                    {
                        embed.AddField(x =>
                        {
                            x.Name  = ":arrow_down: Download";
                            x.Value = line.Replace("Download: ", "");
                        });
                    }
                    else if (line.StartsWith("Upload:"))
                    {
                        embed.AddField(x =>
                        {
                            x.Name  = ":arrow_up: Upload";
                            x.Value = line.Replace("Upload: ", "");
                        });
                    }
                };

                process.ErrorDataReceived += async(sendingProcess, outLine) =>
                {
                    if (outLine == null || string.IsNullOrEmpty(outLine.Data))
                    {
                        return;
                    }

                    await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed($"Failed to conduct speedtest: {outLine.Data}"), lifeTime : Config.FeedbackMessageLifeTime);

                    ConsoleEx.WriteColoredLine(LogSeverity.Warning, ConsoleTextFormat.TimeAndText, outLine.ToString());
                    hasFailed = true;
                };

                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();

                if (hasFailed)
                {
                    return;
                }

                EmbedService.BuildSuccessEmbed(embed);
                embed.Description = "";
                await ReplyAsync(embed);

                if (holdMessage != null)
                {
                    await holdMessage.DeleteAsync();
                }
            }
        }