Ejemplo n.º 1
0
        public bool OpenConnection()
        {
            if (_connObj == null)
            {
                throw new InvalidOperationException("Cannot open connection before connecting to the Database. Please use the ConnectAsync function first.");
            }

            try
            {
                Connection connection = new Connection
                {
                    connectionObject = _connObj,
                };
                DatabaseConnection.connection = connection;

                sql = new SQLProcessor(connection);

                return(true);
            } catch (Exception exception)
            {
                return(false);

                throw exception;
            }
        }
Ejemplo n.º 2
0
        public async Task DisableCommand(ulong guildID, string cmdName)
        {
            SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection);

            if (CommandDisabled(cmdName))
            {
                return;
            }

            await sql.ExecuteQueryAsync($"INSERT INTO blacklistedcommands (guildID, command) VALUES ({guildID}, '{cmdName}')");
        }
Ejemplo n.º 3
0
        public async Task ChangePrefix(string prefix)
        {
            SQLProcessor processor = new SQLProcessor(DatabaseConnection.connection);

            if (CheckIfRegisteredAsync(_guildId))
            {
                await UpdateGuildPrefix(_guildId, prefix);
            }
            else
            {
                await InsertGuildPrefix(_guildId, prefix);
            }
        }
Ejemplo n.º 4
0
        private bool CheckIfRegisteredAsync(ulong guildID)
        {
            var connection = DatabaseConnection.connection;

            SQLProcessor processor = new SQLProcessor(connection);

            connection.connectionObject.Open();
            using (SqliteTransaction transaction = connection.connectionObject.BeginTransaction())
            {
                var selectCommand = connection.connectionObject.CreateCommand();
                selectCommand.Transaction = transaction;
                selectCommand.CommandText = $"SELECT guildID FROM guildprefix WHERE guildID={guildID}";
                var    reader = selectCommand.ExecuteReader();
                string msg    = "";
                while (reader.Read())
                {
                    msg = reader.GetString(0);
                }

                transaction.Commit();
                connection.connectionObject.Close();
                transaction.Dispose();

                bool x = false;
                try
                {
                    ulong id = ulong.Parse(msg);

                    if (id == guildID)
                    {
                        x = true;
                    }
                } catch
                {
                    x = false;
                }
                return(x);
            }
        }
Ejemplo n.º 5
0
 private async Task UpdateGuildPrefix(ulong guildId, string newPrefix)
 {
     SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection);
     await sql.ExecuteQueryAsync($"UPDATE guildprefix SET prefix='{newPrefix}' WHERE guildID={guildId}");
 }
Ejemplo n.º 6
0
 private async Task InsertGuildPrefix(ulong guildId, string newPrefix)
 {
     SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection);
     await sql.ExecuteQueryAsync($"INSERT INTO guildprefix (guildID, prefix) VALUES ({guildId}, '{newPrefix}')");
 }
Ejemplo n.º 7
0
 public async Task EnableCommand(ulong guildID, string cmdName)
 {
     SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection);
     await sql.ExecuteQueryAsync($"DELETE FROM blacklistedcommands WHERE guildID={guildID} and command='{cmdName}'");
 }