Esempio n. 1
0
        public async Task <Bitmap> RenderAsync(Discord.IUser user, int position, long points)
        {
            var bitmap = new Bitmap(1000, 300);

            using var graphics = Graphics.FromImage(bitmap);

            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            FillRectangle(graphics, new Rectangle(0, 0, bitmap.Width, bitmap.Height), Color.FromArgb(35, 39, 42), 15);
            FillRectangle(graphics, new Rectangle(50, 50, 900, 200), Color.FromArgb(100, 0, 0, 0), 15);

            var profileImage = await GetProfileImageAsync(user);

            graphics.DrawImage(profileImage, 70, 70, 160, 160);

            var positionTextSize = graphics.MeasureString($"#{position}", PositionFont);

            graphics.DrawString("BODY", TitleTextFont, WhiteBrush, new PointF(250, 180));
            graphics.DrawString(points.FormatWithSpaces(), PositionFont, new SolidBrush(Color.LightGray), new PointF(340, 150));
            var positionTitleTextSize = graphics.MeasureString("POZICE", TitleTextFont);

            graphics.DrawString("POZICE", TitleTextFont, WhiteBrush, new PointF(900 - positionTextSize.Width - positionTitleTextSize.Width, 180));
            graphics.DrawString($"#{position}", PositionFont, WhiteBrush, new PointF(910 - positionTextSize.Width, 150));

            var nickname = user.GetDisplayName(true).Cut(20);

            graphics.DrawString(nickname, NicknameFont, WhiteBrush, new PointF(250, 60));
            var nicknameSize = graphics.MeasureString(nickname, NicknameFont);

            graphics.DrawString($"#{user.Discriminator}", DiscriminatorFont, new SolidBrush(Color.DimGray), new PointF(260 + nicknameSize.Width, 76));

            return(bitmap);
        }
        public static string ContentWithMention(this Discord.IUser user, string content, ResultKind rmk = ResultKind.Default)
        {
            string middle;

            switch (rmk)
            {
            default:
            case ResultKind.Default:
                middle = " ";
                break;

            case ResultKind.Succeed:
                middle = " ✅";
                break;

            case ResultKind.Failed:
                middle = " 😦";
                break;

            case ResultKind.Warning:
                middle = " ⚠";
                break;

            case ResultKind.Forbidden:
                middle = " 🚫";
                break;
            }

            return(user.Mention + middle + content);
        }
Esempio n. 3
0
 public TradeOffer(Discord.IUser user, Discord.IUser target)
 {
     Author    = new Author(user);
     Target    = new Author(target);
     CreatedAt = DateTime.UtcNow;
     Id        = KeyBuilder.Generate(5);
 }
Esempio n. 4
0
 public static bool IsAdmin(this Discord.IUser user)
 {
     try {
         return(Data.SqliteManager.Get().IsAdmin(user.Id.ToString()));
     }
     catch (Exception) {
         return(user.Id == Data.Users.Ferrone.Id);
     }
 }
Esempio n. 5
0
        private async Task <Image> GetProfileImageAsync(Discord.IUser user)
        {
            var profileImageData = await user.DownloadAvatarAsync(128);

            using var profileImageStream = new MemoryStream(profileImageData);
            using var profileImage       = Image.FromStream(profileImageStream);

            return(profileImage.RoundCorners());
        }
Esempio n. 6
0
        public string JoinGame(Discord.IUser user)
        {
            if (!cardHolders.ContainsKey(user.Id))
            {
                cardHolders.Add(user.Id, new CardHolder(user.Username));
                return("Users currently in game: " + UsersToString());
            }

            return(String.Format("User {0} already in game", user.Username));
        }
Esempio n. 7
0
        public Profile GetOrCreateProfile(Discord.IUserMessage msg, Discord.IUser user)
        {
            if (_profiles.ContainsKey(user.Id))
            {
                return(_profiles[user.Id]);
            }
            Profile p = new Profile(msg, user);

            _profiles.Add(user.Id, p);
            Program.p.db.AddProfile(p);
            return(p);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new reminder from given parameters, adds it to the database, and returns it.
        /// </summary>
        /// <param name="User">The Issuer of the reminder.</param>
        /// <param name="Time">The time the reminder should release at.</param>
        /// <param name="Message">The content of the reminder.</param>
        /// <returns>A <c>Reminder</c> object which includes the assigned ID.</returns>

        public Reminder AddReminder(Discord.IUser User, DateTimeOffset Time, string Message)
        {
            Reminder r = new() {
                ID              = GenerateToken(),
                IssuerID        = User.Id,
                DateTimeRelease = Time.ToUnixTimeSeconds(),
                Message         = Message
            };

            Reminders.Add(r);
            SaveChanges();
            return(r);
        }
Esempio n. 9
0
        public async Task PeepoAngryAsync(Discord.IUser forUser = null)
        {
            if (forUser == null)
            {
                forUser = Context.User;
            }

            var config = await GetMethodConfigAsync <PeepoAngryConfig>(null, "peepoangry");

            using var service = GetService <MemeImagesService>();
            using var bitmap  = await service.Service.PeepoAngryAsync(forUser, config);
            await ReplyImageAsync(bitmap, "peepoangry.png");
        }
Esempio n. 10
0
        public static bool TryParseOffer(Discord.IUser user, Discord.IUser target, string input, out TradeOffer offer)
        {
            offer = null;

            input = input.Trim();
            var reader = new StringReader(input);

            // item,amount item,amount item

            bool requested = false;
            bool remainder = false;

            if (!reader.CanRead())
            {
                return(false); // throw new Exception("Expected a string to read but returned null");
            }
            var offered  = new Dictionary <string, int>();
            var requests = new Dictionary <string, int>();

            while (reader.CanRead())
            {
                string arg;
                int    amount = 1;

                if (!reader.GetRemaining().Contains(' '))
                {
                    arg       = reader.GetRemaining();
                    remainder = true;
                }
                else
                {
                    arg = reader.ReadUntil(' ');
                }

                if (arg == Separator)
                {
                    if (requested)
                    {
                        return(false); // throw new Exception("Offer separator has already been specified");
                    }
                    requested = true;
                    continue;
                }

                if (arg.Contains(','))
                {
                    if (arg.Count(x => x == ',') > 1)
                    {
                        return(false); // throw new Exception("Expected a single comma separator");
                    }
                    int.TryParse(arg[arg.IndexOf(',')..], out amount);
Esempio n. 11
0
        public static string GetAvatarUrlOrDefault(this Discord.IUser user)
        {
            string server = "https://discordapp.com";

            string[] DefaultAvatars = new string[] {
                "/assets/6debd47ed13483642cf09e832ed0bc1b.png",
                "/assets/322c936a8c8be1b803cd94861bdfa868.png",
                "/assets/dd4dbc0016779df1378e7812eabaa04d.png",
                "/assets/0e291f67c9274a1abdddeb3fd919cbaa.png",
                "/assets/1cbd08c76f8af6dddce02c5138971129.png"
            };

            string DefaultBotAvatar = "/assets/f78426a064bc9dd24847519259bc42af.png";

            if (string.IsNullOrEmpty(user.AvatarId))
            {
                if (user.IsBot)
                {
                    return(server + DefaultBotAvatar);
                }
                return(server + DefaultAvatars[user.DiscriminatorValue % DefaultAvatars.Length]);
            }
            return(user.GetAvatarUrl());
        }
Esempio n. 12
0
        public async Task <List <EmoteStatItem> > GetEmoteStatsForUserAsync(SocketGuild guild, Discord.IUser user, bool desc)
        {
            var userId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, user);

            if (userId == null)
            {
                return(new List <EmoteStatItem>());
            }

            var query = GrillBotRepository.EmoteStatsRepository.GetEmotesOfUser(userId.Value);

            if (desc)
            {
                query = query.OrderByDescending(o => o.UseCount).ThenByDescending(o => o.LastOccuredAt);
            }
            else
            {
                query = query.OrderBy(o => o.UseCount).ThenBy(o => o.LastOccuredAt);
            }

            return(await query.ToListAsync());
        }
Esempio n. 13
0
 // Messages
 public static string UserJoinNeeded(Discord.IUser u)
 {
     return($"{u.Mention}, try joining with `+join` first!");
 }
Esempio n. 14
0
        public void GenerateProfile(Profile profile, Discord.IUser user, Image pfpImage = null)
        {
            if (user != null)
            {
                profile.UpdateProfile(user);
            }
            using (var model = new Bitmap("Saves/Assets/Background.png"))
            {
                using (var bp = new Bitmap(model.Width, model.Height))
                {
                    using (var g = Graphics.FromImage(bp))
                    {
                        g.DrawImage(model, 0, 0);
                        Color color           = profile.GetBackgroundColor();
                        Brush backgroundBrush = new SolidBrush(Color.FromArgb(50, color.R, color.G, color.B));
                        g.FillRectangle(backgroundBrush, 0, 0, model.Width, model.Height);
                        if (user != null)
                        {
                            if (pfpImage == null)
                            {
                                pfpImage = profile.GetProfilePicture(user);
                            }
                            // Round the image, from: https://stackoverflow.com/questions/1758762/how-to-create-image-with-rounded-corners-in-c
                            int radius = 20;
                            using (var pfp = new Bitmap(pfpImage.Width, pfpImage.Height))
                            {
                                using (Graphics gPfp = Graphics.FromImage(pfp))
                                {
                                    Brush        brush = new TextureBrush(pfpImage);
                                    GraphicsPath gp    = new GraphicsPath();
                                    gp.AddArc(0, 0, radius, radius, 180, 90);
                                    gp.AddArc(0 + pfpImage.Width - radius, 0, radius, radius, 270, 90);
                                    gp.AddArc(0 + pfp.Width - radius, 0 + pfp.Height - radius, radius, radius, 0, 90);
                                    gp.AddArc(0, 0 + pfp.Height - radius, radius, radius, 90, 90);
                                    gPfp.FillPath(brush, gp);
                                }
                                g.DrawImage(pfp, 20, 20);
                            }
                        }

                        SizeF usernameSize = g.MeasureString(profile.GetUsername(), new Font("Arial", 23));
                        g.DrawString(profile.GetUsername(), new Font("Arial", 23), Brushes.Black, 170f, 70f, StringFormat.GenericDefault);
                        g.DrawString("#" + profile.GetDiscriminator(), new Font("Arial", 17), Brushes.Black, 170f + usernameSize.Width - 8f, 78f, StringFormat.GenericDefault);
                        g.DrawString(profile.GetDescription(), new Font("Arial", 15), Brushes.Black, 20f, 200f, StringFormat.GenericDefault);
                        g.DrawString("Friends: " + profile.GetFriendsCount(), new Font("Arial", 20), Brushes.Black, 460f, 15f, StringFormat.GenericDefault);
                        g.DrawString("Achievements: ", new Font("Arial", 20), Brushes.Black, 460f, 45f, StringFormat.GenericDefault);
                        int i = 0;
                        foreach (var a in profile.GetAchievements())
                        {
                            Brush medalBrush;
                            if (a.Item2 == 1)
                            {
                                medalBrush = new SolidBrush(Color.FromArgb(184, 115, 51));               // Copper
                            }
                            else if (a.Item2 == 2)
                            {
                                medalBrush = new SolidBrush(Color.FromArgb(196, 202, 206));                    // Silver
                            }
                            else
                            {
                                medalBrush = new SolidBrush(Color.FromArgb(255, 215, 0));  // Gold
                            }
                            int xPos = 460 + ((i % 4) * 70);
                            int yPos = 80 + ((i / 4) * 70);
                            g.FillPie(medalBrush, new Rectangle(xPos, yPos, 64, 64), 0, 360);
                            g.DrawImage(a.Item1, xPos, yPos);
                            i++;
                        }
                    }
                    bp.Save("Saves/Profiles/" + profile.GetId() + ".png");
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Gets a list of all reminders filtered by IssuerID, where the Issuer is <paramref name="User"/>.
        /// </summary>
        /// <param name="User">The Issuer of reminders to filter for.</param>
        /// <returns>A <c>Reminder[]</c> array, where all Issuers are <paramref name="User"/>.</returns>

        public Reminder[] GetRemindersByUser(Discord.IUser User)
        {
            return(GetRemindersByUser(User.Id));
        }
Esempio n. 16
0
        /// <summary>
        /// Adds a given <paramref name="Restriction"/> to a user's registry, and creates a new one if none exists for the given <paramref name="User"/>.
        /// </summary>
        /// <param name="User">The target User.</param>
        /// <param name="Restriction">The Restriction flags to add to <paramref name="User"/>.</param>
        /// <returns><see langword="false"/> if the user already had that <paramref name="Restriction"/>, otherwise <see langword="true"/>.</returns>

        public bool AddRestriction(Discord.IUser User, Restriction Restriction)
        {
            return(AddRestriction(User.Id, Restriction));
        }
Esempio n. 17
0
        /// <summary>
        /// Removes a set of restrictions <paramref name="Restriction"/> from a target <paramref name="User"/>.
        /// </summary>
        /// <param name="User">The target user.</param>
        /// <param name="Restriction">The Restriction flags to remove from <paramref name="User"/>.</param>
        /// <returns><see langword="true"/> if the restriction was removed, <see langword="false"/> if the user wasn't in the database or didn't have that restriction.</returns>

        public bool RemoveRestriction(Discord.IUser User, Restriction Restriction)
        {
            return(RemoveRestriction(User.Id, Restriction));
        }
Esempio n. 18
0
 public static string GetAvatarUrlOrDefault(this Discord.IUser user) => (user ?? throw new NullReferenceException()).GetAvatarUrl() ?? $"https://cdn.discordapp.com/embed/avatars/{user.DiscriminatorValue % 5}.png";
Esempio n. 19
0
        /// <summary>
        /// Gets all restrictions related to a <paramref name="User"/>, or NONE if the user's ID is not in the database.
        /// </summary>
        /// <param name="User">The User to fetch from the database.</param>
        /// <returns>A Restriction object representing all flags for which the user is restricted.</returns>

        public Restriction GetUserRestrictions(Discord.IUser User)
        {
            return(GetUserRestrictions(User.Id));
        }
Esempio n. 20
0
        /// <summary>
        /// Checks whether a given <paramref name="User"/> has a set of restrictions <paramref name="Restriction"/>.
        /// </summary>
        /// <param name="User">The target user to query the database for.</param>
        /// <param name="Restriction">The individual or multiple restriction(s) to check for.</param>
        /// <returns><see langword="true"/> if the <paramref name="User"/> has all restriction flags in <paramref name="Restriction"/>, otherwise <see langword="false"/>.</returns>

        public bool IsUserRestricted(Discord.IUser User, Restriction Restriction)
        {
            return(IsUserRestricted(User.Id, Restriction));
        }
Esempio n. 21
0
 public Task Run(Discord.IUser user)
 {
     return(Result(user.Username));
 }
Esempio n. 22
0
 public User(Discord.IUser user)
 {
     DiscordUser = user;
 }
Esempio n. 23
0
 public static bool IsAdmin(this Discord.IUser user)
 {
     return(Data.DataManager.database.isAdmin(user.Id.ToString()));
 }