Ejemplo n.º 1
0
        public async Task <RuntimeResult> HelpCmd()
        {
            List <ModuleInfo> modules = _commands.Modules.OrderBy(x => x.Name).ToList();
            string            prefix  = Context.Guild != null?_guildSettings.GetOrAddGuildSettings(Context.Guild.Id).Prefix ?? _config.Prefix : _config.Prefix;

            try
            {
                foreach (ModuleInfo module in modules)
                {
                    await Context.User.SendMessageAsync(embed : new CommandsEmbed(module, prefix).Build());
                }
            }
            catch (HttpException e)
            {
                switch (e.DiscordCode)
                {
                case 50007:
                    return(new DirectMessageError());

                default:
                    throw;
                }
            }
            return(new SuccessResult());
        }
Ejemplo n.º 2
0
 public async Task HelpCmd()
 {
     System.Collections.Generic.List <ModuleInfo> modules = _commands.Modules.OrderBy(x => x.Name).ToList();
     foreach (ModuleInfo module in modules)
     {
         EmbedBuilder embedBuilder = new EmbedBuilder();
         embedBuilder.WithTitle(module.Name).WithDescription(module.Summary ?? "No summary");
         System.Collections.Generic.IReadOnlyList <CommandInfo> commands = module.Commands;
         foreach (CommandInfo command in commands)
         {
             string title = $"{string.Join(" | ", command.Aliases)}";
             if (command.Summary != null)
             {
                 title += $" | {command.Summary}";
             }
             string text = $"{(Context.Guild != null ? _guildSettings.GetOrAddGuildSettings(Context.Guild.Id).Prefix ?? _config.Prefix : _config.Prefix)}{command.Name}";
             foreach (ParameterInfo param in command.Parameters)
             {
                 text += $" | {param.Name}";
                 if (param.Summary != null)
                 {
                     text += $": {param.Summary}";
                 }
             }
             text = Format.Code('\n' + text);
             embedBuilder.AddField(title, text);
         }
         await ReplyAsync(embed : embedBuilder.Build());
     }
 }
Ejemplo n.º 3
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }

            if (message.Source != MessageSource.User)
            {
                return;
            }

            // This value holds the offset where the prefix ends
            int argPos = 0;
            // Perform prefix check. You may want to replace this with
            // (!message.HasCharPrefix('!', ref argPos))
            // for a more traditional command format like !help.
            ulong?guildId = (message.Channel as SocketGuildChannel)?.Guild?.Id;

            if (!(message.HasStringPrefix(guildId != null ? _guildSettings.GetOrAddGuildSettings(guildId.Value).Prefix ?? _config.Prefix : _config.Prefix, ref argPos) ||
                  message.HasMentionPrefix(_discord.CurrentUser, ref argPos)))
            {
                return;
            }

            SocketCommandContext context = new SocketCommandContext(_discord, message);
            // Perform the execution of the command. In this method,
            // the command service will perform precondition and parsing check
            // then execute the command if one is matched.
            await _commands.ExecuteAsync(context, argPos, _services);

            // Note that normally a result will be returned by this format, but here
            // we will handle the result in CommandExecutedAsync,
        }
Ejemplo n.º 4
0
        public async Task SetPrefixCmd([Summary("If not specified, restores default prefix")] string prefix = null)
        {
            if (!string.IsNullOrEmpty(prefix) && prefix.Length > 32)
            {
                await ReplyAsync("Prefix can't be longer than 32 characters!"); // TODO: Use Post-Execution handler

                return;
            }
            GuildSettings settings = _guildSettingsCache.GetOrAddGuildSettings(Context.Guild.Id);

            settings.Prefix = prefix;
            _guildSettingsCache.UpsertGuildSettings(settings);
            await ReplyAsync($"Current prefix: {prefix ?? _config.Prefix}");
        }
Ejemplo n.º 5
0
        public async Task <RuntimeResult> SetPrefixCmd([Summary("If not specified, restores default prefix")] string prefix = null)
        {
            if (!string.IsNullOrEmpty(prefix) && prefix.Length > 32)
            {
                return(new PrefixLengthError());
            }
            GuildSettings settings = _guildSettingsCache.GetOrAddGuildSettings(Context.Guild.Id);

            settings.Prefix = prefix;
            _guildSettingsCache.UpsertGuildSettings(settings);
            await ReplyAsync($"Current prefix: {prefix ?? _config.Prefix}");

            return(new SuccessResult());
        }