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); }
public static async Task Select(this GuildText guildText) { try { using (SQLiteConnection con = ContextController.getDb()) { try { con.Open(); if (con.State != System.Data.ConnectionState.Open) { throw new SQLiteException("Não foi possível abrir conexão com o banco!"); } } catch (SQLiteException ex) { throw ex; } SQLiteCommand cmd = con.CreateCommand(); SQLiteParameter parameter = new SQLiteParameter(); parameter.ParameterName = "@GuildID"; parameter.DbType = System.Data.DbType.String; parameter.Value = guildText.GuildID; cmd.Parameters.Add(parameter); cmd.CommandText = "SELECT ChannelID FROM GuildTextChannel WHERE Guild = @GuildID"; try { guildText.TextChannelID = (string)await cmd.ExecuteScalarAsync(); } catch (SQLiteException ex) { Console.WriteLine(ex.Message); throw ex; } } } catch (Exception ex) { Console.WriteLine($"Exceção no método {MethodBase.GetCurrentMethod().Name} com a mensagem: {ex.Message}"); throw ex; } finally { } }
public static async Task Insert(this GuildText guildText) { try { using (SQLiteConnection con = ContextController.getDb()) { try { con.Open(); if (con.State != System.Data.ConnectionState.Open) { throw new SQLiteException("Não foi possível abrir conexão com o banco!"); } } catch (SQLiteException ex) { throw ex; } SQLiteCommand cmd = con.CreateCommand(); SQLiteParameter parameter = new SQLiteParameter(); parameter.ParameterName = "@GuildID"; parameter.DbType = System.Data.DbType.String; parameter.Value = guildText.GuildID; cmd.Parameters.Add(parameter); parameter = new SQLiteParameter() { ParameterName = "@ChannelID", DbType = System.Data.DbType.String, Value = guildText.TextChannelID }; cmd.Parameters.Add(parameter); cmd.CommandText = "INSERT INTO GuildTextChannel('Guild', 'ChannelID') VALUES (@GuildID, @ChannelID)"; await cmd.ExecuteNonQueryAsync(); } } catch (Exception ex) { Console.WriteLine($"Exceção no método {MethodBase.GetCurrentMethod().Name} com a mensagem: {ex.Message}"); throw ex; } }