コード例 #1
0
ファイル: CommandWho.cs プロジェクト: Lohikar/Agatha2
        internal override async Task ExecuteCommand(SocketMessage message, GuildConfig guild)
        {
            ModuleAetolia   aetolia      = (ModuleAetolia)parent;
            string          result       = "Authentication or network error.";
            HttpWebResponse aetInfo      = aetolia.GetAPIResponse("characters");
            EmbedBuilder    embedBuilder = new EmbedBuilder();

            if (aetInfo != null)
            {
                var s = aetInfo.GetResponseStream();
                if (s != null)
                {
                    StreamReader  sr             = new StreamReader(s);
                    List <string> characterNames = new List <string>();
                    foreach (JToken player in JObject.Parse(sr.ReadToEnd())["characters"])
                    {
                        characterNames.Add($"{player["name"]}");
                    }

                    if (characterNames.Count == 0)
                    {
                        result = "None";
                    }
                    else if (characterNames.Count == 1)
                    {
                        result = $"{characterNames[1]}";
                    }
                    else
                    {
                        result = "";
                        for (int i = 0; i < characterNames.Count; i++)
                        {
                            if (i != 0)
                            {
                                result += ", ";
                            }
                            if (i == (characterNames.Count - 1))
                            {
                                result += "and ";
                            }
                            result += characterNames[i];
                        }
                    }

                    string playerTerm;
                    if (characterNames.Count != 1)
                    {
                        playerTerm = $"are {characterNames.Count} people";
                    }
                    else
                    {
                        playerTerm = $"is {characterNames.Count} person";
                    }

                    result = $"{result}.\n\n**There {playerTerm} total online.**";
                }
            }
            embedBuilder.Description = result;
            await message.Channel.SendMessageAsync($"{message.Author.Mention}:", false, embedBuilder);
        }
コード例 #2
0
ファイル: CommandNstat.cs プロジェクト: Lohikar/Agatha2
        internal override async Task ExecuteCommand(SocketMessage message, GuildConfig guild)
        {
            ModuleAetolia   aetolia = (ModuleAetolia)parent;
            HttpWebResponse aetInfo = aetolia.GetAPIResponse("news");
            string          result  = "Unknown error.";

            if (aetInfo != null)
            {
                var s = aetInfo.GetResponseStream();
                if (s != null)
                {
                    result = "```\n-- The Aetolian News --------------------------------------";
                    StreamReader sr = new StreamReader(s);
                    foreach (var x in JToken.Parse(sr.ReadToEnd()))
                    {
                        string padding = new String(' ', 49 - (x["name"].ToString().Length + x["total"].ToString().Length));
                        result = $"{result}\n {x["name"]}:{padding}{x["total"]} posts.";
                    }
                    result = $"{result}\n-----------------------------------------------------------";
                    result = $"{result}\n Read individual posts using {guild.commandPrefix}READNEWS [SECTION] [NUMBER].";
                    result = $"{result}\n-----------------------------------------------------------\n```";
                }
            }

            await message.Channel.SendMessageAsync($"{message.Author.Mention}: {result}");
        }
コード例 #3
0
ファイル: CommandHonours.cs プロジェクト: Lohikar/Agatha2
        internal override async Task ExecuteCommand(SocketMessage message, GuildConfig guild)
        {
            ModuleAetolia aetolia = (ModuleAetolia)parent;
            string        result  = "There is no such person, I'm afraid.";

            string[] message_contents = message.Content.Substring(1).Split(" ");
            if (message_contents.Length < 2)
            {
                result = "Who do you wish to know about?";
            }
            else
            {
                HttpWebResponse aetInfo = aetolia.GetAPIResponse($"characters/{message_contents[1].ToLower()}");
                if (aetInfo != null)
                {
                    var s = aetInfo.GetResponseStream();
                    if (s != null)
                    {
                        StreamReader sr = new StreamReader(s);
                        JObject      ci = JObject.Parse(sr.ReadToEnd());
                        result = "```\n-------------------------------------------------------------------------------";
                        result = $"{result}\n{ci["fullname"]}";
                        result = $"{result}\n-------------------------------------------------------------------------------";
                        if (ci["class"].ToString().Equals("(none)"))
                        {
                            result = $"{result}\nThey are a level {ci["level"]} {ci["race"]} with no class.";
                        }
                        else
                        {
                            result = $"{result}\nThey are a level {ci["level"]} {ci["race"]} {ci["class"]}.";
                        }
                        if (ci["city"].ToString().Equals("(none)"))
                        {
                            result = $"{result}\nThey hold no citizenship.";
                        }
                        else
                        {
                            result = $"{result}\nThey are a citizen of {ci["city"]}.";
                        }
                        if (ci["guild"].ToString().Equals("(none)"))
                        {
                            result = $"{result}\nThey hold no guild membership.";
                        }
                        else
                        {
                            result = $"{result}\nThey are a member of the {ci["guild"]}.";
                        }
                        result = $"{result}\nThey are {ci["xp rank"].ToString().ToLower()} in experience, {ci["explore rank"].ToString().ToLower()} in exploration and {ci["combat rank"].ToString().ToLower()} in combat.";
                        result = $"{result}\n-------------------------------------------------------------------------------```";
                    }
                }
            }
            await message.Channel.SendMessageAsync($"{message.Author.Mention}: {result}");
        }
コード例 #4
0
ファイル: CommandReadnews.cs プロジェクト: Lohikar/Agatha2
        internal override async Task ExecuteCommand(SocketMessage message, GuildConfig guild)
        {
            ModuleAetolia aetolia = (ModuleAetolia)parent;

            string[] message_contents = message.Content.Substring(1).Split(" ");
            string   result;

            if (message_contents.Length < 2)
            {
                result = "Please specify a news section name.";
            }
            else if (message_contents.Length < 3)
            {
                result = "Please specify an article number.";
            }
            else
            {
                result = "Invalid article number or news section.";
                string postSection = message_contents[1].ToLower();
                string postNumber  = message_contents[2].ToLower();

                if (postSection.Equals("random") || postNumber.Equals("random"))
                {
                    HttpWebResponse newsInfo = aetolia.GetAPIResponse("news");
                    if (newsInfo != null)
                    {
                        var s = newsInfo.GetResponseStream();
                        if (s != null)
                        {
                            Dictionary <string, string> sections = new Dictionary <string, string>();
                            StreamReader sr = new StreamReader(s);
                            foreach (var x in JToken.Parse(sr.ReadToEnd()))
                            {
                                sections.Add(x["name"].ToString().ToLower(), x["total"].ToString());
                            }
                            if (postSection.Equals("random"))
                            {
                                int randInd = Program.rand.Next(sections.Count);
                                postSection = sections.ElementAt(randInd).Key.ToString();
                            }
                            if (postNumber.Equals("random") && sections.ContainsKey(postSection))
                            {
                                int tempValue = Convert.ToInt32(sections[postSection]);
                                postNumber = Program.rand.Next(tempValue).ToString();
                            }
                        }
                    }
                }

                HttpWebResponse aetInfo = aetolia.GetAPIResponse($"news/{postSection}/{postNumber}");
                if (aetInfo != null)
                {
                    var s = aetInfo.GetResponseStream();
                    if (s != null)
                    {
                        StreamReader sr       = new StreamReader(s);
                        JObject      postInfo = JObject.Parse(sr.ReadToEnd());
                        JToken       ci       = postInfo["post"];
                        DateTime     postDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        postDate = postDate.AddSeconds((int)ci["date"]);

                        result = $"```\n{ci["section"].ToString().ToUpper()} NEWS {ci["id"].ToString().ToUpper()}";
                        result = $"{result}\nDate: {postDate}";
                        result = $"{result}\nFrom: {ci["from"]}";
                        result = $"{result}\nTo:   {ci["to"]}";
                        result = $"{result}\nSubj: {ci["subject"]}\n";
                        string postString = ci["message"].ToString();
                        if (postString.Length > 1500)
                        {
                            string newsURL = $"https://www.aetolia.com/news/?game=Aetolia&section={ci["section"].ToString()}&number={ci["id"].ToString()}";
                            postString = $"{postString.Substring(0,1500)}...```\nPost has been trimmed for Discord: see the full text at {newsURL}.";
                        }
                        else
                        {
                            postString = $"{postString}```";
                        }
                        result = $"{result}\n{postString}";
                    }
                }
            }
            await message.Channel.SendMessageAsync($"{message.Author.Mention}: {result}");
        }