Esempio n. 1
0
        public Embed GetDiscordEmbed(LocaleSetting locale, out GuildEmote subEmote, out GuildEmote specialEmote, SocketGuild guild)
        {
            try
            {
                Image img = new Image(WebRequest.Create(GetSubWeapon().GetImageUrl()).GetResponse().GetResponseStream());
                subEmote = guild.CreateEmoteAsync(Name, img).GetAwaiter().GetResult();
            }
            catch
            {
                subEmote = null;
            }

            try
            {
                Image img = new Image(WebRequest.Create(GetSpecialWeapon().GetImageUrl()).GetResponse().GetResponseStream());
                specialEmote = guild.CreateEmoteAsync(Name, img).GetAwaiter().GetResult();
            }
            catch
            {
                specialEmote = null;
            }

            Embed eb = new EmbedBuilder()
                       .WithTitle(GetName(locale))
                       .WithThumbnailUrl(GetImageUrl())
                       .WithColor(new Color(0x00, 0xFF, 0x00))
                       .AddField("Sub Weapon", (subEmote == null ? "" : $"{subEmote} ") + $"*{GetSubWeapon().GetName(locale)}*")
                       .AddField("Special", (specialEmote == null ? "" : $"{specialEmote} ") + $"*{GetSpecialWeapon().GetName(locale)}*")
                       .AddField(Data.Locales[(int)locale].First(x => x.Key == Param0).Value, $"{ASCIIUI.CreateTextBar(ParamValue0, 100)} **[{ParamValue0}/100]**")
                       .AddField(Data.Locales[(int)locale].First(x => x.Key == Param1).Value, $"{ASCIIUI.CreateTextBar(ParamValue1, 100)} **[{ParamValue1}/100]**")
                       .AddField(Data.Locales[(int)locale].First(x => x.Key == Param2).Value, $"{ASCIIUI.CreateTextBar(ParamValue2, 100)} **[{ParamValue2}/100]**")
                       .Build();

            return(eb);
        }
        private async Task <EmoteAssociation> AddEmoteToEmoteGuilds(Emote em)
        {
            SocketGuild guild       = null;
            Stream      emoteStream = null;

            using (HttpClient client = new HttpClient())
            {
                emoteStream = await client.GetStreamAsync(em.Url);
            }

            int animCount = 0, staticCount = 0;

            foreach (var id in _config.Private_Guilds)
            {
                guild       = Context.Client.GetGuild(id);
                animCount   = guild.Emotes.Count(x => x.Animated);
                staticCount = guild.Emotes.Count(x => !x.Animated);
                if ((em.Animated && animCount < Defined.MAX_EMOTES_IN_GUILD) ||
                    (!em.Animated && staticCount < Defined.MAX_EMOTES_IN_GUILD))
                {
                    break;
                }
            }
            if ((em.Animated && animCount < Defined.MAX_EMOTES_IN_GUILD) ||
                (!em.Animated && staticCount < Defined.MAX_EMOTES_IN_GUILD))
            {
                var addedEmote = await guild.CreateEmoteAsync(em.Name, new Discord.Image(emoteStream));

                return(new EmoteAssociation(addedEmote, guild.Id));
            }

            emoteStream.Dispose();
            return(default(EmoteAssociation));
        }
Esempio n. 3
0
        /// <summary>
        /// Runs updates to the system read from the Silph road.
        /// </summary>
        /// <param name="guilds">List of guilds the bot is currently in.</param>
        /// <returns>Completed Task.</returns>
        public async Task RunSilphUpdate(List <SocketGuild> guilds)
        {
            UpdatePokemonNameList();
            UpdateMoveNameList();
            UpdateEggList();
            UpdateRocketList();

            Dictionary <int, List <string> > newBosses = SilphData.GetRaidBosses();

            bool bossesChanged = RaidBosses.Keys.Count != newBosses.Keys.Count || !RaidBosses.Keys.All(newBosses.Keys.Contains);

            foreach (int tier in RaidBosses.Keys)
            {
                bossesChanged = bossesChanged || RaidBosses[tier].Count != newBosses[tier].Count || !RaidBosses[tier].All(newBosses[tier].Contains);
            }

            if (bossesChanged)
            {
                if (SilphData.GetRaidBossesConfirmed())
                {
                    UpdateRaidBossList();
                    SocketGuild  emoteServer    = guilds.FirstOrDefault(x => x.Name.Equals(Global.EMOTE_SERVER, StringComparison.OrdinalIgnoreCase));
                    GuildEmote[] previousEmotes = emoteServer.Emotes.ToArray();

                    foreach (GuildEmote emote in emoteServer.Emotes)
                    {
                        await emoteServer.DeleteEmoteAsync(emote);
                    }

                    foreach (KeyValuePair <int, List <string> > tier in RaidBosses)
                    {
                        foreach (string boss in tier.Value)
                        {
                            string fileName = GetPokemonPicture(boss);
                            CopyFile(fileName);
                            Image img = new Image(fileName);
                            await emoteServer.CreateEmoteAsync(fileName.Remove(fileName.Length - 4), img);

                            img.Dispose();
                            DeleteFile(fileName);
                        }
                    }

                    Dictionary <ulong, ulong> channels = Instance().GetNotificationChannels();

                    foreach (KeyValuePair <ulong, ulong> chan in channels)
                    {
                        SocketGuild           guild   = guilds.FirstOrDefault(x => x.Id == chan.Key);
                        ISocketMessageChannel channel = (ISocketMessageChannel)guild.Channels.FirstOrDefault(x => x.Id == chan.Value);
                        await ClearNotifyMessage(guild, channel.Id, previousEmotes.ToArray());
                        await SetNotifyMessage(guild, channel, emoteServer.Emotes.ToArray());
                    }
                }
            }
        }
 public virtual Task <GuildEmote> CreateEmoteAsync(string name, Image image, Optional <IEnumerable <IRole> > roles = default, RequestOptions?options = null)
 {
     return(_socketGuild.CreateEmoteAsync(name, image, roles, options));
 }
Esempio n. 5
0
        public async Task Custom(string name, string fontName, string color, string fontSize, [Remainder] string text)
        {
            if (!Program.Owners.Contains(Context.User.Id))
            {
                await Utility.SendEmbedMessage(Context, "이 커맨드를 실행할 권한이 없습니다.");

                return;
            }

            name = new string(name.Where(c => alpha.Contains(c.ToString())).ToArray());
            if (name.Length == 1)
            {
                await Utility.SendEmbedMessage(Context, "이름이 한 글자 이하인 이모지를 만들 수 없습니다.");

                return;
            }

            FontFamily font = new FontFamily(fontName == "_" ? "NanumGothic" : fontName);

            Bitmap   img     = new Bitmap(512, 512);
            Graphics graphic = Graphics.FromImage(img);

            graphic.Clear(System.Drawing.Color.Transparent);

            graphic.InterpolationMode  = InterpolationMode.High;
            graphic.SmoothingMode      = SmoothingMode.HighQuality;
            graphic.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
            graphic.CompositingQuality = CompositingQuality.HighQuality;

            int   len  = text.Length;
            float size = fontSize == "_" ? (len == 1 ? 300 : len <= 4 ? 225 : 175) : int.Parse(fontSize);

            GraphicsPath path = new GraphicsPath();

            path.AddString(text, font, style, size, rect, format);
            graphic.DrawPath(pen, path);
            graphic.FillPath(new SolidBrush(System.Drawing.Color.FromName(color == "_" ? "White" : color)), path);

            graphic.Dispose();

            SocketGuild guild = GetChoGuild(text[0]);

            if (guild == null)
            {
                await Utility.SendEmbedMessage(Context, "남은 이모지 슬롯이 없습니다.");

                return;
            }

            if (GetChoGuilds(text[0]).Where(g => g.Emotes.Where(e => e.Name == name).Count() != 0).Count() == 0)
            {
                if (guild.Emotes.Where(e => !e.Animated).Count() < 50)
                {
                    img.Save($"img/{name}.png");
                    img.Dispose();

                    GuildEmote emote = await guild.CreateEmoteAsync(name, new Discord.Image($"img/{name}.png"));
                    await ReplyAsync(emote.ToString());
                }
                else
                {
                    AnimatedGifEncoder e = new AnimatedGifEncoder();
                    e.SetTransparent(System.Drawing.Color.Black);
                    e.Start($"img/{name}.gif");

                    e.SetDelay(1);
                    e.SetRepeat(-1);

                    e.AddFrame(img);
                    e.AddFrame(img);

                    e.Finish();
                    img.Dispose();

                    GuildEmote emote = await guild.CreateEmoteAsync(name, new Discord.Image($"img/{name}.gif"));
                    await ReplyAsync(emote.ToString());
                }
            }
            else
            {
                await Utility.SendEmbedMessage(Context, "이미 존재하는 이모지입니다.");
            }
        }