Esempio n. 1
0
        private void ListCommands(CommandHandler handler, CommandEventArg args, char prefix, int page = 1)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            else if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            List <(ICommand, AccessLevel)> commands = handler.Commands.Values.Select(s => (s, s.AccessLevel)).ToList();

            for (int i = 0; i < commands.Count; i++)
            {
                AccessLevel newAccess = CommandHandler.GetCommandAccessLevel(commands[i].Item1, args.Guild?.Id ?? 0);

                if (newAccess > args.AccessLevel)
                {
                    commands.RemoveAt(i);
                    i--;
                    continue;
                }

                commands[i] = (commands[i].Item1, newAccess);
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
            {
                Title       = "Command List",
                Description = "Prefix: " + prefix,
                Timestamp   = DateTime.UtcNow
            };

            EmbedPageBuilder epb = new EmbedPageBuilder(3);

            epb.AddColumn("Command");
            epb.AddColumn("Access");
            epb.AddColumn("Description");

            for (int i = 0; i < commands.Count; i++)
            {
                epb.Add("Command", commands[i].Item1.Command);
                epb.Add("Access", commands[i].Item2.ToString());
                epb.Add("Description", commands[i].Item1.Description);
            }

            DiscordEmbed embed = epb.BuildPage(builder, page);

            args.Channel.SendMessageAsync(embed: embed).Wait();

            return;
        }
Esempio n. 2
0
        public void Invoke(CommandHandler handler, CommandEventArgs args)
        {
            int page = 1;

            if (args.Parameters.Count > 0 && int.TryParse(args.Parameters[0], out int p))
            {
                page = Math.Min(1, page);
            }

            EmbedPageBuilder epb = new EmbedPageBuilder(2);

            NetState[] states = NetState.Instances.ToArray();

            if (states.Length == 0)
            {
                args.Channel.SendEmbedMessage("No players currently online").ConfigureAwait(false);
                return;
            }

            epb.AddColumn("Player");
            epb.AddColumn("Connected Since");

            for (int i = 0; i < states.Length; i++)
            {
                if (states[i].IsDisposing || !states[i].Running || states[i].Mobile == null ||
                    states[i].Mobile.AccessLevel > args.AccessLevel)
                {
                    continue;
                }

                epb.Add("Player", states[i].Mobile.Name ?? "Unkown");
                epb.Add("Connected Since", states[i].ConnectedFor.ToString());
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder
            {
                Title     = "Online Players",
                Timestamp = DateTime.UtcNow
            };

            DiscordEmbed embed = epb.BuildPage(builder, page);

            args.Channel.SendMessageAsync(embed: embed).ConfigureAwait(false);
        }
Esempio n. 3
0
        private bool TryListBans(CommandEventArg args)
        {
            List <BannedUser> bans = BanManager.GetBans(guildId: args.Parameters.Count < 2 ? 0 :
                                                        args.Parameters[1].Equals("global", StringComparison.CurrentCultureIgnoreCase) ? 0 :
                                                        args.Parameters[1].Equals("local", StringComparison.CurrentCultureIgnoreCase) ? (long)args.Guild.Id : 0);

            if (bans.Count == 0)
            {
                HelpCommand.ShowHelp(args.Channel, this, "No bans found");
                return(true);
            }

            int page = 1;

            if (args.Parameters.Count >= 3 && int.TryParse(args.Parameters[2], out int page_))
            {
                page = page_;
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
            {
                Title       = "Ban list",
                Description = Resources.InvisibleCharacter
            };
            EmbedPageBuilder epb = new EmbedPageBuilder(3);

            epb.AddColumn("Discord ID");
            epb.AddColumn("Osu ID");
            epb.AddColumn("Reason");

            for (int i = 0; i < bans.Count; i++)
            {
                epb.Add("Discord ID", bans[i].DiscordUserId.ToString(CultureInfo.CurrentCulture));
                epb.Add("Osu ID", bans[i].OsuUserId.ToString(CultureInfo.CurrentCulture));
                epb.Add("Reason", string.IsNullOrEmpty(bans[i].Reason) ? "none" : bans[i].Reason);
            }

            DiscordEmbed embed = epb.BuildPage(builder, page);

            args.Channel.SendMessageAsync(embed: embed).ConfigureAwait(false);

            return(true);
        }
Esempio n. 4
0
        public void Invoke(DiscordHandler client, CommandHandler handler, CommandEventArg args)
        {
            if (args.Parameters[0].Equals("list", StringComparison.CurrentCultureIgnoreCase))
            {
                int page = 1;

                if (args.Parameters.Count > 1 && int.TryParse(args.Parameters[1], out int newPage))
                {
                    page = newPage;
                }

                using DBContext c = new DBContext();

                List <DiscordRoleBind> drbs = c.DiscordRoleBind.Where(drb => drb.GuildId == (long)args.Guild.Id).ToList();

                if (drbs.Count == 0)
                {
                    client.SendSimpleEmbed(args.Channel, "Could not find any role binds").ConfigureAwait(false);
                    return;
                }

                StringBuilder roleIdBuilder = new StringBuilder();
                StringBuilder accessBuilder = new StringBuilder();

                for (int i = 0; i < drbs.Count; i++)
                {
                    roleIdBuilder.AppendLine(((ulong)drbs[i].RoleId).ToString(CultureInfo.CurrentCulture));
                    accessBuilder.AppendLine(drbs[i].AccessLevel.ToString(CultureInfo.CurrentCulture));
                }

                EmbedPageBuilder epb = new EmbedPageBuilder(2);
                epb.AddColumn("RoleId", roleIdBuilder.ToString());
                epb.AddColumn("Access Level", accessBuilder.ToString());

                args.Channel.SendMessageAsync(embed: epb.BuildPage(page));
                return;
            }
            else if (args.Parameters.Count < 2)
            {
                HelpCommand.ShowHelp(args.Channel, this, ResourceExceptions.NotEnoughParameters);
                return;
            }

            if (!ulong.TryParse(args.Parameters[1], out ulong roleId))
            {
                HelpCommand.ShowHelp(args.Channel, this, string.Format(CultureInfo.CurrentCulture, ResourceExceptions.FailedParseException, args.Parameters[1]));
                return;
            }
            else if (args.Guild.GetRole(roleId) == null)
            {
                HelpCommand.ShowHelp(args.Channel, this, $"Discord Role {args.Parameters[1]} not found!");
                return;
            }

            AccessLevel?access = null;

            if (args.Parameters.Count > 2)
            {
                if (args.Parameters[2].TryParseEnum(out AccessLevel acc))
                {
                    access = acc;
                }
                else
                {
                    HelpCommand.ShowHelp(args.Channel, this, $"Access Level {args.Parameters[2]} not found!");
                    return;
                }

                if (access.HasValue)
                {
                    switch (access.Value)
                    {
                    case AccessLevel.Dev:
                        args.Channel.SendMessageAsync("You do not have enough permissions");
                        return;

                    case AccessLevel.Admin:
                    case AccessLevel.Host:
                        if (args.AccessLevel < AccessLevel.Host)
                        {
                            args.Channel.SendMessageAsync("You do not have enough permissions");
                            return;
                        }
                        break;
                    }
                }
            }


            switch (args.Parameters[0].ToLower(CultureInfo.CurrentCulture))
            {
            case "bind":
                if (!access.HasValue)
                {
                    HelpCommand.ShowHelp(args.Channel, this, $"Access Level {args.Parameters[2]} not found!");
                    return;
                }

                if (CommandHandler.BindPermssion(args.Guild, roleId, access.Value))
                {
                    args.Channel.SendMessageAsync("Binded permission");
                }
                else
                {
                    args.Channel.SendMessageAsync("Already binded or failed to bind");
                }

                break;

            case "unbind":
                if (CommandHandler.UnbindPermission(args.Guild, roleId, access))
                {
                    args.Channel.SendMessageAsync("Unbinded permission");
                }
                else
                {
                    args.Channel.SendMessageAsync("Already unbinded or failed to unbind");
                }
                break;
            }
        }