Example #1
0
        public void Invoke(DiscordHandler client, CommandHandler handler, CommandEventArg args)
        {
            args.Parameters[0] = args.Parameters[0].Trim('<', '>', '@', '!');

            DiscordUser user = null;

            if (ulong.TryParse(args.Parameters[0], out ulong uid))
            {
                try
                {
                    user = client.GetUserAsync(uid).ConfigureAwait(false).GetAwaiter().GetResult();
                }
                catch (Exception)
                {
                }
            }

            if (user == null)
            {
                args.Channel.SendMessageAsync($"User {args.Parameters[0]} not found");
                return;
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
            {
                Title        = $"Userinfo for {user.Username} ({user.Id})",
                ThumbnailUrl = user.AvatarUrl,
                Timestamp    = DateTime.UtcNow
            };

            using DBContext c = new DBContext();
            User u = c.User.FirstOrDefault(u => u.DiscordUserId == (long)uid);

            if (u != null)
            {
                builder.AddField("Osu UserId", u.OsuUserId.ToString(CultureInfo.CurrentCulture));
            }

            if (args.Guild != null)
            {
                try
                {
                    DiscordMember dmember = args.Guild.GetMemberAsync(uid).ConfigureAwait(false).GetAwaiter().GetResult();

                    builder.AddField("Join Date", dmember.JoinedAt.ToString(CultureInfo.CurrentCulture));
                }
                catch (Exception)
                {
                }
            }

            builder.AddField("Created On", user.CreationTimestamp.UtcDateTime.ToString(CultureInfo.CurrentCulture));

            builder.AddField("Verified", (u != null).ToString(CultureInfo.CurrentCulture));

            args.Channel.SendMessageAsync(embed: builder.Build());
        }
Example #2
0
        public void Invoke(DiscordHandler client, CommandHandler handler, CommandEventArg args)
        {
            if (args.Parameters.Count == 0)
            {
                args.Channel.SendMessageAsync($"{args.User.Mention} your access level is {Program.DiscordHandler.CommandHandler.GetAccessLevel(args.User, args.Guild)}");
                return;
            }

            if (!ulong.TryParse(args.Parameters[0], out ulong uid))
            {
                HelpCommand.ShowHelp(args.Channel, this, string.Format(ResourceExceptions.FailedParseException, args.Parameters[0]));
                return;
            }

            var         duser  = client.GetUserAsync(uid).Result;
            AccessLevel access = Program.DiscordHandler.CommandHandler.GetAccessLevel(duser, args.Guild);

            if (args.Parameters.Count == 1)
            {
                args.Channel.SendMessageAsync($"Access level of user {duser.Username} is {access}");
                return;
            }
            else if (args.AccessLevel < AccessLevel.Admin)
            {
                HelpCommand.ShowHelp(args.Channel, this);
                return;
            }


            AccessLevel newAccess;

            if (args.Parameters[1].TryParseEnum(out AccessLevel acc))
            {
                newAccess = acc;
            }
            else
            {
                HelpCommand.ShowHelp(args.Channel, this, string.Format(ResourceExceptions.FailedParseException, "Access Level"));
                return;
            }

            switch (newAccess)
            {
            case AccessLevel.Dev:
                args.Channel.SendMessageAsync("Dev permission can only be set via db");
                return;

            case AccessLevel.Host:
                if (args.AccessLevel < AccessLevel.Host)
                {
                    args.Channel.SendMessageAsync("You need to be atleast Host to set someone to host!");
                    return;
                }
                break;

            case AccessLevel.Admin:
                if (args.AccessLevel < AccessLevel.Host)
                {
                    args.Channel.SendMessageAsync("Only the host can add more admins!");
                    return;
                }
                break;

            default:
                break;
            }

            CommandHandler.SetAccessLevel(uid, args.Guild.Id, newAccess);

            args.Channel.SendMessageAsync($"Set {uid} from {access} to {newAccess}");
        }