Exemplo n.º 1
0
        public async Task GetInboundChannelAsync(SocketGuild g, Server s)
        {
            if (s.Config.InboundChannel == 0)
            {
                Embed e = EmbedData.Throw(Context, $"**CrossChat** is currently unbound to a channel.");
                await ReplyAsync(embed : e);

                return;
            }

            if (!g.TryGetTextChannel(s.Config.InboundChannel, out SocketTextChannel c))
            {
                Embed e = EmbedData.Throw(Context, $"{g.Name} is lacking the saved channel.", "This channel no longer exists, and the inbound channel will now be reset.", false);
                await ReplyAsync(embed : e);

                // find a default value.
                s.Config.InboundChannel = 0;
                return;
            }

            EmbedBuilder emb = EmbedData.DefaultEmbed;

            emb.WithColor(EmbedData.GetColor("error"));
            emb.WithDescription($"**CrossChat** is currently bound to {c.Mention}.");

            await ReplyAsync(embed : emb.Build());
        }
Exemplo n.º 2
0
        public static Embed RoleAssignTemplate()
        {
            List <WerewolfRole> roles      = WerewolfManager.GenerateRoles(8, out WerewolfTickGenerator t);
            List <string>       addedroles = new List <string>();
            string       shift             = $"{(t.Shift > 0 ? "+" : "")}{t.Shift} Equinox";
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("error"));
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("**Assigning Roles...**\n");

            foreach (WerewolfRole role in roles)
            {
                if (addedroles.Contains(role.Name))
                {
                    continue;
                }
                string pv = role.PointValue > 0 ? $"+{role.PointValue}" : $"{role.PointValue}";
                sb.AppendLine($"**x{roles.InstanceCount(role)}** | {role.Name.MarkdownBold()} ({pv})");
                sb.AppendLine($"{role.Summary}");

                addedroles.Add(role.Name);
            }
            e.WithDescription(sb.ToString());
            e.WithFooter($"{shift} | {t.PlayerCount} Players");
            return(e.Build());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Asynchronously returns embed data fetched from remote service without retries.
        /// </summary>
        /// <param name="context">The context of the request.</param>
        /// <returns>A task that represents the asynchronous fetch operation.</returns>
        private async Task <EmbedData> FetchOnceAsync(RequestContext context)
        {
            var hc = context.Service.HttpClient;

            var res = await hc.GetAsync($"http://ext.nicovideo.jp/api/getthumbinfo/sm" + VideoId).ConfigureAwait(false);

            if (!res.IsSuccessStatusCode)
            {
                return(null);
            }

            EmbedData d = null;

            EmbedData getOrCreate() => d ?? (d = new EmbedData());

            using (var s = await res.Content.ReadAsStreamAsync().ConfigureAwait(false))
                using (var xr = XmlReader.Create(s))
                {
                    while (xr.Read())
                    {
                        if (xr.Depth == 2 && xr.NodeType == XmlNodeType.Element)
                        {
                            switch (xr.LocalName)
                            {
                            case "title":
                                getOrCreate().Title = xr.ReadElementContentAsString();
                                break;

                            case "description":
                                getOrCreate().Description = xr.ReadElementContentAsString();
                                break;

                            case "thumbnail_url":
                                getOrCreate().MetadataImage = new Media
                                {
                                    Thumbnail = new ImageInfo
                                    {
                                        Url = xr.ReadElementContentAsString()
                                    }
                                };
                                break;

                            case "watch_url":
                                getOrCreate().Url = xr.ReadElementContentAsString();
                                break;

                            case "user_id":
                                getOrCreate().AuthorUrl = $"http://www.nicovideo.jp/user/" + xr.ReadElementContentAsString();
                                break;

                            case "user_nickname":
                                getOrCreate().AuthorName = xr.ReadElementContentAsString();
                                break;
                            }
                        }
                    }
                }

            return(Data = (d?.Title == null ? null : d));
        }
Exemplo n.º 4
0
        public async Task WagerDiceRollRangeAsync(OldAccount a, int wager, int size, int midpoint, bool dir = false)
        {
            Dice d   = new Dice(size);
            int  min = dir ? 1 : 2;
            int  max = dir ? (size - 1) : size;

            // exception catchers.
            if (!midpoint.IsInRange(min, max))
            {
                EmbedBuilder e = new EmbedBuilder();
                e.WithColor(EmbedData.GetColor("error"));

                if (!a.Config.Overflow)
                {
                    await ReplyAsync(embed : EmbedData.Throw(Context, "Midpoint out of range.", $"The midpoint must be inside the range of {min} to {max}.", false));

                    return;
                }
                midpoint = midpoint.InRange(min, max);
            }

            CasinoResult outcome = CasinoService.BetRangedRoll(a, d, wager, midpoint, dir);

            await ReplyAsync(embed : outcome.Generate());
        }
Exemplo n.º 5
0
            public async Task ContinueQueueAsync()
            {
                var displayEmbed = new EmbedBuilder();

                displayEmbed.WithColor(EmbedData.GetColor("yield"));
                displayEmbed.WithTitle("Continuing queue.");
                displayEmbed.WithDescription("Please wait...");

                var selfVoice    = Context.Guild.GetCurrentUserAsync().Result.VoiceChannel ?? null;
                var contextVoice = (Context.User as IGuildUser).VoiceChannel ?? null;

                if (contextVoice == null && selfVoice == null)
                {
                    await ReplyAsync("`I need a channel to connect to in order to play audio.`");

                    return;
                }
                else if (selfVoice == null)
                {
                    await _audio.JoinVoiceChannel(Context.Guild, contextVoice);
                }

                if (_audio.Queue(Context.Guild).Count.Equals(0) || _audio.Stream(Context.Guild))
                {
                    return;
                }

                //await ConnectAsync();
                var display = await ReplyAsync(null, false, displayEmbed.Build());

                await _audio.CheckQueue(Context.Guild, Context.Channel, display);
            }
Exemplo n.º 6
0
        public static void EmbedManyFiles(string fileToReadFrom, string assemblyToEmbedTo)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(EmbedData));
            EmbedData     data       = default(EmbedData);

            using (var fileStream = File.OpenRead(fileToReadFrom))
            {
                data = (EmbedData)serializer.Deserialize(fileStream);
            }

            var directory = new DirectoryInfo(data.directoryRelativeTo);

            //Console.WriteLine("All Files = " + data.files);

            foreach (var file in data.files.Split(';'))
            {
                if (file != "")
                {
                    //Console.WriteLine("File = " + file);
                    //Console.WriteLine("Directory = " + directory.FullName);
                    //Console.WriteLine("Full File Name = " + directory.FullName + "\\" + file);
                    EmbedResourceCMD.EmbedResource(assemblyToEmbedTo, directory.FullName + "\\" + file, file, compression: Enums.CompressionMethod.NoCompression);
                }
            }
        }
Exemplo n.º 7
0
 internal HuffTable(EmbedData d, int l)
 {
     this.dis = d;
     // Get table data from input stream
     this.len = 19 + GetTableData();
     SetSizeTable();     // Flow Chart C.1
     SetCodeTable();     // Flow Chart C.2
     SetOrderCodes();    // Flow Chart C.3
     SetDecoderTables(); // Generate decoder tables Flow Chart F.15
 }
Exemplo n.º 8
0
        // bet on a dice roll with n amount of sides
        // choose the sides that you think it will land on.
        public async Task WagerDiceRollAsync(OldAccount a, int wager, int size, params int[] clear)
        {
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("error"));

            Dice d = new Dice(size);

            string err = "";

            if (clear.Length == 0)
            {
                err = "You need to at least place one landing point.";
                await ReplyAsync(embed : EmbedData.Throw(Context, "Empty landing points.", err, false));

                return;
            }

            if (clear.Length > (d.Sides - 1))
            {
                err = $"You can only place up to {d.Sides - 1} landing points.";
                await ReplyAsync(embed : EmbedData.Throw(Context, "Max landing points hit.", err, false));

                return;
            }

            List <int> called = new List <int>();

            foreach (int safe in clear)
            {
                if (safe > d.Sides)
                {
                    err = $"You can't place a landing point higher than {d.Sides}.";
                    await ReplyAsync(embed : EmbedData.Throw(Context, "Landing point out of range.", err, false));

                    return;
                }
                if (safe.EqualsAny(called))
                {
                    err = "You cannot place a landing point on a side twice.";
                    await ReplyAsync(embed : EmbedData.Throw(Context, "Duplicate landing point.", err, false));

                    return;
                }
                else
                {
                    called.Add(safe);
                }
            }

            CasinoResult outcome = CasinoService.BetSelectiveRoll(a, d, wager, clear);

            await ReplyAsync(embed : outcome.Generate());
        }
Exemplo n.º 9
0
        public async Task GamesResponseAsync()
        {
            WerewolfGame g = new WerewolfGame();
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("error"));
            e.WithTitle("Ori's Arcade Zone");
            e.WithDescription($"{g.Status} **{g.Name}**\n{g.Summary}");//"The arcade is currently closed. Please hang tight while the arcade is being repaired. Sorry about that.");
            e.WithFooter("The arcade is currently closed. :(");
            await ReplyAsync(embed : e.Build());
        }
Exemplo n.º 10
0
        public static Embed DeathTemplate()
        {
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("error"));
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"**PLAYER_NAME** has died. {GetRandomDeathCause()}");
            sb.AppendLine($"PLAYER_NAME proved themselves to be many things, but they preferred that you call them a  **{WerewolfManager.GetAnyRole().Name}**."); // <Description based on player's influence>
            e.WithDescription(sb.ToString());
            return(e.Build());
        }
Exemplo n.º 11
0
        public static Embed RoleGenerationTemplate()
        {
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("yield"));
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Generating Roles...".MarkdownBold());
            e.WithDescription(sb.ToString());
            e.WithFooter(GetFact());
            return(e.Build());
        }
Exemplo n.º 12
0
        public async Task ViewCrossChatAsync(Server s)
        {
            SocketGuild  g = s.Guild(Context.Client);
            EmbedBuilder e = EmbedData.DefaultEmbed;


            StringBuilder sb = new StringBuilder();

            sb.Append(s.Config.CrossChat ? "**CrossChat** is active" : "**CrossChat** is currently disabled.");

            if (s.Config.CrossChat)
            {
                bool hasDefault = Context.TryGetPrimaryChatChannel(g, out SocketTextChannel def);
                if (s.Config.InboundChannel > 0)
                {
                    if (!g.TryGetTextChannel(s.Config.InboundChannel, out SocketTextChannel inb))
                    {
                        sb.AppendLine(", but is missing the inbound channel.");
                        if (hasDefault)
                        {
                            sb.AppendLine($"All messages will be sent to {def.Mention}.");
                        }
                        else
                        {
                            sb.AppendLine("No messages can be received at this time, due to the lack of a default chat channel.");
                        }
                    }
                    else
                    {
                        sb.AppendLine($", and is bound to {inb.Mention}.");
                    }
                }
                else
                {
                    sb.AppendLine(", but is currently unbound to a channel.");
                    if (hasDefault)
                    {
                        sb.AppendLine($"All messages will be sent to {def.Mention}.");
                    }
                    else
                    {
                        sb.AppendLine("No messages can be received at this time, due to the lack of a default chat channel.");
                    }
                }
            }
            else
            {
                e.WithColor(EmbedData.GetColor("error"));
            }

            e.WithDescription(sb.ToString());
            await ReplyAsync(embed : e.Build());
        }
Exemplo n.º 13
0
            public async Task GetPinAsync()
            {
                if (!Context.Channel.HasPins(out IReadOnlyCollection <RestMessage> pins))
                {
                    await ReplyAsync(embed : EmbedData.Throw(Context, "This channel has no pinned messages."));

                    return;
                }

                RestMessage pin = pins.ToList()[RandomProvider.Instance.Next(1, pins.Count) - 1];
                await ModuleManager.TryExecute(Context.Channel, Context.Channel.SendRestMessageAsync(pin));
            }
Exemplo n.º 14
0
        private Embed GetGambleError(OldAccount a, ulong wager)
        {
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(EmbedData.GetColor("error"));
            StringBuilder su = new StringBuilder();

            su.AppendLine($"Hello, {a.GetName()}.");
            su.AppendLine($"As you may know, I was accidently shut down during a wager you placed, and for that, I am sorry.");
            su.Append($"I have returned {EmojiIndex.Balance}{wager.ToPlaceValue().MarkdownBold()} to your wallet.");
            e.WithDescription(su.ToString());
            return(e.Build());
        }
Exemplo n.º 15
0
        private EmbedData ParseResponse(string xml, Item item)
        {
            var xd = new XmlDocument();

            xd.LoadXml(xml);

            foreach (XmlElement asin in xd.GetElementsByTagName("ASIN", "http://webservices.amazon.com/AWSECommerceService/2011-08-01"))
            {
                if (!item.Asin.Equals(asin.InnerText, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var itemElem   = (XmlElement)asin.ParentNode;
                var attributes = itemElem.Element("ItemAttributes");
                var title      = attributes?.Element("Title")?.InnerText;

                if (title == null)
                {
                    continue;
                }

                var sn = char.ToUpper(item.Destination[0]) + item.Destination.Substring(1);

                var d = new EmbedData()
                {
                    Title        = $"{title} - {sn}",
                    Url          = $"https://www.{item.Destination}/dp/{item.Asin}" + itemElem.Element("DetailPageURL")?.InnerText.ToUri().Query,
                    ProviderName = sn,
                    ProviderUrl  = $"https://www.{item.Destination}",
                };
                if (int.TryParse(attributes?.Element("IsAdultProduct")?.InnerText, out int i) && i > 0)
                {
                    d.RestrictionPolicy = RestrictionPolicies.Restricted;
                }

                var imageSets = itemElem.Element("ImageSets");

                if (imageSets != null)
                {
                    var elems = imageSets.Elements("ImageSet").Select(el => new
                    {
                        Category = el.GetAttribute("Category"),
                        Image    = el.ChildNodes
                                   .OfType <XmlElement>()
                                   .Select(ce => new ImageInfo
                        {
                            Url    = ce.Element("URL")?.InnerText,
                            Width  = int.TryParse(ce.Element("Width")?.InnerText, out var w) ? w : -1,
                            Height = int.TryParse(ce.Element("Height")?.InnerText, out var h) ? h : -1,
                        })
Exemplo n.º 16
0
        public async Task DoubleOrNothingAsync(OldAccount a, ulong wager, int times)
        {
            if (times <= 0)
            {
                string err = "You need to set the tick counter for the machine to land on.";
                await ReplyAsync(embed : EmbedData.Throw(Context, "Invalid tick counter.", err, false));

                return;
            }

            CasinoResult outcome = CasinoService.DoubleOrNothing(a, wager, times);

            await ReplyAsync(embed : outcome.Generate());
        }
Exemplo n.º 17
0
        public async Task GetReportAsync(OldGlobal g, ulong id)
        {
            OldAccount a = Context.Account;

            if (g.TryGetReport(id, out Report r))
            {
                await ReplyAsync(embed : r.Generate(a).Build());

                return;
            }

            Embed e = EmbedData.Throw(Context, "Invalid report.", $"R({id}) could not be found in the report collection.", false);

            await ReplyAsync(embed : e);
        }
Exemplo n.º 18
0
        // Constructor Method
        public HuffmanDecode(Stream data)
        {
            size = (int)data.Length;
            dis  = new EmbedData(data);
            // Parse out markers and header info
            bool cont = true;
            byte b;

            while (cont)
            {
                b = dis.Read();
                if (b == 255)
                {
                    b = dis.Read();
                    switch (b)
                    {
                    case 192:
                        SetSOF0();
                        break;

                    case 196:
                        SetDHT();
                        break;

                    case 219:
                        SetDQT();
                        break;

                    case 217:
                    case 218:
                        cont = false;
                        break;

                    case DRI:
                        SetDRI();
                        break;

                    default:
                        if (Array.IndexOf(APP, b) > -1)
                        {
                            dis.Seek(dis.ReadInt() - 2, SeekOrigin.Current);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 19
0
        public static Embed SecondMotionTemplate()
        {
            EmbedBuilder  e  = new EmbedBuilder();
            StringBuilder sb = new StringBuilder();

            e.WithTitle("An accusation has been made!");
            e.WithColor(EmbedData.GetColor("owo"));
            sb.AppendLine("**PLAYER_NAME_A** has seen enough of **PLAYER_NAME_B**'s tactics, and has accused them of being a **Werewolf**!");
            sb.AppendLine("Is there anybody else that follows through?");
            //sb.AppendLine("<10 seconds for anyone else to agree for trial>");
            e.WithDescription(sb.ToString());
            EmbedFooterBuilder f = new EmbedFooterBuilder();

            f.WithText("10 seconds until the window closes.");
            e.WithFooter(f);
            return(e.Build());
        }
Exemplo n.º 20
0
        private async Task <EmbedData> FetchAsyncCore(RequestContext context)
        {
            _LastFaulted = default(DateTime);

            if (Provider == null || Destination == null || Asin == null)
            {
                return(null);
            }
            try
            {
                return(Data = await Provider.FetchAsync(context.Service.HttpClient, Destination, Asin).ConfigureAwait(false));
            }
            catch
            {
                _LastFaulted = DateTime.Now;
                throw;
            }
        }
Exemplo n.º 21
0
            public async Task SetPlayAsync()
            {
                if (!_audio.Stream(Context.Guild))
                {
                    return;
                }
                if (_audio.IsPlaying(Context.Guild))
                {
                    return;
                }
                _audio.SetOutput(Context.Guild, true);
                var oriGreen     = EmbedData.GetColor("origreen");
                var displayEmbed = new EmbedBuilder();

                displayEmbed.WithColor(oriGreen);
                displayEmbed.WithTitle("The queue is now playing.");
                await ReplyAsync(null, false, displayEmbed.Build());
            }
Exemplo n.º 22
0
        private async void ProcessPayload(string payload)
        {
            try {
                EmbedData embedData = JsonConvert.DeserializeObject <EmbedData>(payload);

                EmbedBuilder eb = null;
                eb = new EmbedBuilder {
                    Color = new Color(embedData.Color ?? (uint)EmbedColor.SalmonPink)
                };
                eb.Title       = embedData.Title;
                eb.Description = embedData.Description;
                eb.Url         = embedData.URL;
                eb.ImageUrl    = embedData.IconURL;
                if (embedData.Author != null && embedData.Author != "")
                {
                    eb.WithAuthor(embedData.Author, embedData.AuthorIconURL, embedData.AuthorURL);
                }
                if (embedData.Fields != null)
                {
                    foreach (EmbedFieldData efdata in embedData.Fields)
                    {
                        if ((efdata.Name ?? "") != "" && (efdata.Value ?? "") != "")
                        {
                            eb.AddField(efdata.Name, efdata.Value, efdata.Inline);
                        }
                    }
                }
                if ((embedData.Footer ?? "") != "")
                {
                    eb.WithFooter(embedData.Footer, embedData.FooterIcon);
                }

                List <string> tags = new List <string>();
                foreach (string tag in embedData.Tags)
                {
                    tags.Add(tag);
                }

                await DiscordAPIHelper.PublishNews(eb, _databaseManager, _discordSocketClient, tags.ToArray());
            }
            catch (Exception e) {
                Logger.LogError("Error processing " + Prefix + " payload: " + e.Message);
            }
        }
Exemplo n.º 23
0
        public async Task SetInboundChannelAsync(SocketGuildUser u, Server s, SocketGuild g, SocketTextChannel c)
        {
            if (!u.EnsureRank(s, g))
            {
                await ReplyAsync(embed : EmbedData.Throw(Context, "Unensured.", "You must be ensured to configure **CrossChat's** inbound channel.", false));

                return;
            }

            EmbedBuilder e = EmbedData.DefaultEmbed;

            e.WithTitle("Inbound channel set.");
            e.WithDescription($"Inbound messages will now be sent to {c.Mention}.");

            s.Config.SetInboundChannel(c);
            await ReplyAsync(embed : e.Build());

            Context.Data.Update(s);
        }
Exemplo n.º 24
0
        public EmbedBuilder GenerateChatBox(OldAccount a, Server s, SocketGuild g, string content)
        {
            string        command = "message";
            List <string> demobl  = new List <string> {
                "darn"
            };
            List <string>      blacklist = Context.Data.Blacklist.Merge(s.Config.Blacklist, demobl);
            EmbedBuilder       e         = new EmbedBuilder();
            EmbedFooterBuilder f         = new EmbedFooterBuilder();

            f.WithText($"{s.Config.GetPrefix(Context)}{command} {Context.Guild.Id} <{nameof(content)}>");

            e.WithColor(EmbedData.GetColor("origreen"));
            e.WithDescription(s.Config.SafeChat ? content.Guard(blacklist).Escape('*') : content);
            e.WithTitle($"{EmojiIndex.CrossChat.Pack(a)} {a.GetName()}");
            e.WithFooter(f);

            return(e);
        }
Exemplo n.º 25
0
            public async Task SetPauseAsync()
            {
                if (!_audio.Stream(Context.Guild))
                {
                    return;
                }
                if (!_audio.IsPlaying(Context.Guild))
                {
                    return;
                }
                var yieldColor = EmbedData.GetColor("yield");

                _audio.SetOutput(Context.Guild, false);
                var displayEmbed = new EmbedBuilder();

                displayEmbed.WithColor(yieldColor);
                displayEmbed.WithTitle("The queue has been paused.");
                await ReplyAsync(null, false, displayEmbed.Build());
            }
Exemplo n.º 26
0
        public EmbedBuilder Generate(OldAccount a)
        {
            EmbedBuilder e       = new EmbedBuilder();
            Emoji        icon    = Type.Icon();
            string       user    = $"{Author.Name}";
            string       subject = $"Subject: {Subject.MarkdownBold()}";
            string       title   = $"{icon.Pack(a)} | {user} | {Command}\n{subject}";
            string       footer  = $"Case: {Id}";

            EmbedFooterBuilder f = new EmbedFooterBuilder();

            f.WithText(footer);

            e.WithColor(EmbedData.GetColor("error"));
            e.WithTitle(title);
            e.WithDescription(Content);
            e.WithFooter(f);

            return(e);
        }
Exemplo n.º 27
0
            public async Task TogglePlayAsync()
            {
                if (!_audio.Stream(Context.Guild))
                {
                    return;
                }
                _audio.SetOutput(Context.Guild, !_audio.IsPlaying(Context.Guild));
                var displayEmbed = new EmbedBuilder();
                var yieldColor   = EmbedData.GetColor("yield");

                displayEmbed.WithColor(yieldColor);
                displayEmbed.WithTitle("The queue has been paused.");
                if (_audio.IsPlaying(Context.Guild))
                {
                    var oriGreen = EmbedData.GetColor("origreen");
                    displayEmbed.WithColor(oriGreen);
                    displayEmbed.WithTitle("The queue is now playing.");
                }
                await ReplyAsync(null, false, displayEmbed.Build());
            }
Exemplo n.º 28
0
            public async Task DisplayCurrentAudioAsync()
            {
                var queue              = _audio.Queue(Context.Guild).ToList();
                var displayEmbed       = new EmbedBuilder();
                var displayEmbedFooter = new EmbedFooterBuilder();

                displayEmbed.WithColor(213, 16, 93);
                displayEmbed.WithTitle("Stopped:");
                if (queue.Count == 0)
                {
                    displayEmbed.WithDescription("Nothing is currently playing.");
                    await ReplyAsync(null, false, displayEmbed.Build());

                    return;
                }
                var prevQueue = queue[0].Value;

                displayEmbed.WithDescription($"{prevQueue.Title} ({prevQueue.Duration})");
                if (_audio.IsPlaying(Context.Guild))
                {
                    displayEmbed.WithColor(129, 243, 193);
                    displayEmbed.WithTitle("Now playing:");
                }
                else if (_audio.Stream(Context.Guild))
                {
                    displayEmbed.WithColor(EmbedData.GetColor("yield"));
                    displayEmbed.WithTitle("Paused:");
                }
                if (queue.Count == 1)
                {
                    await ReplyAsync(null, false, displayEmbed.Build());

                    return;
                }
                var nextQueue = queue[1].Value;

                displayEmbed.WithFooter(displayEmbedFooter.WithText($"Up Next => {nextQueue.Title} ({nextQueue.Duration})"));
                var msg = await ReplyAsync(null, false, displayEmbed.Build());
            }
Exemplo n.º 29
0
        /// <summary>
        /// Asynchronously returns embed data fetched from remote service without retries.
        /// </summary>
        /// <param name="context">The context of the request.</param>
        /// <returns>A task that represents the asynchronous fetch operation.</returns>
        private async Task <EmbedData> FetchOnceAsync(RequestContext context)
        {
            var hc = context.Service.HttpClient;

            var redirection = await hc.FollowRedirectAsync(OEmbedUrl.ToUri()).ConfigureAwait(false);

            var r = redirection.Message;

            r.EnsureSuccessStatusCode();

            var txt = await r.Content.ReadAsStringAsync().ConfigureAwait(false);

            Dictionary <string, object> values;

            if (r.Content.Headers.ContentType.MediaType == "text/xml")
            {
                values = new Dictionary <string, object>();
                var d = new XmlDocument();
                d.LoadXml(txt);

                foreach (XmlNode xn in d.DocumentElement.ChildNodes)
                {
                    if (xn.NodeType == XmlNodeType.Element)
                    {
                        var e = (XmlElement)xn;
                        // TODO: parse number
                        values[e.LocalName] = e.InnerText;
                    }
                }
            }
            else
            {
                var jo = JObject.Parse(txt);
                values = jo.ToObject <Dictionary <string, object> >();
            }

            return(Data = CreateEmbedData(values));
        }
Exemplo n.º 30
0
        public async Task GetReportsAsync(OldGlobal g, int page = 1)
        {
            EmbedBuilder e = EmbedData.DefaultEmbed;

            EmbedFooterBuilder f = new EmbedFooterBuilder();

            f.WithText($"{EmojiIndex.Report} Reports");
            e.WithFooter(f);

            const int MAX_DESC = 1024;
            string    desc     = "";

            List <string> list         = new List <string>();
            List <string> descriptions = new List <string>();

            List <Report> reports  = g.Reports;
            List <Report> accepted = g.AcceptedReports;


            foreach (Report accept in accepted)
            {
                list.Add("**+** " + accept.ToString(Context.Account));
            }
            foreach (Report r in reports)
            {
                list.Add(r.ToString(Context.Account));
            }
            if (!list.Funct())
            {
                await ReplyAsync(embed : EmbedData.Throw(Context, "Empty collection.", "There are currently no reports.", false));

                return;
            }

            Embed q = EmbedData.GenerateEmbedList(list, page, e);

            await ReplyAsync(embed : q);
        }
Exemplo n.º 31
0
		private static void FindEmbedFields(ModuleContainer module, ClassOrStruct cl, List<EmbedData> embeds) {
			foreach (var m in cl.Members) {
				var f = m as Field;
				if (f == null || f.OptAttributes == null || f.OptAttributes.Attrs.Count == 0)
					continue;

				if (!(f.TypeExpression is TypeExpression) || f.TypeExpression.Type != module.Compiler.BuiltinTypes.Type)
					continue;

				Mono.CSharp.Attribute embedAttr = null;
				foreach (var attr in f.OptAttributes.Attrs) {
					if (attr.Name == "Embed") {
						embedAttr = attr;
						break;
					}
				}

				if (embedAttr == null)
					continue;

				var e = new EmbedData();
				e._index = _embedCount;
				_embedCount++;
				e._className = "__EmbedLoader" + e._index;
				e._field = f;

				e.source = e.mimeType = e.embedAsCFF = e.fontFamily = e.symbol = "null";

				foreach (NamedArgument arg in embedAttr.NamedArguments) {
					if (!(arg.Expr is StringLiteral))
						continue;
					var s = ((StringLiteral)(arg.Expr)).GetValueAsLiteral();
					switch (arg.Name) {
					case "source": e.source = s; break;
					case "mimeType": e.mimeType = s; break;
					case "embedAsCFF": e.embedAsCFF = s; break;
					case "fontFamily": e.fontFamily = s; break;
					case "symbol": e.symbol = s; break;
					}
				}

				embeds.Add (e);

			}
		}