Esempio n. 1
0
        public async Task setTextChannel(CommandContext ctx, [Description("Canal de texto")] DiscordChannel channel)
        {
            if (channel.Type != ChannelType.Text)
            {
                await ctx.RespondAsync("O canal precisa ser do tipo Texto!");

                return;
            }
            GuildText guildText = new GuildText()
            {
                GuildID = ctx.Guild.Id.ToString()
            };
            await guildText.Select();

            if (string.IsNullOrEmpty(guildText.TextChannelID) || guildText.TextChannelID == "0")
            {
                guildText.TextChannelID = channel.Id.ToString();;
                await guildText.Insert();
            }
            else
            {
                guildText.TextChannelID = channel.Id.ToString();
                await guildText.Update();
            }
            DiscordMessage response = await ctx.Channel.SendMessageAsync(ctx.User.Mention + " Positivo e operante , agora só falarei aqui! " + channel.Mention);

            await Task.Delay(10000);

            await ctx.Message.DeleteAsync();
        }
        /// <summary>
        /// Creates a command execution context from specified arguments.
        /// </summary>
        /// <param name="msg">Message to use for context.</param>
        /// <param name="prefix">Command prefix, used to execute commands.</param>
        /// <param name="cmd">Command to execute.</param>
        /// <param name="rawArguments">Raw arguments to pass to command.</param>
        /// <returns>Created command execution context.</returns>
        public CommandContext CreateContext(DiscordMessage msg, string prefix, Command cmd, string rawArguments = null)
        {
            GuildText gt = new GuildText(msg.Channel.GuildId.ToString(CultureInfo.InvariantCulture));

            gt.Select().Wait();
            DiscordChannel channel;

            if (string.IsNullOrEmpty(gt.TextChannelID))
            {
                channel = msg.Channel;
            }
            else
            {
                channel = msg.Channel.Guild.Channels.Values.Where(f => f.Id.ToString(CultureInfo.InvariantCulture) == gt.TextChannelID).FirstOrDefault();
                if (channel == null)
                {
                    channel = msg.Channel;
                }
                else
                {
                    if (channel.Id != msg.Channel.Id)
                    {
                        msg.DeleteAsync();
                        msg.ChannelId = channel.Id;
                    }
                }
            }
            var ctx = new CommandContext
            {
                Client            = this.Client,
                Channel           = channel,
                Command           = cmd,
                Message           = msg,
                Config            = this.Config,
                RawArgumentString = rawArguments ?? "",
                Prefix            = prefix,
                CommandsNext      = this,
                Services          = this.Services
            };

            if (cmd != null && (cmd.Module is TransientCommandModule || cmd.Module == null))
            {
                var scope = ctx.Services.CreateScope();
                ctx.ServiceScopeContext = new CommandContext.ServiceContext(ctx.Services, scope);
                ctx.Services            = scope.ServiceProvider;
            }

            return(ctx);
        }