예제 #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;
        }
예제 #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);
        }
예제 #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);
        }