Exemplo n.º 1
0
        /// <summary>
        /// uploads the bot emojis to the server, if possible
        /// </summary>
        /// <param name="guild">the guild on which to upload the emoji</param>
        /// <param name="channel">the channel on which to send the error messages, if allowed</param>
        /// <param name="showErrors">shows error messages</param>
        /// <returns></returns>
        public async Task VerifyServerEmojis(DiscordGuild guild, DiscordChannel channel = null, bool showErrors = false)
        {
            var missingEmojis = _Configuration.Emojis.Where(x => !guild.Emojis.Values.Any(e => e.Name == x.DiscordName));

            if (missingEmojis.Any())
            {
                //bot has the right to add emojis
                if (PermissionsManager.UserHasPermission(guild, _Client.CurrentUser, Permissions.ManageEmojis))
                {
                    //check if the server has the required amount of emoji slots
                    if (50 - guild.Emojis.Count < missingEmojis.Count())
                    {
                        if (channel != null)
                        {
                            await channel.SendMessageAsync($"the server doesn't have enough emoji slots left for me");
                        }

                        return;
                    }

                    foreach (var emoji in missingEmojis)
                    {
                        if (!guild.Emojis.Values.Any(x => x.Name == emoji.DiscordName))
                        {
                            var localFilePath = Path.Combine(Directory.GetCurrentDirectory(), emoji.LocalPath);
                            using (var stream = File.OpenRead(localFilePath))
                            {
                                await guild.CreateEmojiAsync(emoji.DiscordName, stream);
                            }
                        }
                    }
                }
                else if (showErrors)
                {
                    if (channel != null)
                    {
                        await channel.SendMessageAsync($"i dont have the right to modify emoji");
                    }
                }
            }
        }