Exemplo n.º 1
0
        public async Task CommandHelp()
        {
            var io     = new GuildDataIO(Context.Guild.Id);
            var prefix = io.Read().CommandPrefix;

            List <string> commandsList = new List <string>();

            foreach (var cmd in Commands)
            {
                commandsList.Add(cmd.Aliases[0]);
            }

            commandsList = commandsList.Distinct().ToList();

            string commandsText = string.Empty;

            foreach (var cmd in commandsList)
            {
                commandsText += "`-` " + prefix + cmd + "\n";
            }

            await ReplyAsync(string.Empty, false, new EmbedBuilder
            {
                Title = string.Format("Total {0} {1}",
                                      commandsList.Count,
                                      commandsList.Count == 1 ? "command has been found!" : "commands have been found!"),
                Description = commandsText,
                Footer      = new EmbedFooterBuilder
                {
                    Text = $"{prefix}help <pluginName> for more detail."
                },
                Color = Color.Green
            }.Build());
        }
Exemplo n.º 2
0
        public async Task CommandPrefix()
        {
            GuildDataIO io        = new GuildDataIO(Context.Guild.Id);
            GuildData   guildData = io.Read();

            await ReplyAsync(string.Empty, false, new EmbedBuilder()
            {
                Description = string.Format("Current prefix is `{0}`", guildData.CommandPrefix),
                Color       = Color.Green
            }.Build());
        }
Exemplo n.º 3
0
        internal static async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;

            // return if message is null
            if (message == null)
            {
                return;
            }

            // return if message is sended by bot itself
            if (message.Author.Id == Client.CurrentUser.Id)
            {
                return;
            }

            // return if message string dosen't contain any characters
            if (string.IsNullOrWhiteSpace(message.Content))
            {
                return;
            }

            // Get prefix
            GuildDataIO io     = new GuildDataIO((message.Channel as SocketGuildChannel).Guild.Id);
            var         prefix = io.Read().CommandPrefix;
            int         argPos = 0;

            // Consider to be command if the message has prefix or mention to bot in front of it
            if (message.HasStringPrefix(prefix, ref argPos) ||
                message.HasMentionPrefix(Client.CurrentUser, ref argPos))
            {
                var context = new SocketCommandContext(Client, message);
                var result  = await Command.ExecuteAsync(context, argPos, Service);

                if (result.IsSuccess)
                {
                    Logger.Info("Command", $"({context.Guild.Id}) {context.User} calls command \"{message}\"!");
                }
                else
                {
                    await message.Channel.SendMessageAsync(null, false, new EmbedBuilder()
                    {
                        Description = string.Format(result.ErrorReason),
                        Color       = Color.Red
                    }.Build());

                    Logger.Error("Command", $"({context.Guild.Id}) {result.ErrorReason}");
                }
            }
        }
Exemplo n.º 4
0
        public async Task CommandPrefix(string prefix)
        {
            GuildDataIO io        = new GuildDataIO(Context.Guild.Id);
            GuildData   guildData = io.Read();

            guildData.CommandPrefix = prefix;

            io.Write(guildData);

            await ReplyAsync(string.Empty, false, new EmbedBuilder()
            {
                Title       = "Prefix Changed!",
                Description = string.Format("Command prefix of the guild has changed to `{0}`.", prefix),
                Color       = Color.Green
            }.Build());
        }
Exemplo n.º 5
0
        public async Task CommandHelp([Remainder] string command)
        {
            var io     = new GuildDataIO(Context.Guild.Id);
            var prefix = io.Read().CommandPrefix;

            command = command.Replace(prefix, "");

            List <EmbedFieldBuilder> CommandInfoFieldList = new List <EmbedFieldBuilder>();
            var foo = Commands.Where(cmd => string.Equals(command, cmd.Aliases[0]));

            foreach (var cmd in foo)
            {
                string parameterText = null;
                foreach (var param in cmd.Parameters)
                {
                    parameterText += $"`<{param}>` ";
                }

                string aliasesText = null;
                foreach (var alias in cmd.Aliases)
                {
                    if (alias != cmd.Aliases[0])
                    {
                        aliasesText += $"`{alias}` ";
                    }
                }

                /*
                 * string permissionText = null;
                 * foreach (var attribute in cmd.Preconditions)
                 * {
                 *  Logging.Logger.Debug("Help", attribute.ToString());
                 *
                 *  if (attribute is RequireUserPermissionAttribute)
                 *  {
                 *      permissionText = (attribute as RequireUserPermissionAttribute).GuildPermission.ToString();
                 *  }
                 * }*/

                CommandInfoFieldList.Add(new EmbedFieldBuilder
                {
                    Name  = $"**{prefix}{command}** {parameterText}",
                    Value = $"{cmd.Summary ?? "No description."}\n" +
                            aliasesText != null ? "" : $"**Aliases**: {aliasesText}\n", // if aliasesText is null, append nothing. else append aliases
                    //$"**Permissions**: `{permissionText ?? "Any Users"}`",
                    IsInline = false
                });
            }

            if (CommandInfoFieldList.Count == 0)
            {
                await ReplyAsync(string.Empty, false, new EmbedBuilder
                {
                    Description = $"Command `{prefix}{command}` has not found.",
                    Color       = Color.Red
                }.Build());
            }
            else
            {
                await ReplyAsync(string.Empty, false, new EmbedBuilder
                {
                    Title  = $"All about `{prefix}{command}`",
                    Fields = CommandInfoFieldList,
                    Color  = Color.Blue
                }.Build());
            }
        }